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

Daily Creative Coding

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

円を取り囲む線

/**
* line surrounding sphere
*
* @author aa_debdeb
* @date 2016/06/10
*/

float radious = 200;

float radian;

void setup(){
  size(500, 500, P3D);
  noFill();
  strokeWeight(2);
  stroke(0, 150);
  radian = 0.0;
}

void draw(){
  background(255);
  translate(width / 2, height / 2, -100);
  rotateZ(map(mouseX, 0, width, -PI / 3, PI / 3));
  rotateX(map(mouseY, 0, height, -PI / 3, PI / 3)); 
  beginShape();
  float r = radian;
  for(float y = -radious; y <= radious; y += 0.3){
    float x = radious * cos(r) * cos(asin(abs(y / radious)));
    float z = radious * sin(r) * cos(asin(abs(y / radious)));
    vertex(x, y, z);
    r += PI / 16;  
  }
  endShape();
  radian += PI / 32;
  if(radian > TWO_PI){
    radian -= TWO_PI;
  }
}