ProcessingでGenerative art #48
Code
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100);
noLoop();
blendMode(SUBTRACT);
}
void draw() {
background(21, 8, 89);
pushMatrix();
translate(width * 0.7, height);
sinBranch(height * 0.75, 6);
popMatrix();
pushMatrix();
translate(width * 0.3, height);
sinBranch(height * 0.75, 6);
popMatrix();
}
void sinBranch(float len, float n) {
if (n > 0) {
n--;
float lastX = -999;
float lastY = -999;
float rad = map(len, 0, height, 0, 100);
for (float y = 0; y > -len; y--) {
float theta = radians(map(y, 0, -len, 0, 360));
float w = map(sin(radians(y)), -1, 1, n, 1);
float x = rad * pow(sin(theta), 5);
if ( lastX> -999) {
strokeWeight(w);
stroke(360, 82, 85);
line(x, y, lastX, lastY);
}
lastX = x;
lastY = y;
}
noStroke();
fill(211, 82, 85);
ellipse(lastX, lastY, (n + 1) * 6, (n + 1)* 6);
ellipse(lastX, lastY/2, (n + 1) * 6, (n + 1) * 6);
translate(0, -len/2);
len *= 0.6;
pushMatrix();
rotate(random(PI));
sinBranch(len, n);
popMatrix();
pushMatrix();
rotate(random(-PI));
sinBranch(len, n);
popMatrix();
translate(0, -len *0.83);
pushMatrix();
rotate(random(PI));
sinBranch(len, n);
popMatrix();
pushMatrix();
rotate(random(-PI));
sinBranch(len, n);
popMatrix();
}
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == ' ') {
saveFrame("####.png");
}
}
Happy coding!!
応援してくださる方!いつでもサポート受け付けてます!