Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

バリステック凝集モデル

/**
* Balistic Aggregation Model
*
* @author aa_debdeb
* @date 2016/08/05
*/

int[] stacks;

void setup(){
  size(300, 300);
  frameRate(360);
  noFill();
  stroke(0);
  initialize();
}

void mousePressed(){
  initialize();
}

void initialize(){
  background(255);
  stacks = new int[width];
  for(int i = 0; i < width; i++){
    stacks[i] = height;
  }
}

void draw(){
  int x = int(random(1, width - 1));
  if(stacks[x - 1] < stacks[x] && stacks[x - 1] < stacks[x + 1]){
    stacks[x] = stacks[x - 1];
  } else if(stacks[x + 1] < stacks[x] && stacks[x + 1] < stacks[x - 1]){
    stacks[x] = stacks[x + 1];  
  } else {
    stacks[x] -= 1;
  }
  point(x, stacks[x]);
}
f:id:aa_debdeb:20160730092032j:plain