-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeCreative.pde
More file actions
267 lines (230 loc) · 20.1 KB
/
BeCreative.pde
File metadata and controls
267 lines (230 loc) · 20.1 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
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
/*
ToDo: JavaDoc
*/
import java.util.Iterator;
boolean drawSkeletonTool = true;
String userTextInput = "";
boolean gettingUserTextInput = false;
Scene scene = new Scene();
private boolean MOTION_BLUR = true;
private PVector normPosRight = new PVector(0,0);
private PVector normPosLeft = new PVector(0,0);
boolean firstTime = true;
private ParticleSystem systemRight = new ParticleSystem();
private ParticleSystem systemLeft = new ParticleSystem();
PGraphics mixer;
PShader mixerShader;
private int numberOfParticles = 12;
private int firstSkeleton;
private int coder = 2;
private int codel = 2;
private float minHeight;
private float maxHeight;
int pdPort = 3000;
int myPort = 3001;
Communication communication = new Communication("143.106.219.176" , pdPort, myPort);//"127.0.0.1" "143.106.219.176"
private color blue1 ;
private color purple1;
private color red1;
private color red2;
private color orange;
private color yellow1;
private color yellow2;
private color pink ;
private color blu1;
private color blu2;
private color green;
private color blue2;
private color purple2;
//Estes são os valores para serem alterados
private int saturationIncrement = 1; //
private float jerkRange = 0.5; //quanto menor mais rápido aumenta a saturação
void setup() {
colorMode(HSB,360,100,100);
frameRate(scene.frameRate_);
size(500, 500, P3D);
scene.init();
green = color(100,100,100);
blue1 = color(270, 100, 100);//245
purple1 = color(295, 100, 100);//280
red1 = color(0, 100, 100);
red2 = color(359, 100, 100);
orange = color(38, 100, 100);//38
yellow1 = color(60, 100, 100);
yellow2 = color(70, 100, 100);
pink = color(315, 100, 100);
blu1 = color(180,100,100);
blu2 = color(210,100,100);//150
purple2 = color(290, 100, 100);//295
blue2 = color(240, 100, 100);//270
}
void draw() {
scene.update();
for(Skeleton skeleton:scene.activeSkeletons.values()){
firstSkeleton = skeleton.indexColor;
minHeight = (skeleton.bones[14].measuredLength+skeleton.bones[18].measuredLength)/2;
maxHeight = ((skeleton.bones[14].measuredLength+skeleton.bones[18].measuredLength)/2)+((skeleton.bones[13].measuredLength+skeleton.bones[17].measuredLength)/2)+skeleton.bones[0].measuredLength+skeleton.bones[1].measuredLength+skeleton.bones[2].measuredLength+skeleton.bones[3].measuredLength+((skeleton.bones[6].measuredLength+skeleton.bones[10].measuredLength)/2);//+((skeleton.bones[7].measuredLength+skeleton.bones[11].measuredLength)/2);
if(scene.floor.isCalibrated){
//this.numberOfParticles = int(skeleton.momentum.total/percentOfParticles);
this.normPosRight = skeleton.scene.floor.toFloorCoordinateSystem(skeleton.joints[HAND_RIGHT].estimatedPosition);
this.normPosRight.x = map(this.normPosRight.x,(-scene.floor.dimensions.x)/2,(scene.floor.dimensions.x)/2,-width/2,width/2);
this.normPosRight.y = map(this.normPosRight.y,maxHeight,minHeight,-height/2,height/2);
if(skeleton.joints[HAND_RIGHT].standartDeviationNorm < this.jerkRange){
systemRight.saturation = systemRight.saturation - this.saturationIncrement;
skeleton.joints[HAND_RIGHT].saturation = systemRight.saturation;
skeleton.joints[HAND_RIGHT].saturation = norm(skeleton.joints[HAND_RIGHT].saturation,0,100);
}
if(skeleton.joints[HAND_RIGHT].standartDeviationNorm > this.jerkRange && skeleton.joints[HAND_RIGHT].standartDeviationNorm<1){
systemRight.saturation = systemRight.saturation + this.saturationIncrement;
skeleton.joints[HAND_RIGHT].saturation = systemRight.saturation;
skeleton.joints[HAND_RIGHT].saturation = norm(skeleton.joints[HAND_RIGHT].saturation,0,100);
}
systemRight.saturation = constrain(systemRight.saturation,0,100);
if(skeleton.rightHandRondDuBras.activatedDirectionCode != 0){this.coder = skeleton.rightHandRondDuBras.activatedDirectionCode;}
systemRight.addParticles(this.normPosRight,coder);
this.normPosLeft = skeleton.scene.floor.toFloorCoordinateSystem(skeleton.joints[HAND_LEFT].estimatedPosition);
this.normPosLeft.x = map(this.normPosLeft.x,(-scene.floor.dimensions.x)/2,(scene.floor.dimensions.x)/2,-width/2,width/2);
this.normPosLeft.y = map(this.normPosLeft.y,maxHeight,minHeight,-height/2,height/2);
if(skeleton.joints[HAND_LEFT].standartDeviationNorm<0.5){
systemLeft.saturation = systemLeft.saturation - this.saturationIncrement;
skeleton.joints[HAND_LEFT].saturation = systemLeft.saturation;
skeleton.joints[HAND_LEFT].saturation = norm(skeleton.joints[HAND_LEFT].saturation,0,100);
}
if(skeleton.joints[HAND_LEFT].standartDeviationNorm>0.5 && skeleton.joints[HAND_LEFT].standartDeviationNorm<1){
systemLeft.saturation = systemLeft.saturation + this.saturationIncrement;
skeleton.joints[HAND_LEFT].saturation = systemLeft.saturation;
skeleton.joints[HAND_LEFT].saturation = norm(skeleton.joints[HAND_LEFT].saturation,0,100);
}
systemLeft.saturation = constrain(systemLeft.saturation,0,100);
if(skeleton.leftHandRondDuBras.activatedDirectionCode != 0){this.codel = skeleton.leftHandRondDuBras.activatedDirectionCode;}
systemLeft.addParticles(this.normPosLeft,codel);
communication.sendMessageToElenaProject(skeleton);
}
}
if(scene.drawScene){
scene.draw(); // measuredSkeletons, jointOrientation, boneRelativeOrientation, handRadius, handStates
firstTime = true;
} else{
// Your animation algorithm should be placed here
beginCamera();
camera();
translate(0,0,0);
rotateX(0);
rotateY(0);
endCamera();
drawBackground();
translate(width/2, height/2,0);
systemLeft.update();
systemRight.update();
}
//communication.sendScene(scene);
}
/*void paint(float x,float y,color cor){
int NUM = 500;
float mx = x;
float my = y;
color col = cor;
Particles [] particle = new Particles [NUM];
for(int j = 0; j<5;j++){
for(int i = 0; i< NUM; i++){
if(mx < width/2 && my <height/2){col = color (255,random(0,150),random(0,150));};
if(mx > width/2 && my <height/2){col = color (random(0,150),255,random(0,150));};
if(mx < width/2 && my >height/2){col = color (random(0,150),random(0,150),255);};
if(mx > width/2 && my > height/2){col = color (random(0,255),random(0,255),random(0,255));};
float divX = random(-900,900);
float divY = random(-900,900);
float distance = sqrt(divX*divX+divY*divY);
float particleR = 60* exp(-distance*0.03);
particle[i] = new Particles(mx+divX, my+divY, particleR,col);
particle[i].appear();
}
for(int i = 0; i< NUM; i++){
if(mx < width/2 && my <height/2){col = color (255,random(0,150),random(0,150));};
if(mx > width/2 && my <height/2){col = color (random(0,150),255,random(0,150));};
if(mx < width/2 && my >height/2){col = color (random(0,150),random(0,150),255);};
if(mx > width/2 && my > height/2){col = color (random(0,255),random(0,255),random(0,255));};
float divX = random(-600,600);
float divY = random(-600,600);
float distance = sqrt(divX*divX+divY*divY);
float particleR = 60* exp(-distance*0.06);
particle[i] = new Particles(mx+divX, my+divY, particleR,col);
particle[i].appear();
}
for(int i = 0; i< NUM; i++){
if(mx < width/2 && my <height/2){col = color (255,random(0,150),random(0,150));};
if(mx > width/2 && my <height/2){col = color (random(0,150),255,random(0,150));};
if(mx < width/2 && my >height/2){col = color (random(0,150),random(0,150),255);};
if(mx > width/2 && my > height/2){col = color (random(0,255),random(0,255),random(0,255));};
float divX = random(-300,300);
float divY = random(-300,300);
float distance = sqrt(divX*divX+divY*divY);
float particleR = 60* exp(-distance*0.12);
particle[i] = new Particles(mx+divX, my+divY, particleR,col);
particle[i].appear();
}
}
}*/
void drawBackground(){
color back = color(0,0,0);
if (MOTION_BLUR) {
// Background with motion blur
noStroke();
fill(back,45);
rect(0, 0, width, height);
} else {
// Normal background
noStroke();
background(back);
}
}
void keyPressed(){
if(gettingUserTextInput){
if (keyCode == BACKSPACE) {
if (userTextInput.length() > 0) {
userTextInput = userTextInput.substring(0, userTextInput.length()-1);
println(userTextInput);
}
} else if (keyCode == DELETE) {
userTextInput = "";
} else if (keyCode == RETURN || keyCode == ENTER){
gettingUserTextInput = false;
} else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
userTextInput = userTextInput + key;
println(userTextInput);
}
} else{
if(key == 'f') scene.floor.manageCalibration();
if(key == 's') scene.drawScene = !scene.drawScene;
if(key == 'm') scene.drawMeasured = !scene.drawMeasured;
if(key == 'b') scene.drawBoneRelativeOrientation = !scene.drawBoneRelativeOrientation;
if(key == 'j') scene.drawJointOrientation = !scene.drawJointOrientation;
if(key == 'h') scene.drawHandRadius = !scene.drawHandRadius;
if(key == 'H') scene.drawHandStates = !scene.drawHandStates;
if(key == 'p') scene.drawPollock = !scene.drawPollock;
if(key == 'r') scene.drawRondDuBras = !scene.drawRondDuBras;
if(key == 'c') scene.drawCenterOfMass = !scene.drawCenterOfMass;
if(key == 'M') scene.drawMomentum = !scene.drawMomentum;
}
}
void mouseDragged() {
if(mouseButton == CENTER){
scene.cameraRotX = scene.cameraRotX - (mouseY - pmouseY)*PI/height;
scene.cameraRotY = scene.cameraRotY - (mouseX - pmouseX)*PI/width;
}
if(mouseButton == LEFT){
scene.cameraTransX = scene.cameraTransX + (mouseX - pmouseX);
scene.cameraTransY = scene.cameraTransY + (mouseY - pmouseY);
systemRight.saturation = 100;
systemLeft.saturation = 100;
systemRight.addParticles(new PVector (-mouseX, -mouseY),codel);
systemLeft.addParticles(new PVector (mouseX, mouseY),coder);
}
}
void mouseWheel(MouseEvent event) {
float zoom = event.getCount();
if(zoom < 0){
scene.cameraTransZ = scene.cameraTransZ + 30;
}else{
scene.cameraTransZ = scene.cameraTransZ - 30;
}
}