Generative Art #106
Code
int[] colors = {#FF6F59, #FF1053, #34D1BF, #3454D1, #FFFC31};
ArrayList<PVector> node = new ArrayList<PVector>();
float dist;
float maxSize;
void setup() {
size(840, 840);
pixelDensity(2);
noLoop();
}
void draw() {
background(#176FCB);
tile();
}
void tile() {
int c = (int)random(5, 12);
float w = width/c;
dist = sqrt(sq(w)*2);
maxSize = w;
for (float j = 0; j < c+1; j++) {
for (float i = 0; i < c+1; i++) {
if (random(1) < 0.5) {
node.add(new PVector(i*w, j*w));
}
}
}
node();
noStroke();
for (float j = 0; j < c; j+= 2) {
for (float i = 0; i < c; i+= 2) {
fill(getCol(), random(100));
square(i*w, j*w, w);
}
}
for (float j = 1; j < c; j+= 2) {
for (float i = 1; i < c; i+= 2) {
fill(getCol(), random(100));
square(i*w, j*w, w);
}
}
}
void node() {
for (PVector n : node) {
for (PVector other : node) {
float d = dist(other.x, other.y, n.x, n.y);
if (n != other) {
if (d <= dist) {
stroke(255, random(50, 100));
strokeWeight(1);
line(other.x, other.y, n.x, n.y);
}
}
}
}
for (PVector n : node) {
myCircle(n.x, n.y, random(50, maxSize));
}
}
void myCircle(float x, float y, float d) {
float angle = 0;
float lastAngle = 0;
float r = random(1);
pushMatrix();
translate(x, y);
rotate(random(PI));
noStroke();
while (angle < TAU) {
gradationArc(0, 0, d, lastAngle, angle);
lastAngle = angle;
angle += random(PI*r);
}
gradationArc(0, 0, d, lastAngle, TAU);
popMatrix();
fill(getCol());
circle(x, y, random(d));
fill(getCol());
circle(x, y, random(d));
}
void gradationArc(float x, float y, float d, float start, float end) {
pushMatrix();
translate(x, y);
color c1 = color(#ffffff);
color c2 = getCol();
for (float i = d; i > 0; i -= 2) {
color c = lerpColor(c1, c2, i/d);
fill(c);
arc(0, 0, i, i, start, end, PIE);
}
popMatrix();
}
int getCol() {
return colors[(int)random(colors.length)];
}
void mousePressed() {
redraw();
node.clear();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
Happy coding
応援してくださる方!いつでもサポート受け付けてます!