ProcessingでGenerative art #90
Code
int actRandomSeed = 0;
void setup() {
size(800, 800, P2D);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
randomSeed(actRandomSeed);
background(0);
tile();
}
void tile() {
int tileCount = int(random(4, 12));
float rectSize = width/tileCount;
for (int j = 0; j < tileCount; j++) {
for (int i = 0; i < tileCount; i++) {
rectMode(CORNER);
noFill();
stroke(0);
strokeWeight(2);
square(i*rectSize, j*rectSize, rectSize);
if (random(1) > 0.5) {
gradationRect(i*rectSize + rectSize/2, j*rectSize + rectSize/2, rectSize, rectSize);
}
if (random(1) > 0.5) {
strokeWeight(1);
circle(i*rectSize + rectSize/2, j*rectSize + rectSize/2, rectSize);
}
if (random(1) > 0.5) {
rects(i*rectSize, j*rectSize, rectSize);
}
}
}
}
void rects(float x, float y, float size) {
pushMatrix();
translate(x, y);
rectMode(CENTER);
strokeWeight(0.5);
noFill();
float count = int(random(3, 7));
float rectSize = size/count;
float sRectSize = rectSize*random(0.5, 1);
for (float j = 0; j < count; j++) {
for (float i =0; i < count; i++) {
gradationRect(i * rectSize + rectSize/2, j * rectSize + rectSize/2, sRectSize, sRectSize);
}
}
popMatrix();
}
void gradationRect(float x, float y, float w_, float h_) {
//rectMode(CENTER);
float cw = w_/2;
float ch = h_/2;
push();
fill(Randomcol());
if (random(1) > 3.0/4.0) {
beginShape();
vertex(x-cw, y-ch);
vertex(x+cw, y-ch);
fill(360);
vertex(x+cw, y+ch);
vertex(x-cw, y+ch);
endShape(CLOSE);
} else if (random(1) > 2.0/4.0) {
beginShape();
vertex(x-cw, y+ch);
vertex(x-cw, y-ch);
fill(360);
vertex(x+cw, y-ch);
vertex(x+cw, y+ch);
endShape(CLOSE);
} else if (random(1) > 1.0/4.0) {
beginShape();
vertex(x+cw, y-ch);
vertex(x+cw, y+ch);
fill(360);
vertex(x-cw, y+ch);
vertex(x-cw, y-ch);
endShape(CLOSE);
} else {
beginShape();
vertex(x+cw, y+ch);
vertex(x-cw, y+ch);
fill(360);
vertex(x-cw, y-ch);
vertex(x+cw, y-ch);
endShape(CLOSE);
}
pop();
}
void circle(float x, float y, float diameter) {
float radius = diameter/2;
color col1 = Randomcol();
pushMatrix();
translate(x, y);
rotate(random(PI));
beginShape();
fill(Randomcol());
for (float theta = 0; theta <= TWO_PI; theta += radians(1)) {
float posX = radius * cos(theta);
float posY = radius * sin(theta);
if (theta > TWO_PI/2) {
fill(col1);
}
vertex(posX, posY);
}
endShape();
popMatrix();
}
int colors[] = {#FF27BF, #0DF9FF, #FEFF03, #FF0303};
int Randomcol() {
return colors[int(random(colors.length))];
}
void mousePressed() {
actRandomSeed = (int)random(100000);
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
Happy coding!!
応援してくださる方!いつでもサポート受け付けてます!