pub enum Angle {
Degree(f64),
Radian(f64),
}Expand description
Angles
Variants§
Implementations§
Source§impl Angle
impl Angle
Sourcepub fn to_radian(self) -> f64
pub fn to_radian(self) -> f64
Get the angle in radians
Examples found in repository?
examples/sunflower.rs (line 18)
4fn main() {
5 let points = Vogel::golden_builder()
6 .seeds(256)
7 .scaling_factor(50.0)
8 .build();
9 let mut canvas = Canvas::builder()
10 .size(2560.0, 1440.0)
11 .background_color("#fcba03".try_into().unwrap())
12 .points(points)
13 .build();
14
15 let polygon_builder = || {
16 Polygon::builder()
17 .sides(4)
18 .rotation_fn(move |n: &usize| Angle::Radian(*n as f64 * points.angle.to_radian()))
19 };
20 canvas.add_shape(
21 polygon_builder()
22 .size(100.0)
23 .color("#3d2f06".try_into().unwrap())
24 .build(),
25 );
26 canvas.add_shape(
27 polygon_builder()
28 .size(20.0)
29 .color("#dedbd5".try_into().unwrap())
30 .build(),
31 );
32
33 let document = canvas.render(|_| true);
34 svg::save("examples/sunflower.svg", &document).unwrap();
35}More examples
examples/placemat.rs (line 21)
5fn main() {
6 let mut rng = rand::rng();
7
8 let lattice = Lattice::builder()
9 .grid_size(rng.random_range(5..50), rng.random_range(1..50))
10 .len_a(rng.random_range(100.0..400.0))
11 .len_b(rng.random_range(100.0..400.0))
12 .theta(Angle::Degree(rng.random_range(0.0..90.0)))
13 .build();
14 let mut canvas_builder = Canvas::builder()
15 .size(2560.0, 1440.0)
16 .background_color("#e0d8d1".try_into().unwrap())
17 .points(lattice);
18
19 let size = rng
20 .random_range(100.0..lattice.len_a)
21 .min(rng.random_range(100.0..lattice.len_b) * lattice.theta.to_radian().sin());
22
23 canvas_builder.add_shape(
24 Polygon::builder()
25 .sides_fn(|_| rand::rng().random_range(3..8))
26 .size(size)
27 .color_fn(|_| {
28 vec![
29 "#6f6e6a", "#b3b4af", "#b09e90", "#bea24e", "#d9bdb9", "#9a9ba0",
30 ]
31 .choose(&mut rand::rng())
32 .copied()
33 .unwrap()
34 .try_into()
35 .unwrap()
36 })
37 .cv_fn(|_| rand::rng().random_range(0.1..0.5) / 6.0)
38 .build(),
39 );
40
41 let canvas = canvas_builder.build();
42
43 let document = canvas.render(|_| rand::rng().random_bool(0.9));
44 svg::save("examples/placemat.svg", &document).unwrap();
45}Trait Implementations§
Source§impl AddAssign for Angle
impl AddAssign for Angle
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreimpl Copy for Angle
Auto Trait Implementations§
impl Forget for Angle
impl Freeze for Angle
impl Move for Angle
impl RefUnwindSafe for Angle
impl Send for Angle
impl Sync for Angle
impl Unpin for Angle
impl UnsafeUnpin for Angle
impl UnwindSafe for Angle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more