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

Daily Creative Coding

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

3Dのトンネル #1

3D
f:id:aa_debdeb:20161017074308j:plain

3D tunnel #1 - OpenProcessing

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

float distance = 0.0;
float speed = 3;
float objStep = 35;

color c1, c2;
boolean useRect;

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 camX = map(mouseX, 0, width, -30, 30);
  float camY = map(mouseY, 0, height, -30, 30);
  camera(camX, camY, 0, 0, 0, -100, 0, 1, 0);
  stroke(c2);
  strokeWeight(2);
  noFill();
  for(float depth = 0; depth > -1500; depth -= objStep){
    pushMatrix();
    translate(0, 0, depth + distance % objStep);
    if(useRect){
      rect(0, 0, 200, 200);
    } else {
      ellipse(0, 0, 200, 200);
    }
    popMatrix();
  }
  distance += speed;
  if(distance > objStep){
    distance -= objStep;
  }
}