-
Notifications
You must be signed in to change notification settings - Fork 1
/
Builder.pde
216 lines (181 loc) · 4.93 KB
/
Builder.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import java.awt.Rectangle;
import java.util.Collection;
PVector v(float x, float y) {
return new PVector(x, y);
}
class SequenceBuilder {
Sequence s;
int currentColor;
Palette p;
public SequenceBuilder(int numSteps, Palette p) {
s = new Sequence(numSteps);
currentColor = color(255,255,255,255);
this.p = p;
}
public SequenceBuilder() {
this(Integer.MAX_VALUE, new Palette());
}
public SequenceBuilder(int numSteps) {
this(numSteps, new Palette());
}
public SequenceBuilder(Palette p) {
this(Integer.MAX_VALUE, p);
}
Sequence sequence() {
return s;
}
void add(Transform t) {
s.add(t);
}
SequenceBuilder anchor(float x, float y) {
return anchor(new PVector(x,y));
}
SequenceBuilder anchor(PVector disp) {
add(new Anchor(disp));
return this;
}
SequenceBuilder col(int col) {
currentColor = col;
return this;
}
SequenceBuilder col(int r, int g, int b, int a) {
currentColor = color(r,g,b,a);
return this;
}
SequenceBuilder col(String name) {
currentColor = p.fetch(name);
return this;
}
SequenceBuilder pen() {
return pen(0,0,currentColor);
}
SequenceBuilder pen(PVector pos, int col) {
add(new Pen(pos, col));
return this;
}
SequenceBuilder pen(float x, float y) {
return pen(new PVector(x, y), currentColor);
}
SequenceBuilder pen(float x, float y, int col) {
return pen(new PVector(x,y), col);
}
SequenceBuilder pen(float x, float y, String name) {
return pen(x,y,p.fetch(name));
}
SequenceBuilder pens(PVector pos, PVector step, int n) {
add(new Pen(pos, color(255,255,255,100)));
for (int i = 1; i < n; i++) {
pos = PVector.add(pos, step);
add(new Pen(pos, color(255,255,255,100)));
}
return this;
}
SequenceBuilder pens(PVector pos, PVector step) {
Collection<Integer> colors = p.values();
if (colors.size() < 0) return pens(pos, step, 3);
PVector root = pos;
for (int c : colors) {
pen(root, c);
root = PVector.add(root, step);
}
return this;
}
SequenceBuilder translator(PVector disp, PVector vel, Rectangle bounds) {
add(new Translator(disp, vel, bounds));
return this;
}
SequenceBuilder translator(float x, float y, float dx, float dy, float bx, float by, int w, int h) {
return translator(
new PVector(x,y),
new PVector(dx, dy),
new Rectangle((int)bx, (int)by, (int)w, (int)h)
);
}
SequenceBuilder rotator() {
return rotator(0,0,0.125);
}
SequenceBuilder rotator(float x, float y, float speed) {
return this.rotator(new PVector(x,y), speed);
}
SequenceBuilder rotator(PVector p, float speed) {
add(new Rotator(p, speed));
return this;
}
SequenceBuilder path(float speed, PVector... points) {
Path pa = new Path(speed);
for (PVector p : points) {
pa.point(p);
}
add(pa);
return this;
}
SequenceBuilder ellipse(float x, float y, float major, float minor, float speed) {
add(new Ellipse(v(x,y),major,minor,speed));
return this;
}
SequenceBuilder sin(float x, float y, float scaleX, float scaleY, float speed) {
add(new SinTranslator(new PVector(x,y), scaleX, scaleY, speed));
return this;
}
private Transform getLast() {
return s.steps.get(s.steps.size() - 1);
}
private void setLast(Transform t) {
s.steps.set(s.steps.size() - 1, t);
}
SequenceBuilder ratchet(int frames) {
Transform last = getLast();
setLast(new Ratchet(last, frames));
return this;
}
SequenceBuilder ramp(float step, float max) {
Transform last = getLast();
setLast(new Ramp(last, step, max));
return this;
}
SequenceBuilder osc(String patt, String... mappings) {
Transform last = getLast();
setLast(new OscWrapper(patt, last, mappings));
return this;
}
SequenceBuilder oscColor(String patt) {
Transform last = getLast();
setLast(new ColorWrapper(patt, last));
return this;
}
SequenceBuilder oscColor(String patt, Palette p) {
Transform last = getLast();
setLast(new PaletteWrapper(patt, p, last));
return this;
}
SequenceBuilder oscMomentum(String patt, float friction) {
Transform last = getLast();
setLast(new PositionWrapper(patt, friction, last));
return this;
}
SequenceBuilder oscSpeed(String patt) {
Transform last = getLast();
setLast(new SpeedWrapper(patt, last));
return this;
}
SequenceBuilder delay(int frames, String field, float value) {
Transform last = getLast();
setLast(new DelayWrapper(last, frames, field, value));
return this;
}
SequenceBuilder toggle(int frames) {
Transform last = getLast();
setLast(new PauseDelay(last, frames));
return this;
}
SequenceBuilder pause() {
Transform last = getLast();
try {
Pausable p = (Pausable)last;
p.pause();
} catch (Exception ex) {
println(ex.getMessage());
}
return this;
}
}