Minor changes to examples, more code color tweaks for 2b8

This commit is contained in:
Casey Reas
2012-12-20 03:21:07 +00:00
parent cebf10855e
commit 234cbdd85f
13 changed files with 114 additions and 138 deletions
+23 -22
View File
@@ -9,6 +9,7 @@
* body segments, controlling body shape and jitter.
*/
// For puff head
float headX;
float headY;
@@ -17,13 +18,13 @@ float speedY = .9;
// For puff body
int cells = 1000;
float[]px= new float[cells];
float[]py= new float[cells];
float[]radiiX = new float[cells];
float[]radiiY = new float[cells];
float[]angle = new float[cells];
float[]frequency = new float[cells];
float[]cellRadius = new float[cells];
float[] px= new float[cells];
float[] py= new float[cells];
float[] radiiX = new float[cells];
float[] radiiY = new float[cells];
float[] angle = new float[cells];
float[] frequency = new float[cells];
float[] cellRadius = new float[cells];
void setup(){
@@ -34,7 +35,7 @@ void setup(){
headY = height/2;
// Fill body arrays
for (int i=0; i< cells; i++){
for (int i = 0; i < cells; i++){
radiiX[i] = random(-7, 7);
radiiY[i] = random(-4, 4);
frequency[i]= random(-9, 9);
@@ -49,42 +50,42 @@ void draw(){
fill(255, 255, 255, 5);
// Follow the leader
for (int i =0; i< cells; i++){
if (i==0){
px[i] = headX+sin(radians(angle[i]))*radiiX[i];
py[i] = headY+cos(radians(angle[i]))*radiiY[i];
for (int i = 0; i < cells; i++){
if (i == 0){
px[i] = headX + sin(radians(angle[i]))*radiiX[i];
py[i] = headY + cos(radians(angle[i]))*radiiY[i];
}
else{
px[i] = px[i-1]+cos(radians(angle[i]))*radiiX[i];
py[i] = py[i-1]+sin(radians(angle[i]))*radiiY[i];
px[i] = px[i-1] + cos(radians(angle[i]))*radiiX[i];
py[i] = py[i-1] + sin(radians(angle[i]))*radiiY[i];
// Check collision of body
if (px[i] >= width-cellRadius[i]/2 || px[i] <= cellRadius[i]/2){
if ((px[i] >= width-cellRadius[i]/2) || (px[i] <= cellRadius[i]/2)){
radiiX[i]*=-1;
cellRadius[i] = random(1, 40);
frequency[i]= random(-13, 13);
}
if (py[i] >= height-cellRadius[i]/2 || py[i] <= cellRadius[i]/2){
if ((py[i] >= height-cellRadius[i]/2) || (py[i] <= cellRadius[i]/2)){
radiiY[i]*=-1;
cellRadius[i] = random(1, 40);
frequency[i]= random(-9, 9);
}
}
// Draw puff
ellipse(px[i], py[i], cellRadius[i], cellRadius[i]);
ellipse(px[i], py[i], cellRadius[i], cellRadius[i]);
// Set speed of body
angle[i]+=frequency[i];
angle[i] += frequency[i];
}
// Set velocity of head
headX+=speedX;
headY+=speedY;
headX += speedX;
headY += speedY;
// Check boundary collision of head
if (headX >= width-cellRadius[0]/2 || headX <=cellRadius[0]/2){
if ((headX >= width-cellRadius[0]/2) || (headX <=cellRadius[0]/2)){
speedX*=-1;
}
if (headY >= height-cellRadius[0]/2 || headY <= cellRadius[0]/2){
if ((headY >= height-cellRadius[0]/2) || (headY <= cellRadius[0]/2)){
speedY*=-1;
}
}