Generative Art #194
Code
void setup() {
size(800, 800);
pixelDensity(2);
noLoop();
}
void draw() {
background(colors[3]);
dots();
rectRec(50, 50, width-100);
shuffleCol();
}
void dots() {
int c = 100;
float w = width/c;
noStroke();
fill(colors[4]);
for (int j=0; j<c; j++) {
for (int i=0; i<c; i++) {
float x = i*w+w/2;
float y = j*w+w/2;
ellipse(x, y, 2, 2);
}
}
}
void rectRec(float x, float y, float s) {
int c = int(random(2, 4));
float ss = s/c;
for (int i=0; i<c; i++) {
for (int j=0; j<c; j++) {
if (random(1) < 0.5 && ss > 100) {
rectRec(x+i*ss, y+j*ss, ss);
} else {
if (random(1) < 0.8) {
form(x+i*ss+ss/2, y+j*ss+ss/2, ss);
}
}
}
}
}
void form(float x, float y, float s) {
float angle = int(random(4))*HALF_PI;
float hs = s/2;
push();
translate(x, y);
rotate(angle);
stroke(colors[0]);
fill(colors[0]);
beginShape();
vertex(-hs, -hs);
vertex(hs, -hs);
vertex(hs, 0);
vertex(hs/2, 0);
bezierVertex(hs/4, 0, 0, hs/4, 0, hs/2);
vertex(0, hs);
vertex(-hs, hs);
endShape(CLOSE);
noStroke();
for (int i=0; i<4; i++) {
float d = map(i, 0, 3, hs*0.9, hs*0.3);
fill(getCol());
ellipse(hs/2, hs/2, d, d);
}
pop();
}
int[] shuffleCol() {
int[] array = colors;
int n = array.length;
int i, t;
while (n > 0) {
n--;
i = int(random(n));
t = array[n];
array[n] = array[i];
array[i] = t;
}
return array;
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
int[] colors = {#fffeff, #ff01fb, #02a9ea, #faff00, #000300};
int getCol() {
return colors[(int)random(colors.length)];
}
Happy coding!!
応援してくださる方!いつでもサポート受け付けてます!