見出し画像

ProcessingによるGenerative art作品#2

コード

int num =  3; 
Circle[] circleArr = {};
Circle thisCircle;

void setup() {
  size(700, 700);
  background(250);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
}

void draw() {
  //キーを押して描画
  if (keyPressed) {
    drawFlower();
  }
  for (int i=0; i <circleArr.length; i++) {
    thisCircle = circleArr[i];
    thisCircle.updateMe();
  }
}

void drawFlower() {
  for (int i= 0; i<num; i++) {
    thisCircle  = new Circle();
    thisCircle.drawMe(random(width), random(height));
    circleArr = (Circle[])append(circleArr, thisCircle);
  }
}

//スペースキーで保存
void keyPressed() {
  if (key == ' ') {
    saveFrame("####.png");
  }
}

//クラス
class Circle {
  //属性(フィールド)
  float angle;
  float rad; 
  float pointX, pointY; 
  float xoff, yoff;
  float xmove, ymove;
  color col;
  float xDisplace;
  float yDisplace;
  boolean rotateDirection;

  //コンストラクタ
  Circle() {
    rad = 30;    //半径
    xmove = random(-2, 2);
    ymove = random(-2, 2);
    col = color(random(360), 70, 80, 30);
    xDisplace = random(-10, 10);
    yDisplace = random(-10, 10);
    rotateDirection = random(1) > 0.5 ? true : false;
  }
  //メソッド
  void drawMe(float x, float y) {
    pointX = x;
    pointY = y;
    noStroke();
    fill(col);
    pushMatrix();
    translate(pointX, pointY);
    //50%の確率で回転方向を逆に
    if (rotateDirection) {
      rotate(angle);
    } else {
      rotate(-angle);
    }
    if (rad >= 0) {
      ellipse(0+xDisplace, 0+yDisplace, rad, rad);     //回転の中心からずらす
    }
    popMatrix();
  }
  void updateMe() {
    pointX +=  xmove;
    pointY +=  ymove;
    angle += 0.2;    //回転速度
    rad -= 0.3;    //半径を小さくしていく
    drawMe(pointX, pointY);
  }
}

前回の記事の作品をころころ弄くっただけですが。


水彩で描いた抽象画のような作品ができました。
ひとつひとつは豚のしっぽのような形をしています。
パーリンノイズをかけてみたりしたんですがどうもいい感じにならなかったので回転の中心から円を少しずらしてみたら気持ちのいいモノができてくれました。

noteに作品を100個投稿することを目指します!
まずは10!


応援してくださる方!いつでもサポート受け付けてます!