Daily Creative Coding

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

うねる輪

/**
* rolling ring
*
* @author aa_debdeb
* @date 2016/10/03
*/

int num = 100;
float radious = 130;
float breadth = 75;

void setup(){
  size(640, 640, P3D);
}

void draw(){
  background(30);
  stroke(255);
  strokeWeight(2);
  fill(0, 255, 255, 170);
  translate(width / 2, height / 2);
  rotateX(map(mouseY, 0, height, -PI / 3, PI / 3));
  float angStep1 = TWO_PI / num;
  float angStep2 = TWO_PI * 3.0 / num;
  float t = frameCount * 0.03;
  for(int i = 0; i < num; i++){
    int j = i != num - 1? i + 1: 0;
    beginShape();
    vertex(radious * cos(i * angStep1), 0, radious * sin(i * angStep1));
    vertex((radious + breadth * cos(i * angStep2 + t)) * cos(i * angStep1), breadth * sin(i * angStep2 + t), (radious + breadth * cos(i * angStep2 + t)) * sin(i * angStep1));
    vertex((radious + breadth * cos(j * angStep2 + t)) * cos(j * angStep1), breadth * sin(j * angStep2 + t), (radious + breadth * cos(j * angStep2 + t)) * sin(j * angStep1));
    vertex(radious * cos(j * angStep1), 0, radious * sin(j * angStep1));
    endShape(CLOSE);
  }
}
f:id:aa_debdeb:20160927181527j:plain