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

Daily Creative Coding

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

円で多角形

インタラクション
/**
* Polygonal Shape
*
* @author aa_debdeb
* @date 2016/11/14
*/

int circleNum = 75;
float radious = 180;

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

void draw(){
  background(165, 42, 42);
  translate(width / 2, height / 2);
  rotate(frameCount * 0.03);
  int poly = int(map(mouseX, 0, width, 3, 20));
  for(int i = 0; i < circleNum; i++){
    int current = int(i / (circleNum / poly));
    float startRad = radians((360 / poly) * current);
    float stopRad = radians((360 / poly) * (current + 1));
    float amt = float(i % (circleNum / poly)) / (circleNum / poly);

    float x = lerp(radious * cos(startRad), radious * cos(stopRad), amt);
    float y = lerp(radious * sin(startRad), radious * sin(stopRad), amt);
    
    fill(240, 230, 140);
    stroke(0);
    strokeWeight(2);
    float diameter = map(mouseY, 0, height, 5, 100);
    ellipse(x, y, diameter, diameter);
  }
}