ProcessingでGenerative art #97
Code
ArrayList<PVector> position;
int actRandomSeed = 0;
int[] colors = {#F7B839, #FA95E1, #7381FC, #000000};
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
position = new ArrayList<PVector>();
randomSeed(actRandomSeed);
background(360);
tile();
node();
}
void tile() {
int count = 20;
float w = width/count;
noStroke();
//Square
for (int j = 0; j < count; j++) {
for (int i = 0; i < count; i++) {
fill(getCol());
noStroke();
rect(i*w, j*w, w, w);
randomShape(i*w, j*w, w);
//add position
if (random(1)>0.5) {
position.add(new PVector(i*w, j*w));
}
}
}
}
void randomShape(float x, float y, float size) {
float halfSize = size/2;
fill(getCol());
pushMatrix();
translate(x + halfSize, y + halfSize);
if (random(1) > 1.0/2.0) {
rotate(HALF_PI*int(random(4)));
beginShape();
vertex(-halfSize, -halfSize);
vertex(-halfSize, halfSize);
vertex(halfSize, halfSize);
endShape(CLOSE);
}
else {
rotate(HALF_PI*int(random(4)));
beginShape();
vertex(-halfSize, -halfSize);
vertex(-halfSize, halfSize);
vertex(0, halfSize);
vertex(0, -halfSize);
endShape(CLOSE);
}
popMatrix();
}
void node() {
for (PVector p : position) {
for (PVector other : position) {
float d = dist(other.x, other.y, p.x, p.y);
if (p != other) {
if (d < 60) {
stroke(360);
strokeWeight(0.7);
line(other.x, other.y, p.x, p.y);
}
}
}
}
for (PVector p : position) {
fill(getCol());
circle(p.x, p.y, 10);
}
}
int getCol() {
return colors[(int)random(colors.length)];
}
void mousePressed() {
actRandomSeed = (int)random(100000);
position.clear();
}
void keyPressed(){
if(key == 's')saveFrame("####.png");
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!