読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

3Dのトンネル #3

f:id:aa_debdeb:20161017074748j:plain

3D tunnel #3 - OpenProcessing

/**
* 3D tunnel #3
* 
* @author aa_debdeb
* @date 2016/10/25
*/

float distance = 0.0;
float speed = 5;
float objStep = 30;

color c1, c2;
boolean useRect;
float noiseX = random(10000);
float noiseY = random(10000);
float noiseScale = 0.001;

void setup(){
  //fullScreen(P3D);
  size(640, 640, P3D);
  rectMode(CENTER);
  mousePressed();
}

void mousePressed(){
  c1 = color(random(255), random(255), random(255));
  c2 = color(random(255), random(255), random(255));
  useRect = random(1) < 0.5 ? true: false;
}

void draw(){
  background(c1);
  translate(width / 2, height / 2);
  float eyeX = map(noise(distance * noiseScale + noiseX), 0, 1, -200, 200);
  float eyeY = map(noise(distance * noiseScale + noiseY), 0, 1, -200, 200);
  float cenZ = 50;
  float cenX = map(noise((distance + cenZ) * noiseScale + noiseX), 0, 1, -200, 200);
  float cenY = map(noise((distance + cenZ) * noiseScale + noiseY), 0, 1, -200, 200);
  camera(eyeX, eyeY, 0, cenX, cenY, cenZ, 0, 1, 0);
  stroke(c2);
  strokeWeight(2);
  noFill();
  for(float depth = 0; depth < 1500; depth += objStep){
    pushMatrix();
    float objX = map(noise((distance + depth - distance % objStep) * noiseScale + noiseX), 0, 1, -200, 200);
    float objY = map(noise((distance + depth - distance % objStep) * noiseScale + noiseY), 0, 1, -200, 200);
    translate(objX, objY, depth - distance % objStep);
    float objSize = 100;
    if(useRect){
      rect(0, 0, objSize, objSize);
    } else {
      ellipse(0, 0, objSize, objSize);
    }
    popMatrix();
  }
  distance += speed;
}