見出し画像

ProcessingでGenerative art #96

Code

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

void draw() {
  background(30, 5, 100);
  for (int i=0; i<80; i++) {
    tile(random(width), random(height), random(50, 200), random(50, 200));
  }
}

void tile(float x, float y, float w, float h) {
  int wCount = int(random(3, 20));
  int hCount = int(random(3, 20));
  float sw = w/wCount;
  float sh = h/hCount;
  float angle = (int)random(4)*HALF_PI;

  pushMatrix();
  translate(x-15, y+15);
  rotate(angle);
  translate(-w/2, -w/2);
  noStroke();
  fill(0, 90);
  rect(0, 0, w, h);
  popMatrix();

  pushMatrix();
  translate(x, y);
  rotate(angle);
  translate(-w/2, -w/2);
  stroke(0);
  strokeWeight(0.5);
  for (int j = 0; j < hCount; j++) {
    for (int i = 0; i < wCount; i++) {
      fill(getCol());
      line(i*sw, random(-h/2), i*sw, 0);
      line(random(-w/2), j*sh, 0, j*sh);
      rect(i*sw, j*sh, sw, sh);
    }
  }
  line(w, random(-h), w, 0);
  line(random(-w), h, 0, h);
  popMatrix();
}

int[] colors = {#F95418, #11AA65, #51083E, #7A0C2B, #0F0000, #FF0C00, #FFFFFF, #34FFFA};
int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  redraw();
}

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

Happy coding!

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