-
Notifications
You must be signed in to change notification settings - Fork 2
/
TheClimb.pde
143 lines (108 loc) · 2.65 KB
/
TheClimb.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
// These important flags indicate which role(s) this program is taking on. We tend to flip between bWorkOnAnimation
// and bRunAnimation while working in this way
boolean bWorkOnAnimation = false;
boolean bRunAnimation = true;
boolean bRecord = false;
PImage background;
Poses poses;
ArrayList<StickFigure> sequence;
AnimatedFigure fig1;
AnimatedFigure fig2;
int nCurrentPose;
StickFigure stickFigure;
StickFigure onionSkin;
void setup() {
size(800, 600);
strokeWeight(18);
background = loadImage("background.png");
poses = new Poses();
sequence = poses.pulled; // We set this to the sequence we're currently working on
setCurrentPose(sequence.size() - 1); // And we usually want to start with the last frame
fig1 = new AnimatedFigure();
fig1.resetFig1();
fig2 = new AnimatedFigure();
fig2.resetFig2();
}
void draw() {
image(background, 0, 0);
if (bRunAnimation == true) {
stroke(0, 255);
fill(0, 255);
int nFrame = (frameCount) % max(fig1.lastFrame(), fig2.lastFrame());
if (nFrame < frameCount) {
bRecord = false;
}
fig1.draw(nFrame);
fig2.draw(nFrame);
}
if (bWorkOnAnimation) {
if (onionSkin != null) {
stroke(0, 128);
fill(0, 128);
onionSkin.draw();
}
stroke(0, 255);
fill(0, 255);
if (stickFigure != null) {
stickFigure.draw();
stickFigure.drawPoints();
}
text("Current pose " + nCurrentPose, 10, 10);
}
if (bRecord && (frameCount % 5 == 0)) {
saveFrame("TheClimb-######.png");
}
}
void mousePressed() {
if (bWorkOnAnimation) {
stickFigure.mousePressed();
}
}
void mouseReleased() {
if (bWorkOnAnimation) {
stickFigure.mouseReleased();
}
}
void mouseDragged() {
if (bWorkOnAnimation) {
stickFigure.mouseDragged();
}
}
void keyPressed() {
if (bWorkOnAnimation) {
char key = Character.toLowerCase((char)keyCode);
switch(key) {
case 'p':
stickFigure.print();
break;
case 'n':
sequence.add(stickFigure.copy());
setCurrentPose(sequence.size() - 1);
break;
}
switch (keyCode) {
case LEFT:
if (nCurrentPose > 0) {
setCurrentPose(nCurrentPose - 1);
}
break;
case RIGHT:
if (nCurrentPose + 1 < sequence.size()) {
setCurrentPose(nCurrentPose + 1);
}
}
}
}
void setCurrentPose(int nPose) {
nCurrentPose = nPose;
if (nPose >= 0 && nPose < sequence.size()) {
stickFigure = sequence.get(nPose);
} else {
stickFigure = null;
}
if (nPose - 1 >= 0 && nPose - 1 < sequence.size()) {
onionSkin = sequence.get(nPose - 1);
} else {
onionSkin = null;
}
}