見出し画像

ProcessingでGenerative art #94

beginContour()が逆向きに座標位置を指定しなきゃいけないの忘れていて30分ぐらい格闘してました。

リファレンス見るの大事。

Code

int drawMode = 1;
int actRandomSeed = 0;
Form[] forms = new Form[1000] ;

void setup(){
  size(800, 800,P2D);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
  smooth(8);
  newForm();
}

void draw(){
  randomSeed(actRandomSeed);
  background(360);
  for(int i=0; i < forms.length;i++){
    forms[i].display();
  }
}

void newForm(){
  for(int i=0; i < forms.length;i++){
    forms[i] = new Form(random(width), random(height), random(50, 300));
  }
}

void mousePressed() {
  newForm();
  actRandomSeed = (int)random(1000000);
}

void keyPressed(){
  if(key == 's')saveFrame("####.png");
  
  if(key == '1')drawMode = 1;
  if(key == '2')drawMode = 2;
}

//---------------------------------------------------------------
class Form {
  float x, y;
  float s, hs;
  float shiftHS;
  int corner;
  int[] colors1 = {#3200FF, #FF003C, #3FFF00, #FAFF00, #FFAA00, #F200FF, #00F9FF};
  int[] colors2 = {#DDFFF7, #93E1D8, #FFA69E, #AA4465, #462255};

  Form(float x, float y, float s) {
    this.x = x;
    this.y = y;
    this.s = s;
    hs = s/2;
    shiftHS = hs*0.6;
    corner = (int)random(3, 7);
  }

  void display() {
    pushMatrix();
    translate(x, y);
    rotate(random(-PI, PI));
    if(drawMode == 1)fill(getCol1());
    if(drawMode == 2)fill(getCol2());
    stroke(0);

    beginShape();
    for (float t = 0; t < TWO_PI; t+= TWO_PI/corner) {
      float x_ = hs * cos(t);
      float y_ = hs * sin(t);
      vertex(x_, y_);
    }
    beginContour();
    if (drawMode == 1)fill(320);
    if (drawMode == 2)fill(60);
    stroke(0, 0);
    for (float t = TWO_PI; t > 0; t -= TWO_PI/corner) {
      float x_ = shiftHS * cos(t);
      float y_ = shiftHS * sin(t);
      vertex(x_, y_);
    }
    endContour();
    endShape(CLOSE);
    popMatrix();
  }

  int getCol1() {
    return colors1[(int)random(colors1.length)];
  }
  int getCol2() {
    return colors2[(int)random(colors2.length)];
  }
}

Happy coding!!

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