Chore: cleanup
This commit is contained in:
parent
cb29aaf7f7
commit
65401700c0
3 changed files with 18 additions and 11 deletions
|
@ -66,7 +66,7 @@ pub fn draw_polygon(
|
||||||
num_sides: i32,
|
num_sides: i32,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
dark_mode: bool,
|
dark_mode: bool,
|
||||||
) {
|
) -> Result<(), cairo::Error> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let c1 = generate_color(&mut rng, dark_mode, None);
|
let c1 = generate_color(&mut rng, dark_mode, None);
|
||||||
set_color_i8(c1, context);
|
set_color_i8(c1, context);
|
||||||
|
@ -79,7 +79,9 @@ pub fn draw_polygon(
|
||||||
}
|
}
|
||||||
|
|
||||||
context.close_path();
|
context.close_path();
|
||||||
context.fill().unwrap();
|
context.fill()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_segmented_polygon(
|
pub fn draw_segmented_polygon(
|
||||||
|
@ -88,7 +90,7 @@ pub fn draw_segmented_polygon(
|
||||||
num_sides: i32,
|
num_sides: i32,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
dark_mode: bool,
|
dark_mode: bool,
|
||||||
) {
|
) -> Result<(), cairo::Error> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let c1 = generate_color(&mut rng, dark_mode, None);
|
let c1 = generate_color(&mut rng, dark_mode, None);
|
||||||
set_color_i8(c1, context);
|
set_color_i8(c1, context);
|
||||||
|
@ -108,7 +110,7 @@ pub fn draw_segmented_polygon(
|
||||||
}
|
}
|
||||||
|
|
||||||
context.close_path();
|
context.close_path();
|
||||||
context.fill().unwrap();
|
context.fill()?;
|
||||||
|
|
||||||
let c2 = generate_color(&mut rng, dark_mode, Some(c1));
|
let c2 = generate_color(&mut rng, dark_mode, Some(c1));
|
||||||
set_color_i8(c2, context);
|
set_color_i8(c2, context);
|
||||||
|
@ -120,7 +122,9 @@ pub fn draw_segmented_polygon(
|
||||||
}
|
}
|
||||||
|
|
||||||
context.close_path();
|
context.close_path();
|
||||||
context.fill().unwrap();
|
context.fill()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_polygon_of_segmented_polygons(
|
pub fn draw_polygon_of_segmented_polygons(
|
||||||
|
@ -129,11 +133,12 @@ pub fn draw_polygon_of_segmented_polygons(
|
||||||
num_sides: i32,
|
num_sides: i32,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
dark_mode: bool,
|
dark_mode: bool,
|
||||||
) {
|
) -> Result<(), cairo::Error> {
|
||||||
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
|
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
|
||||||
for corner in corners {
|
for corner in corners {
|
||||||
draw_segmented_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode);
|
draw_segmented_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode)?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_polygon_of_polygons(
|
pub fn draw_polygon_of_polygons(
|
||||||
|
@ -142,9 +147,10 @@ pub fn draw_polygon_of_polygons(
|
||||||
num_sides: i32,
|
num_sides: i32,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
dark_mode: bool,
|
dark_mode: bool,
|
||||||
) {
|
) -> Result<(), cairo::Error> {
|
||||||
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
|
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
|
||||||
for corner in corners {
|
for corner in corners {
|
||||||
draw_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode);
|
draw_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode)?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ async fn handler() -> impl axum::response::IntoResponse {
|
||||||
context.set_source_rgba(0.0, 0.0, 0.0, 0.0);
|
context.set_source_rgba(0.0, 0.0, 0.0, 0.0);
|
||||||
context.fill().unwrap();
|
context.fill().unwrap();
|
||||||
|
|
||||||
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false);
|
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false).unwrap();
|
||||||
|
|
||||||
let mut data: Vec<u8> = Vec::new();
|
let mut data: Vec<u8> = Vec::new();
|
||||||
surface.write_to_png(&mut data).unwrap();
|
surface.write_to_png(&mut data).unwrap();
|
||||||
|
|
|
@ -32,7 +32,8 @@ async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::respon
|
||||||
6,
|
6,
|
||||||
&context,
|
&context,
|
||||||
properties.dark_mode,
|
properties.dark_mode,
|
||||||
);
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut data: Vec<u8> = Vec::new();
|
let mut data: Vec<u8> = Vec::new();
|
||||||
surface.write_to_png(&mut data).unwrap();
|
surface.write_to_png(&mut data).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue