-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSequencer.pde
55 lines (51 loc) · 1.05 KB
/
Sequencer.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
class LineSegment {
float x1, y1, x2, y2;
int col;
public LineSegment(float x1, float y1, float x2, float y2, int col) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.col = col;
}
void draw(PGraphics g) {
g.stroke(col);
g.line(x1, y1, x2, y2);
}
}
class Sequence {
ArrayList<Transform> steps = new ArrayList<Transform>();
ArrayList<LineSegment> lines = new ArrayList<LineSegment>();
int numSteps = Integer.MAX_VALUE;
public Sequence() {}
public Sequence(int numSteps) {
this.numSteps = numSteps;
}
void add(LineSegment ls) {
if (ls != null) lines.add(ls);
if (lines.size() > numSteps) {
lines.remove(0);
}
}
void build() {
int pops = 0;
for (Transform s : steps) {
pushMatrix();
s.tick();
s.transform();
add(s.draw());
pops++;
}
for (int i = 0; i < pops; i++) {
popMatrix();
}
}
void draw(PGraphics g) {
for (LineSegment l : lines) {
l.draw(g);
}
}
void add(Transform t) {
steps.add(t);
}
}