ProcessingでGenerative art #47
Code
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
noLoop();
}
void draw() {
drawRect(0, 0, width, height);
drawCircle(width/2, height/2, 200, 5);
}
void drawCircle(float x, float y, float d, int n) {
pushMatrix();
translate(x, y);
circle(0, 0, d);
n--;
if (n > 0) {
for (float angle = 0; angle < TWO_PI; angle += TWO_PI / 3 ) {
pushMatrix();
rotate(angle);
float len = d*random(1, 2);
stroke(0);
line(d/2, 0, len - d*0.3, 0);
drawCircle(len, 0, d*0.6, n);
popMatrix();
}
}
popMatrix();
}
void drawRect(float _x, float _y, float _w, float _h) {
color c1 = color(214, 10, 90);
color c2 = color(72, 40, 99);
noStroke();
for (float s=_w; s>0; s-=1) {
color c = lerpColor(c1, c2, s/_w);
fill(c);
rect(_x, _y, s, _h);
}
}
void circle(float x_, float y_, float d) {
pushMatrix();
translate(x_, y_);
noStroke();
fill(random(360), 80, 80);
ellipse(0, 0, d, d);
stroke(random(360), 80, 80, 20);
for (float i = d/2; i > 0; i-=random(1)) {
for (float theta = radians(random(1)); theta < TWO_PI; theta += radians(random(2))) {
float x = i * cos(theta);
float y = i * sin(theta);
point(x, y);
}
}
popMatrix();
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!