Daily Creative Coding

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

動く階段

/*
* moving steps
*
* @author aa_debdeb
* @date 2016/12/21
*/

float DISPLAY_WIDTH = 450;
float BLOCK_WIDTH = 20;
PVector loc;

void setup(){
  size(500, 500, P3D);
  noStroke();
  fill(255, 255, 0);
  loc = new PVector(random(10000), random(10000));
}

void draw(){
  background(255);
  translate(width / 2, height / 3);
  rotateX(HALF_PI / 2.5);
  rotateZ(PI / 4);
  lights();
  for(float w = -DISPLAY_WIDTH; w <= DISPLAY_WIDTH; w += BLOCK_WIDTH){
    for(float h = -DISPLAY_WIDTH; h <= DISPLAY_WIDTH; h += BLOCK_WIDTH){  
      pushMatrix();
      float blockHeight = map(noise(loc.x + w * 0.01, loc.y + h * 0.01), 0, 1, 0, 150);
      translate(w, h, blockHeight / 2);
      box(BLOCK_WIDTH, BLOCK_WIDTH, blockHeight);
      popMatrix();
    }
  }
  loc.x += map(mouseX, 0, width, -0.03, 0.03);
  loc.y += map(mouseY, 0, height, -0.03, 0.03);
}
f:id:aa_debdeb:20161217201728j:plain