ProcessingでGenerative art #51
Code
int tileCount = 50;
int actRandomSeed = 0;
float maxDist;
void setup() {
size(750, 750);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
strokeCap(PROJECT);
maxDist = sqrt(sq(width)+sq(height));
}
void draw() {
background(360);
randomSeed(actRandomSeed);
drawGrid();
}
void drawGrid() {
for (int gridY = 0; gridY< tileCount; gridY++) {
for (int gridX = 0; gridX< tileCount; gridX++) {
int posX = width/tileCount * gridX;
int posY = height/tileCount * gridY;
int toggle = (int)random(0, 2);
float w = map(dist(mouseX, mouseY, posX, posY), 0, maxDist, 0, 20);
float b = map(dist(mouseX, mouseY, posX, posY), 0, maxDist, 100, 0);
color strokeCol = color(199,93, b, 100);
if (toggle == 0) {
stroke(strokeCol);
strokeWeight(w);
line(posX, posY, posX+width/tileCount, posY+height/tileCount);
}
if (toggle == 1) {
stroke(strokeCol);
strokeWeight(w);
line(posX, posY+width/tileCount, posX+height/tileCount, posY);
}
}
}
}
void mousePressed() {
actRandomSeed = (int) random(10000);
}
void keyPressed(){
if(key == 's') saveFrame("####.png");
}
Happy coding!
参考: 『Generative Design-Processingで切り拓く、デザインの新たな地平』
応援してくださる方!いつでもサポート受け付けてます!