/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://ccworkshop.sketchpad.cc/sp/pad/view/ro.9zxdHSMzNLR/rev.4
*
* authors:
* Tamara Nagui Khalil
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
Walker[] w;
int total = 50;
void setup() {
size(600, 400);
frameRate(50);
w = new Walker[total];
for (int i = 0; i < w.length; i++) {
w[i] = new Walker();
}
noiseDetail(4,0.6);
}
void draw() {
fill(0,120);
rect(0,0,width,height);
for (int i = 0; i < total; i++) {
w[i].walk();
fill(10*i, 2*i, 5*i);
w[i].display();
/* for (int j = 0; j < total; j++) {
// if distance between particles less than 50
// connect them!
if(dist(w[i].location.x, w[i].location.y, w[j].location.x, w[j].location.y) < 50){
strokeWeight(0.5);
stroke(255);
line(w[i].location.x, w[i].location.y, w[j].location.x, w[j].location.y);
}*/
}
}
// A random walker class!
class Walker {
PVector location, plocation;
PVector noff;
Walker() {
location = new PVector(0, 0);
plocation = new PVector(0, 0);
noff = new PVector(random(1000),random(1000));
}
void display() {
//fill(200, random(255), 60);
noStroke();
//line(location.x, location.y, 85, 75)
rect(location.x, location.y, 55, 55, 7);
// ellipse(location.x, location.y, 2, 2);
}
// Randomly move up, down, left, right, or stay in one place
void walk() {
plocation.x = location.x;
plocation.y = location.y;
plocation.z = location.z;
location.x = map(noise(noff.x),0,1,0,width);
location.y = map(noise(noff.y),0,1,0,height);
location.z = map(noise(noff.z),0,1,0,height);
noff.x += 0.005;
noff.y += 0.005;
noff.z += 0.005;
}
}