ProcessingでGenerative art #40
今まで作ったものを組み合わせました。
Code
ArrayList <PVector> circles;
color red;
void setup() {
size(800, 500);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
noLoop();
red = color(#F24E4E);
}
void draw() {
background(360);
pushMatrix();
translate(width*0.5, height*0.5);
rotate(radians(28));
divideRect(-width*0.75, -height*0.8, width*1.5, height*1.7, 15);
popMatrix();
strokeWeight(0.5);
circles = new ArrayList <PVector>();
addCircle();
for (int i = 0; i < circles.size(); i ++) {
PVector c = circles.get(i);
drawCircle(c.x, c.y, c.z);
}
}
void drawCircle(float _x, float _y, float d) {
pushMatrix();
translate(_x, _y);
noStroke();
float h = random(200, 250);
color c1= color(h, 100, 50);
color c2= color(h, 2, 90, 0);
for (float l = d; l > 0; l-=2) {
color c = lerpColor(c1, c2, l / d);
fill(c);
ellipse(0, 0, l, l);
}
for (int i = int(random(50)); i < d; i+= random(100)) {
noFill();
stroke(random(1) > 0.5 ? 0 : red);
if (random(1)>0.5) {
ellipse(0, 0, i, i);
} else {
float start = random(PI);
float stop = start + random(PI*2);
arc(0, 0, i, i, start, stop);
}
for (int j = 0; j < int(random(15)); j++) {
rotate(random(PI*2));
float len = random(1);
if (len > 0.7) {
line(0, 0, i/2, 0);
} else if (len > 0.6) {
line(i / 6, 0, i/2, 0);
} else if (len > 0.5) {
line(random(d/2), 0, d/2, 0);
}
noStroke();
fill(random(1) > 0.5 ? 0 : red);
float dot = random(10);
ellipse(i/2, 0, dot, dot);
}
}
popMatrix();
}
void addCircle() {
while (circles.size() < 30) {
float d = random(30, 400);
PVector pos = new PVector(random(width), random(height), d);
boolean overlapping = false;
for (PVector c : circles) {
if (dist(pos.x, pos.y, c.x, c.y) < (pos.z + c.z)/2) {
overlapping = true;
break;
}
}
if (!overlapping) {
circles.add(pos);
}
}
}
void divideRect(float x, float y, float w, float h, int n) {
float randw = map(randomGaussian(), -3, 3, 0, w);
float randh = map(randomGaussian(), -3, 3, 0, h);
strokeWeight(1);
stroke(0);
if (n>0) {
n--;
if (w>h) {
line(x+randw, y, x+randw, y+h);
divideRect(x, y, randw, h, n-1);
divideRect(x+randw, y, w-randw, h, n-1);
}
if (w<h) {
line(x, y+randh, x+w, y+randh);
divideRect(x, y, w, randh, n-1);
divideRect(x, y+randh, w, h-randh, n-1);
}
}
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == ' ') {
saveFrame("####.png");
}
}
応援してくださる方!いつでもサポート受け付けてます!