/
monster_generator.pde
301 lines (246 loc) · 7.22 KB
/
monster_generator.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*--------------------------------------------------------------------------------
MONSTER GENERATOR
Interactive Art & Computational Design
M. Yvonne Hidle (yvonnehidle@gmail.com)
--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
// ALL OUR GLOBAL VARIABLES ARE HERE
/*--------------------------------------------------------------------------------*/
// MY IMAGES
PImage bg;
// IS THE MOUSE OVER THE CRITTER
boolean overCritter = false;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;
// CRITTER VARIABLES
// gravity, wind, and life bitches
PVector wind;
PVector gravity;
// control the position of the body
body myBody;
PVector body_location;
PVector body_velocity;
float body_numPoints;
float body_noiseFactor;
float body_shapeSize;
float body_fluff;
// control the position of the eyes
eyes myEyes;
float eyesX;
float eyesY;
float eyes_n1;
float eyes_n2;
int eyes_rollNumber;
// control the position of the ears
ears myEars;
int ears_rollNumber;
float earsX;
float earsY;
float ears_branchRot1;
float ears_branchRot2;
float ears_antlerWidth1;
float ears_antlerWidth2;
// roll a random color
int randomC1;
int randomC2;
int randomC3;
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
void setup()
{
size(800, 600);
smooth();
frameRate(60);
// IMAGES
bg = loadImage("paperbg.png");
// BODY PART VARIABLES
// gravity, wind, and life bitches
wind = new PVector(0.01,0);
gravity = new PVector(0,0.1);
// body
myBody = new body();
body_location = new PVector(width/2,height/2);
body_velocity = new PVector(0,0);
body_numPoints = 3000;
body_noiseFactor = 10;
body_shapeSize = int( random(60,80) );
body_fluff = 10;
// eyes
myEyes = new eyes();
eyesX = body_location.x;
eyesY = body_location.y-10;
eyes_n1 = random(20,30);
eyes_n2 = random(35,50);
eyes_rollNumber = int( random(1,5) );
// ears
myEars = new ears();
ears_rollNumber = int( random(1,3) );
earsX = body_location.x-10;
earsY = body_location.y-40;
ears_branchRot1 = random(0, 1);
ears_branchRot2 = random(-1,1);
ears_antlerWidth1 = random(20,50);
ears_antlerWidth2 = random(30,80);
// GENERATE MONSTER COLORS
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
// we don't want white so please reroll
if(randomC1>230 && randomC2>230 && randomC3>230)
{
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
}
// we don't want black so please reroll
if(randomC1<30 && randomC2<30 && randomC3<30)
{
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
}
}
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
void draw()
{
background(bg);
// IS THE MOUSE OVER THE CRITTER?
if (mouseX > body_location.x-body_shapeSize && mouseX < body_location.x+body_shapeSize && mouseY > body_location.y-body_shapeSize && mouseY < body_location.y+body_shapeSize)
{
overCritter = true;
if(!locked)
{
}
}
else
{
overCritter = false;
}
//println(overCritter);
// DRAW MONSTER
drawMonster();
// GENERATE A NEW CRITTER WHEN YOU PRESS "R"
if (keyPressed==true)
{
if (key =='r')
{
generateNew();
}
}
// SHOW FRAMERATE
pushStyle();
textSize(12);
stroke(0);
fill(0);
text(frameRate, 20,20);
popStyle();
}
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
void drawMonster()
{
// CRITTER BODY MOVEMENT
myBody.applyForce(wind);
myBody.applyForce(gravity);
myBody.update();
myBody.checkEdges(body_shapeSize);
// DRAW MONSTER PARTS
myEars.drawMe(ears_rollNumber, ears_branchRot1, ears_branchRot2, ears_antlerWidth1, ears_antlerWidth2);
myBody.drawMe(body_numPoints, body_noiseFactor, body_shapeSize, body_fluff);
myEyes.drawMe(eyes_n1, eyes_n2, eyes_rollNumber);
// ATTACH BODY PARTS TO THE CRITTER
// eyes
eyesX = body_location.x;
eyesY = body_location.y-10;
// ears
earsX = body_location.x-10;
earsY = body_location.y-40;
ears_branchRot1 = sin( radians(frameCount) );
ears_branchRot2 = cos( radians(frameCount) );
}
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
// USE THE MOUSE TO MOVE THE CRITTER
/*--------------------------------------------------------------------------------*/
void mousePressed()
{
// PICK UP OUR CRITTER
if(overCritter == true)
{
locked = true;
}
else
{
locked = false;
}
xOffset = mouseX-body_location.x;
yOffset = mouseY-body_location.y;
}
void mouseDragged()
{
if(locked == true)
{
// LOCK ALL BODY PARTS
// body
body_location.x = mouseX-xOffset;
body_location.y = mouseY-yOffset;
body_fluff = -5;
// eyes
eyesX = body_location.x;
eyesY = body_location.y-10;
// ears
earsX = body_location.x-10;
earsY = body_location.y-40;
ears_branchRot1 = sin( radians(frameCount) );
ears_branchRot2 = cos( radians(frameCount) );
ears_antlerWidth1 = ears_antlerWidth1 + 0.1;
ears_antlerWidth2 = ears_antlerWidth2 + 0.1;
}
}
void mouseReleased()
{
locked = false;
body_fluff = 10;
}
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
// WHEN YOU PRESS ANY KEY, RESET THE VARIABLES
// GENERATE A DIFFERENT CRITTER
/*--------------------------------------------------------------------------------*/
void generateNew()
{
// GENERATE MONSTER COLORS
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
// we don't want white so please reroll
if(randomC1>200 && randomC2>200 && randomC3>200)
{
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
}
// we don't want black so please reroll
if(randomC1<30 && randomC2<30 && randomC3<30)
{
randomC1 = int( random(0,300) );
randomC2 = int( random(0,300) );
randomC3 = int( random(0,300) );
}
// GENERATE RANDOM VARIABLES
// body
body_shapeSize = int( random(60,80) );
// eyes
eyes_n1 = random(20,30);
eyes_n2 = random(35,50);
eyes_rollNumber = int( random(1,5) );
// ears
ears_rollNumber = int( random(1,3) );
ears_branchRot1 = random(0, 1);
ears_branchRot2 = random(-1,1);
ears_antlerWidth1 = random(20,50);
ears_antlerWidth2 = random(30,80);
}
/*--------------------------------------------------------------------------------*/