Feat: don't segment polygons in favicon
This commit is contained in:
parent
3d32fa6bd8
commit
cb29aaf7f7
2 changed files with 43 additions and 2 deletions
|
@ -60,6 +60,28 @@ fn generate_color(
|
||||||
color
|
color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw_polygon(
|
||||||
|
center: (f64, f64),
|
||||||
|
side_length: f64,
|
||||||
|
num_sides: i32,
|
||||||
|
context: &Context,
|
||||||
|
dark_mode: bool,
|
||||||
|
) {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let c1 = generate_color(&mut rng, dark_mode, None);
|
||||||
|
set_color_i8(c1, context);
|
||||||
|
context.new_path();
|
||||||
|
|
||||||
|
let corners = calculate_polygon_corners(center, num_sides, side_length, 30.0);
|
||||||
|
|
||||||
|
for (x, y) in corners {
|
||||||
|
context.line_to(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.close_path();
|
||||||
|
context.fill().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_segmented_polygon(
|
pub fn draw_segmented_polygon(
|
||||||
center: (f64, f64),
|
center: (f64, f64),
|
||||||
side_length: f64,
|
side_length: f64,
|
||||||
|
@ -101,7 +123,7 @@ pub fn draw_segmented_polygon(
|
||||||
context.fill().unwrap();
|
context.fill().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_polygon_of_polygons(
|
pub fn draw_polygon_of_segmented_polygons(
|
||||||
center: (f64, f64),
|
center: (f64, f64),
|
||||||
side_length: f64,
|
side_length: f64,
|
||||||
num_sides: i32,
|
num_sides: i32,
|
||||||
|
@ -113,3 +135,16 @@ pub fn draw_polygon_of_polygons(
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw_polygon_of_polygons(
|
||||||
|
center: (f64, f64),
|
||||||
|
side_length: f64,
|
||||||
|
num_sides: i32,
|
||||||
|
context: &Context,
|
||||||
|
dark_mode: bool,
|
||||||
|
) {
|
||||||
|
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
|
||||||
|
for corner in corners {
|
||||||
|
draw_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,13 @@ async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::respon
|
||||||
|
|
||||||
context.paint().unwrap();
|
context.paint().unwrap();
|
||||||
|
|
||||||
polygon::draw_polygon_of_polygons((200.0, 200.0), 200.0, 6, &context, properties.dark_mode);
|
polygon::draw_polygon_of_segmented_polygons(
|
||||||
|
(200.0, 200.0),
|
||||||
|
200.0,
|
||||||
|
6,
|
||||||
|
&context,
|
||||||
|
properties.dark_mode,
|
||||||
|
);
|
||||||
|
|
||||||
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