ProcessingでGenerative art #78
Code
int count = 5;
int actRandomSeed = 0;
int drawMode = 1;
int posZ =-100;
void setup() {
size(800, 800, OPENGL);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
randomSeed(actRandomSeed);
background(233, 4, 90);
lights();
translate(width/2, height/2, posZ);
rotateX(map(mouseY, 0, height, PI, -PI));
rotateY(map(mouseX, 0, width, -PI, PI));
translate(-width/2, -height/2);
divideRect(10, 10, width-10, 10, width - 10, height - 10, 10, height - 10, count);
}
void divideRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, int n) {
if (n == 1) {
if (drawMode == 1) {
if (random(1) > 0.5) {
noStroke();
if (random(1) > 0.75) {
fill(0, 100, 100);
} else if (random(1) >0.50) {
fill(240, 100, 100);
} else if (random(1) >0.25) {
fill(360);
} else {
fill(58, 100, 100);
}
} else {
strokeWeight(1);
noFill();
if (random(1) > 0.75) {
stroke(0, 100, 100);
} else if (random(1) >0.50) {
stroke(240, 100, 100);
} else if (random(1) >0.25) {
stroke(360);
} else {
stroke(58, 100, 100);
}
}
}
if (drawMode == 2) {
strokeWeight(0.5);
stroke(0);
fill(190, 100, random(0, 100));
}
if (drawMode == 3) {
noStroke();
if (random(1) > 0.75) {
fill(27, 70, 100);
} else if (random(1) >0.7) {
fill(0, 100, 100);
} else if (random(1) >0.65) {
fill(320, 46, 100);
} else if (random(1) >0.6) {
fill(0);
} else if (random(1) >0.4) {
fill(181, 54, 100);
} else {
fill(360);
}
}
drawBox(x1, y1, x2, y2, x3, y3, x4, y4);
}
n--;
if (n > 0) {
float randomPointX = map(randomGaussian(), -5, 5, (x1+x4)/2, (x2+x3)/2);
float randomPointY = map(randomGaussian(), -5, 5, (y1+y2)/2, (y3+y4)/2);
divideRect(x1, y1, (x2+x1)/2, ( y1+y2)/2, randomPointX, randomPointY, (x1+x4)/2, (y4+y1)/2, n);
divideRect((x2+x1)/2, ( y1+y2)/2, x2, y2, (x2+x3)/2, (y2+y3)/2, randomPointX, randomPointY, n);
divideRect(randomPointX, randomPointY, (x2+x3)/2, (y2+y3)/2, x3, y3, (x3+x4)/2, (y3+y4)/2, n);
divideRect((x1+x4)/2, (y1+y4)/2, randomPointX, randomPointY, (x3+x4)/2, (y3+y4)/2, x4, y4, n);
}
}
void drawBox(float x1_, float y1_, float x2_, float y2_, float x3_, float y3_, float x4_, float y4_) {
float z = map(noise(x1_ * 0.01, y1_ * 0.01), 0, 1, 0, 200);
//奥
beginShape(QUADS);
vertex(x1_, y1_, 0);
vertex(x2_, y2_, 0);
vertex(x3_, y3_, 0);
vertex(x4_, y4_, 0);
//前
vertex(x1_, y1_, z);
vertex(x2_, y2_, z);
vertex(x3_, y3_, z);
vertex(x4_, y4_, z);
//右
vertex(x3_, y3_, z);
vertex(x2_, y2_, z);
vertex(x2_, y2_, 0);
vertex(x3_, y3_, 0);
//左
vertex(x1_, y1_, z);
vertex(x4_, y4_, z);
vertex(x4_, y4_, 0);
vertex(x1_, y1_, 0);
//上
vertex(x2_, y2_, z);
vertex(x1_, y1_, z);
vertex(x1_, y1_, 0);
vertex(x2_, y2_, 0);
//下
vertex(x4_, y4_, z);
vertex(x3_, y3_, z);
vertex(x3_, y3_, 0);
vertex(x4_, y4_, 0);
endShape();
}
void mousePressed() {
actRandomSeed = (int)random(100000);
noiseSeed((int)random(1000));
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
if (key == '1')drawMode = 1;
if (key == '2')drawMode = 2;
if (key == '3')drawMode = 3;
if (keyCode == RIGHT)count += 1;
if (keyCode == LEFT)count -= 1;
if (keyCode == UP)posZ += 10;
if (keyCode == DOWN)posZ -= 10;
}
Happy coding!!
応援してくださる方!いつでもサポート受け付けてます!