【Processing】リサージュ曲線を描画に使う(5)〜ellipse2()をゆらしながら動かす〜



またまた自分で作った関数を使うシリーズ。
そろそろネタ切れ。
今回は色とサイズと変えながら、ゆらゆら動かして描画。
次はnoise()をつかってみようか。

float a;
float b = random(2,10);
float c1 = random(255);
float c2 = random(255);
float c3 = random(255);
float d = random(10,30);

void setup() {
  size(1200, 600);
  background(250);
  a = height;
}

void draw() {
  a -= abs(cos(radians(frameCount)));

  color strokeColor =color(c1,a, a*b,c3);
  color fillColor = color(a/2, random(c2),  c3, width - a);

  ellipse2( b*b*cos(radians(frameCount))+ width/2,a, 
    width/2+ b*b, a/10, 
    1, (int)d, 
    strokeColor, fillColor);


  if (a < 0) {
    save("save/save.jpg");
    stop();
  }
}


//リサージュ設定付きのellipse()-------
void ellipse2(float x, float y, 
  float radiusX, float radiusY, 
  int risaX, int risaY, 
  color st, 
  color fi) {
  int degree = 0;
  float rx, ry;
  float prx, pry ;

  if (risaX%2 == 0) {
    //risaX++;
  } //奇数にする
  if (risaY%2 == 0) {
    //risaY++;
  } //奇数にする

  pushMatrix();
  translate(x, y);

  for (int i = 0; i < 360; i++) {
    degree = i;

    rx = radiusX*cos(radians(degree*risaX));
    ry = radiusY*sin(radians(degree*risaY));       
    prx = radiusX*cos(radians((-1 + degree)*risaX));
    pry = radiusY*sin(radians((-1+ degree)*risaY)); 

    noStroke();  
    fill(fi);
    beginShape();

    if (  risaX <=  risaY ) {
      vertex(0, 0);
      vertex(prx, 0); 
      vertex(prx, pry);  
      vertex(rx, ry);
      vertex(rx, 0); 
      vertex(0, 0);
    } else {
      vertex(0, 0);
      vertex(0, pry); 
      vertex(prx, pry);  
      vertex(rx, ry);
      vertex(0, ry); 
      vertex(0, 0);
    }
    endShape(CLOSE);
  }

  for (int i = 0; i < 360; i++) {
    degree = i;

    rx = radiusX*cos(radians(degree*risaX));
    ry = radiusY*sin(radians(degree*risaY));       
    prx = radiusX*cos(radians((-1 + degree)*risaX));
    pry = radiusY*sin(radians((-1+ degree)*risaY)); 
    noFill();
    strokeWeight(0.1);
    stroke(st);
    line(prx, pry, rx, ry);
  }
  popMatrix();

}