-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dancer.pde
154 lines (142 loc) · 3.4 KB
/
Dancer.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
class Dancer{
boolean isDancing = false;
boolean isFrowning = false;
boolean isCrying = false;
PVector location;
PVector velocity;
PVector acceleration;
PVector[] tearLocation = new PVector[10];
int tearEye = 1;
int tearSpeed = (int)(Math.random()*2)+1;
int size;
int rColor = (int)(Math.random()*127)+127;
int gColor = 200;
int bColor = (int)(Math.random()*127)+127;
float squishOffset, squishSpeed = 1;
float noiseIndex = 0, bounceIndex = 0, bounceIncr;
float haloSize;
float haloIndex = 0;
Dancer(int x, int y, int s){
location = new PVector(x,y);
velocity = new PVector(Math.random()-0.5,0);
bounceIncr = (Math.random()*0.5) + 0.07;
size = s;
for(int i = 0; i<tearLocation.length; i++){
tearLocation.x = location.x + size/2;
tearLocation.y = location.y + size/10;
}
}
void update(){
acceleration = new PVector((noise(noiseIndex) - 0.5)*0.01,0);
noiseIndex += 1;
velocity.add(acceleration);
location.add(velocity);
checkXBounds();
//Actually Drawing the Dancer
beginShape();
noStroke();
fill(rColor,gColor,bColor, 180);
ellipse(location.x,location.y,size + squishOffset,size);
fill(0);
ellipse(location.x - (size*0.2) ,location.y - (size*0.1), size*0.2, size*0.2);
ellipse(location.x + (size*0.2) ,location.y - (size*0.1), size*0.2, size*0.2);
drawMouth();
endShape();
if(isDancing){
squish();
bounce();
danceHalo();
}
if(isCrying){
cry();
}
else{
velocity.y = 0;
}
}
void drawMouth(){
fill(200,0,0);
if(isDancing){
vertex(location.x-(size*0.2),location.y+(size*0.2));
vertex(location.x,location.y+(size*0.4));
vertex(location.x+(size*0.2),location.y+(size*0.2));
vertex(location.x-(size*0.2),location.y+(size*0.2));
}
else if(isFrowning){
vertex(location.x,location.y+(size*0.2));
vertex(location.x-(size*0.2),location.y+(size*0.3));
vertex(location.x+(size*0.2),location.y+(size*0.3));
vertex(location.x,location.y+(size*0.2));
}
else{
ellipse(location.x, location.y + (size*0.2), size*0.4,size*0.1);
}
}
void checkXBounds(){
if((location.x>width) || (location.x<0)){
velocity.x *= -1;
}
}
void checkYBounds(){
if((location.y>400) || (location.y<0)){
velocity.y *= -1;
}
}
void squish(){
if(squishOffset < 0 || squishOffset > 10){
squishSpeed *= -1;
}
squishOffset += squishSpeed;
}
void bounce(){
checkYBounds();
velocity.y = sin(bounceIndex);
//println(velocity.y);
bounceIndex += bounceIncr;
if (bounceIndex >= 2 * PI){
bounceIndex -= 2 * PI;
};
}
void danceHalo(){
strokeWeight(3);
stroke(0,255,0,100);
haloSize = abs(sin(haloIndex)*2);
haloIndex += 0.1;
noFill();
ellipse(location.x,location.y,size*haloSize,size*haloSize);
}
void startDancer(){
for(int i = 0; i < dancer.length; i++)
if(!dancer[i].isDancing){
dancer[i].isDancing = true;
setNotePlayable();
numDancersDancing++;
break;
}
}
void stopDancer(){
for(int i = dancer.length - 1; i >= 0; i--){
if(dancer[i].isDancing){
dancer[i].isDancing = false;
setNoteUnplayable();
numDancersDancing--;
break;
}
}
}
void cry(){
fill(0,0,255,100);
tearLocation.x = location.x + (size/5*tearEye);
ellipse(tearLocation.x,tearLocation.y,2,5);
tearLocation.y+=tearSpeed;
if(tearLocation.y > 400 + size/2){
tearLocation.y = location.y + size/10;
tearEye *= -1;
}
}
}
/*
void mousePressed(){
dancer[0].startDancer();
}
*/