【Processing】ピクセル取得してランダムウォーク

 

 

PImage img; //画像のオブジェクトを宣言
float x,y;
float area; 
float xp = random(-1,1);
float yp = random(-1,1);
color c;
boolean start = false;

void setup(){
img = loadImage("snj.jpg"); //画像をロードする
size(559,800);   //画面サイズ
image(img,0,0,width,height); //画像を表示
x = int(random(width));
y = int(random(height));
c = get(int(x),int(y));
area = 10;
}

void draw(){
  if(start == true){
  for(int i = 0 ; i < 1000 ; i++){
  area = (red(c) + green(c) + blue(c))/3;
  stroke(c);
  fill(c);
  rectMode(CENTER);
  rect(x,y,area/30,area/30);
  x += xp;
  y += yp;
  area -= (abs(xp*10) + abs(yp*10))*20;
  xp = random(-1,1);
  yp = random(-1,1);
  c =  color(red(c)-0.0001 , green(c)-0.0001 , blue(c)-0.0001);
  
  if(area < 0 || 
     x < 0 || x > width ||
     y < 0 || y > height){
   x = int(random(width)); 
   y = int(random(height));
   c = get(int(x),int(y));
   area = 10;
   }
  }
   println(area);
  }
}


void mousePressed(){
start = true;
}