Code a Week #2: Life in a minute

This week I really didn’t have a lot of time. So I played around with Perlin noise. And Shiffman’s Nature of code book.

[p5js code canvas]
class Walker {
PVector location;

PVector noff;

Walker() {
location = new PVector(width/2, height/2);
noff = new PVector(random(1000),random(1000));
}

void display() {
noStroke();
fill(50);
ellipse(location.x, location.y, 4, 4);
}

// Randomly move up, down, left, right, or stay in one place
void walk() {

location.x = map(noise(noff.x),0,1,0,width);
location.y = map(noise(noff.y),0,1,0,height);

noff.x += (second()/10)* 0.008;
noff.y += (second()/10)* 0.008;

}
}

Walker[] w;

int total = 0;

void setup() {
size(600, 400);

w = new Walker[50];
for (int i = 0; i < w.length; i++) { w[i] = new Walker(); } background(255); } void draw() { fill(255,40); noStroke(); rect(0,0,height,width); // int o = int(map((second()*10),0,width,1,20)); noiseDetail(100,0.5); if (frameCount % 30 == 0) { total = total + 1; if (total > w.length-1) {
total = w.length-1;
}
}

for (int i = 0; i < total; i++) { w[i].walk(); w[i].display(); } }[/p5js]

Comments are closed.