> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://ccworkshop.sketchpad.cc/sp/pad/view/ro.3-k26ogJ$L9/rev.48
 * 
 * authors: 
 *   Youssef Faltas

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// A Perlin hive + connections


//based on 
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com


Walker[] w;

int total = 50;

void setup() {
  size(600, 400);
  frameRate(20);
  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();
   
    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(255);
    noStroke();
    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;
    
    location.x = map(noise(noff.x),0,1,0,width);
    location.y = map(noise(noff.y),0,1,0,height);
    
    noff.x += 0.005;
    noff.y += 0.005;
  }
}