Daily Creative Coding

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

車輪の回転

/**
* Wheel Rotation
*
* @author aa_debdeb
* @date 2016/01/15
*/

void setup(){
  size(500, 500);
  frameRate(30);
  smooth();
}

void draw(){
  background(255);
  fill(220, 20, 60);
  noStroke();  
  float posRad = frameCount * 0.3;
  float posR = 100;
  translate(width / 2 + posR * cos(posRad), height / 2 + posR * sin(posRad));
  rotate(frameCount * 0.07);
  float angWidth = 6.5;
  float angInterval = 0.7;
  float angle = 0.0;
  while(angle < 360){
    float innerR = 100;
    float outerR = 1000;
    beginShape();
    for(float a = angle; a <= angle + angWidth; a += 0.5){
      vertex(innerR * cos(radians(a)), innerR * sin(radians(a)));
    }
    for(float a = angle + angWidth; a >= angle; a -= 0.5){
      vertex(outerR * cos(radians(a)), outerR * sin(radians(a)));      
    }
    angle += angWidth + angInterval;
    endShape(CLOSE);
  }
}