Daily Creative Coding

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

Peter de Jong アトラクター

f:id:aa_debdeb:20160512001022j:plain

/**
* Peter de Jong Attractor
*
* @author aa_debdeb
* @date 2016/05/12
*/

float x, y;
float a, b, c, d;

float scale = 150.0;

void setup(){
  size(640, 640);
  frameRate(360);
  fill(0, 128);
  noStroke();
  
  mousePressed();
  
}

void mousePressed(){
  background(255);
  x = random(-0.1, 0.1);
  y = random(-0.1, 0.1);
//  a = -2.24;
//  b = 0.43;
//  c = -0.65;
//  d = -2.43;
  a = random(-2.5, 2.5);
  b = random(-2.5, 2.5);
  c = random(-2.5, 2.5);
  d = random(-2.5, 2.5);
}

void draw(){
  for(int i = 0; i < 10000; i++){
    float nx = sin(a * y) - cos(b * x);
    float ny = sin(c * x) - cos(d * y); 
    translate(width / 2, height / 2);
    rect(x * scale, y * scale, 1, 1);
    x = nx;
    y = ny;
  }
}