Scrambled Rectangles(Processing)





by Flik
2017-10-22


Source Code

void setup() {
  size(1440, 860);
  background(80);
    int size = width/5;
    for (int y=0; y < height; y += size+0) {
      for (int x=0; x < width; x += size+0) {
        pushMatrix();
        translate(x+size/2, y+size/2);
        rotate(PI/2 * int(random(0, 4)));   
        translate(-size/2, -size/2);
        tile(size, 0, 0, 0);
        popMatrix();
      }
    }
}

void draw() {
}


void tile(float size, float x, float y, int level  ) {
  if (level<5) {
    pushMatrix();
    translate(x, y);

    noStroke();
    fill(int(random(20, 100)), 255);
    rect(0, 0, size, size);

    stroke(140);
    strokeWeight(3);
    line(0, 0, size/3, 0);
    line(2*size/3, 0, size, 0);
    line(0, size, size/3, size);
    line(2*size/3, size, size, size);
    line(0, 0, size/2, size/2);
    line(0, size, size/2, size/2);
    line(size, 0, size, size);

    pushMatrix();
    translate(1*size/3, 0);
    rotate(PI/2);
    tile(size/3, 0, 0, level + 1);
    popMatrix();

    pushMatrix();
    translate(0, size);
    rotate(-PI/2);
    tile(size/3, 0, 0, level + 1);
    popMatrix();

    pushMatrix();
    translate(size, 2*size/3);
    rotate(PI);
    tile(size/3, 0, 0, level + 1);
    popMatrix();

    popMatrix();
  }
}

댓글