Daily Creative Coding

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

レスラーアトラクター

/**
* Rossler Attractor
*
* @author aa_debdeb
* @date 2016/01/31
*/

float param1 = 0.2;
float param2 = 0.2;
float param3 = 5.7;

float time;
float timeStep;
float x, y, z;

int c1 = color(240, 248, 255);
int c2 = color(70, 130, 180);

void setup(){
  size(500, 500, P3D);
  smooth();
  frameRate(360);
  sphereDetail(32);
  background(0);
  noStroke();
  
  time = 0;
  timeStep = 0.01;
  x = map(random(1), 0, 1, -1, 1);
  y = map(random(1), 0, 1, -1, 1);
  z = map(random(1), 0, 1, -1, 1);
}

void draw(){
  translate(width / 2, height / 2);
  rotateX(-PI / 4);
  rotateY(-PI / 4);
  time += timeStep;
  float r = map(sin(time), -1, 1, red(c1), red(c2));
  float g = map(sin(time), -1, 1, green(c1), green(c2));
  float b = map(sin(time), -1, 1, blue(c1), blue(c2));
  fill(r, g, b, 100);
  float dx = timeStep *(-y - z);
  float dy = timeStep * (x + param1 * y);
  float dz = timeStep * (param2 + x * z - param3 * z);
  x += dx;
  y += dy;
  z += dz;
  float sx = map(x, -20, 20, -250, 250);
  float sy = map(y, -20, 20, -250, 250);
  float sz = map(z, -30, 30, -250, 250);
  translate(sx, sy, sz);
  sphere(1);
}