Generative Art #124
Code
int count = 4;
void setup() {
size(840, 840);
pixelDensity(2);
noLoop();
}
void draw() {
background(#ffffff);
squareRec(0, 0, width, count);
powder();
}
void squareRec(float x, float y, float s, int n) {
form(x, y, s);
n--;
if (n >= 0) {
float probability = map(n, 0, count-1, 0.3, 0);
float hs = s/2;
if (random(1) > probability) {
squareRec(x, y, hs, n);
squareRec(x+hs, y, hs, n);
squareRec(x+hs, y+hs, hs, n);
squareRec(x, y+hs, hs, n);
}
}
}
void form(float x, float y, float s) {
color c = getCol();
strokeWeight(0.5);
stroke(0);
fill(c);
square(x, y, s);
fill(10, 120);
noStroke();
if (random(1) > 0.66) {
rect(x, y + s/2, s, s/2);
} else if (random(1) > 0.33) {
beginShape();
vertex(x, y);
vertex(x + s, y);
vertex(x + s, y + s);
vertex(x, y + s);
vertex(x + s/2, y + s/2);
endShape();
beginShape();
vertex(x + s, y);
vertex(x + s/2, y + s/2);
vertex(x + s, y + s);
endShape();
} else {
beginShape();
vertex(x + s*0.5, y);
vertex(x + s, y);
vertex(x + s, y + s);
vertex(x, y + s);
vertex(x, y + s*0.5);
vertex(x + s*0.5, y + s*0.5);
endShape();
beginShape();
vertex(x + s*0.5, y);
vertex(x + s, y);
vertex(x + s, y + s);
vertex(x + s*0.5, y + s*0.5);
endShape();
}
}
void powder() {
for (int i = 0; i < 500000; i ++) {
stroke(255, 30);
strokeWeight(0.4);
point(random(width), random(height));
}
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
int[] colors = {#d7263d, #f46036, #2e294e, #1b998b, #c5d86d};
int getCol() {
return colors[(int)random(colors.length)];
}
薄い黒の図形を重ねて陰っぽく。
陰影でいう陰。
もっと面白い陰のつけ方がありそうな気がする。
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!