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

Daily Creative Coding

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

3D空間を高速移動する

3D
/**
* endless rollar coaster
*
* @author aa_debdeb
* @date 2016/07/13
*/

float xScale = 750;
float yScale = 750;
float zScale = 0.001;
float speed = 0.005;
float eyeZ = 10;
float ellipseWidth = 100;
float noiseX, noiseY;

void setup(){
  size(500, 500, P3D);
  noiseX = random(10000);
  noiseY = random(10000);
}

void draw(){
  background(0);
  noFill();
  stroke(255, 165, 0);
  strokeWeight(3);
  translate(width / 2, height / 2, 0);
  float x1 = getX(0);
  float y1 = getY(0);
  float x2 = getX(-eyeZ);
  float y2 = getY(-eyeZ);
  camera(x1, y1, 0, x2, y2, -eyeZ, 0, 1, 0);
  for(float z = 0; z > -500; z -= 10){
    pushMatrix();
    translate(getX(z), getY(z), z);
    ellipse(0, 0, ellipseWidth, ellipseWidth);
    popMatrix();
  }
}


float getX(float z){
  return map(noise(z * zScale - frameCount * speed + noiseX), 0, 1, -xScale, xScale);
}

float getY(float z){
  return map(noise(z * zScale - frameCount * speed + noiseY), 0, 1, -yScale, yScale);
}