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

Daily Creative Coding

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

リングの上で回転する線がつくるパターン #5

f:id:aa_debdeb:20161111194042j:plain

patterns by lines on ring #5 - OpenProcessing

/**
* patterns by lines on ring #5
* 
* @author aa_debdeb
* @date 2016/11/15
*/

float radius = 150;
float bar = 150;

int barNum;
float barSpeed;
int rotNum;
float rotSpeed;
color bg, sr;

void setup(){
  size(640, 640);
  stroke(20, 100);
  mousePressed();
}

void draw(){
  background(240);
  translate(width / 2, height / 2);
  for(float angle = 0; angle < 360; angle += 0.5){
    float radian = radians(angle);
    pushMatrix();
    translate(radius * cos(radian), radius * sin(radian));
    rotate(radian + radian * rotNum + frameCount * rotSpeed);
    float b = map(sin(radian + radian * barNum + frameCount * barSpeed), -1, 1, 0, bar);
    line(-b / 2, 0, b / 2, 0);
    popMatrix();
  }
}

void mousePressed(){
  rotNum = int(random(1) * 50) * 2;
  rotSpeed = map(random(1), 0, 1, -0.25, 0.25);
  barNum = int(random(1) * 50) * 2;
  barSpeed = map(random(1), 0, 1, -0.25, 0.25);
  bg = color(random(255), random(255), random(255));
  sr = color(random(255), random(255), random(255));
}