-
Notifications
You must be signed in to change notification settings - Fork 54
/
snowflake.rs
43 lines (35 loc) · 1.06 KB
/
snowflake.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Source: http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/
// Modified to create a full snowflake with the fractals
extern crate turtle;
use turtle::Turtle;
fn main() {
let mut turtle = Turtle::new();
turtle.drawing_mut().set_background_color("#29B6F6");
turtle.set_pen_color("#B2EBF2");
turtle.pen_up();
turtle.set_speed(11);
turtle.backward(200.0);
turtle.right(30.0);
turtle.pen_down();
turtle.set_speed(10);
fractal(&mut turtle, 350.0, 3);
turtle.left(120.0);
fractal(&mut turtle, 350.0, 3);
turtle.left(120.0);
fractal(&mut turtle, 350.0, 3);
turtle.hide();
}
fn fractal(turtle: &mut Turtle, length: f64, depth: usize) {
if depth == 0 {
turtle.forward(length);
}
else {
fractal(turtle, length/3.0, depth-1);
turtle.right(60.0);
fractal(turtle, length/3.0, depth-1);
turtle.left(120.0);
fractal(turtle, length/3.0, depth-1);
turtle.right(60.0);
fractal(turtle, length/3.0, depth-1);
}
}