Daily Creative Coding

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

ローレンツアトラクター

/**
* Lorenz Attractor
*
* @author aa_debdeb
* @date 2016/01/26
*/

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.005;
  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(){
  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);
  translate(width / 2, height / 2);
  x += timeStep * (-10.0 * x + 10 * y);
  y += timeStep * (28.0 * x - y - x * z);
  z += timeStep * ((-8.0 / 3.0) * z + x * y);
  float sx = map(x, -50, 50, -250, 250);
  float sy = map(y, -50, 50, -250, 250);
  float sz = map(z, -50, 50, -250, 250);
  translate(sx, sy, sz);
  sphere(1);
}