見出し画像

ProcessingでGenerative art #91

Code

Texture texture;
int actRandomSeed = 1;
int drawMode = 1;

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

void draw() {
  randomSeed(actRandomSeed);
  background(320, 3, 90);
  for (int i = 0; i < 20; i++) {
    fill(getRandomCol());
    circle(random(width), random(height), random(100, 200));
  }
  rectRecursion(0, 0, width, height, 5);
}

void rectRecursion(float x, float y, float w, float h, int n) {
  if (n == 1) {
    noFill();
    strokeWeight(1);
    stroke(getRandomCol());
    rect(x, y, w, h);
    texture = new Texture(x, y, w, h);
    texture.display();
  }
  n--;
  if (n>0) {
    float newW = map(randomGaussian(), -5, 5, 0, w);
    float newH = map(randomGaussian(), -5, 5, 0, h);
    if (drawMode == 2) {
      newW = random(w);
      newH = random(h);
    }
    rectRecursion(x, y, newW, newH, n);
    rectRecursion(x+newW, y, w-newW, newH, n);
    rectRecursion(x, y+newH, newW, h-newH, n);
    rectRecursion(x+newW, y+newH, w-newW, h-newH, n);
  }
}

int colors[] = {#FF0000, #FFF700, #FFBC00, #BC5626, #1AF5FF};
int getRandomCol() {
  return colors[int(random(colors.length))];
}

void mousePressed() {
  actRandomSeed = (int)random(12345678);
}

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

  if (key == '1')drawMode = 1;
  if (key == '2')drawMode = 2;
}

//---------------------------------------------------------------------------------

class Texture {
  float x, y, h, w;
  int wNum, hNum;
  float t;
  Texture(float x, float y, float w, float h) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    wNum = (int)random(10, 35);
    hNum = (int)random(10, 35);
    t = random(10);
  }

  void display() {
    noStroke();
    fill(getRandomCol(), 30);
    strokeWeight(0.5);
    pushMatrix();
    translate(x, y);
    for (float j = 0; j <= h; j += h/hNum) {
      for (float i = 0; i <= w; i += w/wNum) {
        pushMatrix();
        translate(i, j);
        circle(0, 0, map(noise(i * 0.01, j * 0.01, t), 0, 1, 0, 5));
        popMatrix();
      }
    }
    popMatrix();
  }
}

Happy coding!

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