-
Notifications
You must be signed in to change notification settings - Fork 5
/
westworld.pde
99 lines (76 loc) · 1.81 KB
/
westworld.pde
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Manuale di Programmazione Cinematografica
// Daniele Olmisani, 2022
// Westworld (1973)
final color PAPER = color(10, 100, 40);
final color INK = color(240);
final float dL = 0.05;
final float dA = QUARTER_PI;
final String P = "d2r9frfl5fu 2lflfl14f4r d9fu rfl d3f2lf2l3f2rf2r3fu" +
"f2r d2fu 2r9frfrf2r d4flflf2r2flfu r d2fl2fl3fu 2r" +
"d2frfr4fr2fu r df2l2fl2fu 4l6f3r d2fu";
void setup() {
size(480, 640);
noLoop();
}
void draw() {
final float S = min(width, height);
final float U = 0.002;
translate(0.2*width, 0.2*height);
scale(S);
background(PAPER);
fill(PAPER);
stroke(INK);
strokeWeight(5*U);
drawTurtle(P, dL, dA);
save("westworld.png");
}
void drawTurtle(String path, float dL, float dA) {
int k = 0;
boolean penDown = false;
boolean firstStep = true;
for (int i=0; i<path.length(); i++) {
char c = path.charAt(i);
switch (c) {
case 'u':
ellipse(0, 0, 0.5*dL, 0.5*dL);
penDown = false;
break;
case 'd':
penDown = true;
firstStep = true;
break;
case 'f':
if (k==0) k=1;
if (penDown) {
line(0, 0, k*dL, 0);
if (firstStep) {
ellipse(0, 0, 0.5*dL, 0.5*dL);
firstStep = false;
}
}
translate(k*dL, 0);
k=0;
break;
case 'r':
if (k==0) k=1;
rotate(k*dA);
k=0;
break;
case 'l':
if (k==0) k=1;
rotate(-k*dA);
k=0;
break;
case '1': case '2':
case '3': case '4':
case '5': case '6':
case '7': case '8':
case '9': case '0':
k = 10*k + c-'0';
break;
default:
break;
}
}
ellipse(0, 0, 0.5*dL, 0.5*dL);
}