-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWrapperTransforms.pde
More file actions
63 lines (59 loc) · 1.23 KB
/
WrapperTransforms.pde
File metadata and controls
63 lines (59 loc) · 1.23 KB
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
class BaseWrapper implements Transform {
Transform wrapped;
public Transform getWrapped() {
return wrapped;
}
public BaseWrapper(Transform wrapped) {
this.wrapped = wrapped;
}
void transform() {
wrapped.transform();
}
void tick() {
wrapped.tick();
}
LineSegment draw() {
return wrapped.draw();
}
Transform unwrap() { //we sometimes need a REAL instance of a transform to access its properties
Transform w = this.wrapped;
while(w instanceof BaseWrapper) {
w = ((BaseWrapper)w).getWrapped();
}
return w;
}
}
class Ratchet extends BaseWrapper {
int ratchetBy;
int ticks = 0;
public Ratchet(Transform wrapped, int ratchetBy) {
super(wrapped);
this.ratchetBy = ratchetBy;
}
void tick() {
ticks++;
if (ticks >= ratchetBy) {
for (int i = 0; i < ratchetBy; i++) {
wrapped.tick();
}
ticks = 0;
}
}
}
class Ramp extends BaseWrapper {
float max,step,i;
public Ramp(Transform wrapped, float step, float max) {
super(wrapped);
this.step = step;
this.max = max;
this.i = 0;
}
void tick() {
i += step;
if (i > max) i = 0;
if (i < 0) i = max;
for (int j = 0; j < i; j++) {
wrapped.tick();
}
}
}