Codecember 2020 #13

#codecember

int maxAge = 200 , n = 100, maxRange = 150;
ArrayList<PVector> fromPath = new ArrayList<PVector>();
ArrayList<PVector> toPath = new ArrayList<PVector>();
ArrayList<Float> age = new ArrayList<Float>();

void setup() {
  fullScreen();
  //size(600,600);
  for(int i = 0; i < n; i++) {
    fromPath.add(new PVector(random(width),random(height)));
    toPath.add(new PVector(random(height),random(height)));
    age.add((float)random(maxAge));
  }
  colorMode(HSB);
}
void draw() {
  background(0);
  stroke(255);
  for(int i = 0; i < n; i++) {
    age.set(i,age.get(i)+1);
    circle( map(age.get(i),0,maxAge,fromPath.get(i).x,toPath.get(i).x), map(age.get(i),0,maxAge,fromPath.get(i).y,toPath.get(i).y),4);
    if(age.get(i) > maxAge) {
      fromPath.set(i,toPath.get(i));
      toPath.set(i,new PVector(random(width),random(height)));
      age.set(i,(float)0);
    }
  }
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
    float x1 = map(age.get(i),0,maxAge,fromPath.get(i).x,toPath.get(i).x);
    float y1 = map(age.get(i),0,maxAge,fromPath.get(i).y,toPath.get(i).y);
    
    float x2 = map(age.get(j),0,maxAge,fromPath.get(j).x,toPath.get(j).x);
    float y2 = map(age.get(j),0,maxAge,fromPath.get(j).y,toPath.get(j).y);
    if(dist(x1,y1,x2,y2) < maxRange) {
      stroke(map(dist(x1,y1,x2,y2),0,maxRange,0,255),255,255, 255-map(dist(x1,y1,x2,y2),0,maxRange,0,255));
      line(x1,y1,x2,y2);
    }
  }
}

2 Likes