topical media & game development

graphic-processing-site-examples-Topics-Motion-Puff-Puff.pde / pde

```
```
Puff by Ira Greenberg. Series of ellipses simulating a multi-segmented organism, utilizing a follow the leader algorithm. Collision detection occurs on the organism's head, controlling overall direction, and on the individual body segments, controlling body shape and jitter.
```

// For puff head
float speedX = .7;
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];

void setup(){

size(640, 360);

// Begin in the center

// Fill body arrays
for (int i=0; i< cells; i++){
radiiX[i] = random(-7, 7);
radiiY[i] = random(-4, 4);
frequency[i]= random(-9, 9);
cellRadius[i] = random(16, 30);
}
frameRate(30);
}

void draw(){
background(0);
noStroke();
fill(255, 255, 255, 5);

for (int i =0; i< cells; i++){
if (i==0){
}
else{

// Check collision of body
if (px[i] >= width-cellRadius[i]/2 || px[i] <= cellRadius[i]/2){
cellRadius[i] = random(1, 40);
frequency[i]= random(-13, 13);
}
if (py[i] >= height-cellRadius[i]/2 || py[i] <= cellRadius[i]/2){
cellRadius[i] = random(1, 40);
frequency[i]= random(-9, 9);
}
}
// Draw puff
// Set speed of body
angle[i]+=frequency[i];
}

// Set velocity of head

// Check boundary collision of head