ProcessingでGenerative art #87
Code
float len = 600;
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
noLoop();
}
void draw() {
background(55, 10, 100);
pushMatrix();
translate(width/2, height/2);
rotate(radians(-30));
form();
popMatrix();
}
void form() {
noFill();
stroke(0);
strokeWeight(2);
line(-len, 0, len, 0);
for (float angle = 0; angle <= PI; angle += PI) {
rotate(angle);
float x = -len;
while (x < len) {
float rectW = random(50, 250);
float rectH = random(150, 500);
stroke(0);
strokeWeight(2);
line(x, 0, x, 0 + rectH);
line(x + rectW, 0, x + rectW, 0 + rectH);
drawRamdomShape(x, 0, rectW, random(rectH/2, rectH));
x += rectW;
}
}
}
void drawRamdomShape(float x_, float y_, float w_, float h_) {
noFill();
stroke(0);
strokeWeight(1);
if (random(1) > 3.0/4.0) {
for (float i = x_; i < x_ + w_ - (w_/10); i += w_/5) {
if (random(1) > 0.5) {
fill(randomFillCol());
rect(i, y_, (w_/5), h_);
}
}
} else if (random(1) > 2.0/4.0) {
for (float i = y_; i < y_ + h_; i += h_/10) {
if (random(1) > 0.5) {
fill(randomFillCol());
rect(x_, i, w_, h_/10);
}
}
} else if (random(1) > 1.0/4.0) {
for (float j = y_; j < y_ + h_; j += h_/5) {
for (float i = x_; i <= x_ + w_ - (w_/10); i += w_/5) {
if (random(1) > 0.5) {
fill(randomFillCol());
rect(i, j, w_/5, h_/5);
}
}
}
} else {
ellipseMode(CORNER);
strokeWeight(2);
fill(randomFillCol());
circle(x_, y_, w_);
}
}
color randomFillCol() {
float r = random(1);
if (r > 6.0/7.0) return color(0, 100, 100);
else if (r > 5.0/7.0) return color(37, 100, 100);
else if (r > 4.0/7.0) return color(55, 100, 100);
else if (r > 3.0/7.0) return color(216, 100, 100);
else if (r > 2.0/7.0) return color(318, 100, 100);
else if (r > 1.0/7.0) return color(117, 100, 100);
else return color(50);
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!