ProcessingでGenerative art #81
三角形を3つに分割して分割して分割して・・・・
Code
int actRandomSeed = 0;
int count = 4;
int drawMode = 1;
void setup() {
size(800, 800, P2D);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
randomSeed(actRandomSeed);
background(30);
divideTriangle(0, 0, width, 0, mouseX, mouseY, count);
divideTriangle(width, 0, width, height, mouseX, mouseY, count);
divideTriangle(width, height, 0, height, mouseX, mouseY, count);
divideTriangle(0, height, 0, 0, mouseX, mouseY, count);
}
void divideTriangle(float x1, float y1, float x2, float y2, float x3, float y3, float n) {
if (n == 1) {
getDrawMode(x1, y1, x2, y2, x3, y3);
}
n -- ;
if (n > 0) {
float random1 = map(randomGaussian(), -5, 5, 0, 1);
float randomX1 = x3 + (x1- x3) * random1;
float randomY1 = y1 + (y3 - y1) * (1 - random1);
float random2 = map(randomGaussian(), -5, 5, 0, 1);
float randomX2 = x1 + (x2- x1) * random2;
float randomY2 = y1 + (y2 - y1) * random2;
if (random(1) > 0.5) {
divideTriangle(x1, y1, randomX2, randomY2, randomX1, randomY1, n);
divideTriangle(randomX1, randomY1, randomX2, randomY2, x3, y3, n);
divideTriangle(randomX2, randomY2, x2, y2, x3, y3, n);
} else {
divideTriangle(x1, y1, randomX2, randomY2, randomX1, randomY1, n);
divideTriangle(randomX1, randomY1, randomX2, randomY2, x2, y2, n);
divideTriangle(randomX1, randomY1, x2, y2, x3, y3, n);
}
}
}
void getDrawMode(float x1_, float y1_, float x2_, float y2_, float x3_, float y3_) {
if (drawMode == 1) {
float ellipseSize = random(5);
fill(360);
strokeWeight(1);
stroke(360);
ellipse(x1_, y1_, ellipseSize, ellipseSize);
ellipse(x2_, y2_, ellipseSize, ellipseSize);
ellipse(x3_, y3_, ellipseSize, ellipseSize);
noFill();
triangle(x1_, y1_, x2_, y2_, x3_, y3_);
}
if (drawMode == 2) {
noStroke();
if (random(1) > 0.66)fill(320, random(50, 100), 100);
else if (random(1) > 0.33)fill(220, random(50, 100), 100);
else fill(20, random(50, 100), 100);
if (random(1) > 0.66) {
beginShape();
vertex(x1_, y1_);
vertex(x2_, y2_);
fill(0);
vertex(x3_, y3_);
endShape(CLOSE);
} else if (random(1) > 0.33) {
beginShape();
vertex(x3_, y3_);
vertex(x2_, y2_);
fill(0);
vertex(x1_, y1_);
endShape(CLOSE);
} else {
beginShape();
vertex(x1_, y1_);
vertex(x3_, y3_);
fill(0);
vertex(x2_, y2_);
endShape(CLOSE);
}
}
}
void mousePressed() {
actRandomSeed = (int) random(10000);
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
if (keyCode == UP)count += 1;
if (keyCode == DOWN)count -= 1;
if (key == '1')drawMode = 1;
if (key == '2')drawMode = 2;
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!