all regular polygon plus no regular polygon but balanced

This commit is contained in:
2025-05-29 23:16:08 +02:00
parent 140ab51811
commit 1ca46270ac
2 changed files with 149 additions and 6 deletions

View File

@@ -38,7 +38,11 @@ impl MyApp {
time_last_frame: Instant::now(), time_last_frame: Instant::now(),
polys: PolygonFrame { polys: PolygonFrame {
teta: 0.0, teta: 0.0,
polygons: vec![Polygon::triangle(0.0), Polygon::triangle(PI / 2.0)], polygons: vec![
//Polygon::n_gon(0.0, 12),
Polygon::nr_10a_in_42(0.0),
Polygon::nr_10b_in_42(0.0),
],
}, },
}, },
Task::none(), Task::none(),

View File

@@ -54,7 +54,7 @@ impl<Message> canvas::Program<Message> for PolygonFrame {
frame.stroke( frame.stroke(
&line, &line,
Stroke { Stroke {
width: 5.0, width: 4.0,
style: Style::Solid(Color::BLACK), style: Style::Solid(Color::BLACK),
..Stroke::default() ..Stroke::default()
}, },
@@ -67,7 +67,7 @@ impl<Message> canvas::Program<Message> for PolygonFrame {
frame.stroke( frame.stroke(
&circle, &circle,
Stroke { Stroke {
width: 5.0, width: 6.0,
style: Style::Solid(Color::from_rgba(0.0, 0.0, 0.0, 1.0)), style: Style::Solid(Color::from_rgba(0.0, 0.0, 0.0, 1.0)),
..Stroke::default() ..Stroke::default()
}, },
@@ -95,12 +95,151 @@ pub struct Polygon {
pub global_teta: f32, pub global_teta: f32,
pub points_teta: Vec<f32>, pub points_teta: Vec<f32>,
} }
#[warn(dead_code)]
impl Polygon { impl Polygon {
pub fn triangle(teta: f32) -> Self { pub fn n_gon(teta: f32, n_side: u8) -> Self {
let mut v: Vec<f32> = Vec::with_capacity(n_side as usize);
for i in 0..n_side {
v.push((i as f32 * 2.0 * PI) / n_side as f32);
}
Polygon { Polygon {
global_teta: teta, global_teta: teta,
points_teta: vec![0.0, 2.0 * PI / 3.0, 4.0 * PI / 3.0], points_teta: v,
}
}
pub fn segment(teta: f32) -> Self {
Polygon::n_gon(teta, 2)
}
pub fn triangle(teta: f32) -> Self {
Polygon::n_gon(teta, 2)
}
pub fn square(teta: f32) -> Self {
Polygon::n_gon(teta, 2)
}
pub fn nr_6_in_30(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
2.0 * 5.0 * PI / 30.0,
2.0 * 6.0 * PI / 30.0,
2.0 * 12.0 * PI / 30.0,
2.0 * 18.0 * PI / 30.0,
2.0 * 24.0 * PI / 30.0,
2.0 * 25.0 * PI / 30.0,
],
}
}
pub fn nr_7_in_30(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
0.0,
2.0 * 6.0 * PI / 30.0,
2.0 * 7.0 * PI / 30.0,
2.0 * 13.0 * PI / 30.0,
2.0 * 17.0 * PI / 30.0,
2.0 * 23.0 * PI / 30.0,
2.0 * 24.0 * PI / 30.0,
],
}
}
pub fn nr_8_in_30(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
2.0 * PI / 30.0,
2.0 * 5.0 * PI / 30.0,
2.0 * 11.0 * PI / 30.0,
2.0 * 12.0 * PI / 30.0,
2.0 * 18.0 * PI / 30.0,
2.0 * 19.0 * PI / 30.0,
2.0 * 25.0 * PI / 30.0,
2.0 * 29.0 * PI / 30.0,
],
}
}
pub fn nr_9_in_30(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
0.0,
2.0 * PI / 30.0,
2.0 * 7.0 * PI / 30.0,
2.0 * 11.0 * PI / 30.0,
2.0 * 13.0 * PI / 30.0,
2.0 * 17.0 * PI / 30.0,
2.0 * 19.0 * PI / 30.0,
2.0 * 23.0 * PI / 30.0,
2.0 * 29.0 * PI / 30.0,
],
}
}
pub fn nr_8_in_42(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
2.0 * 3.0 * PI / 42.0,
2.0 * 9.0 * PI / 42.0,
2.0 * 14.0 * PI / 42.0,
2.0 * 15.0 * PI / 42.0,
2.0 * 27.0 * PI / 42.0,
2.0 * 28.0 * PI / 42.0,
2.0 * 33.0 * PI / 42.0,
2.0 * 39.0 * PI / 42.0,
],
}
}
pub fn nr_9_in_42(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
0.0,
2.0 * 6.0 * PI / 42.0,
2.0 * 11.0 * PI / 42.0,
2.0 * 12.0 * PI / 42.0,
2.0 * 17.0 * PI / 42.0,
2.0 * 25.0 * PI / 42.0,
2.0 * 30.0 * PI / 42.0,
2.0 * 31.0 * PI / 42.0,
2.0 * 36.0 * PI / 42.0,
],
}
}
pub fn nr_10a_in_42(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
2.0 * 6.0 * PI / 42.0,
2.0 * 7.0 * PI / 42.0,
2.0 * 11.0 * PI / 42.0,
2.0 * 12.0 * PI / 42.0,
2.0 * 17.0 * PI / 42.0,
2.0 * 25.0 * PI / 42.0,
2.0 * 30.0 * PI / 42.0,
2.0 * 31.0 * PI / 42.0,
2.0 * 35.0 * PI / 42.0,
2.0 * 36.0 * PI / 42.0,
],
}
}
pub fn nr_10b_in_42(teta: f32) -> Self {
Polygon {
global_teta: teta,
points_teta: vec![
0.0,
2.0 * 1.0 * PI / 42.0,
2.0 * 5.0 * PI / 42.0,
2.0 * 13.0 * PI / 42.0,
2.0 * 18.0 * PI / 42.0,
2.0 * 19.0 * PI / 42.0,
2.0 * 24.0 * PI / 42.0,
2.0 * 29.0 * PI / 42.0,
2.0 * 30.0 * PI / 42.0,
2.0 * 41.0 * PI / 42.0,
],
} }
} }
} }