ProcessingでGenerative art #75
遊びでやってみたらなんだか新しい方向性が見えました!
たまにはこんな感じにかわいいものもよいです!
Code
int count = 4;
int actRandomSeed = 0;
int drawMode = 1;
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
randomSeed(actRandomSeed);
background(360);
divideRect(40, 40, width-40, 40, width - 40, height - 40, 40, height - 40, count);
}
void divideRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, int n) {
if (n == 1) {
changeDrawMode();
beginShape();
curveVertex(x4, y4);
curveVertex(x1, y1);
curveVertex(x2, y2);
curveVertex(x3, y3);
curveVertex(x4, y4);
curveVertex(x1, y1);
curveVertex(x2, y2);
endShape(CLOSE);
float centerX = (x1 + x2 + x3 + x4) * 0.25;
float centerY = (y1 + y2 + y3 + y4) * 0.25;
if (drawMode == 1) {
fill(360);
strokeWeight((x2 - x1)* 0.07);
stroke(0);
float eye = (x2 - x1)* 0.2;
ellipse(centerX - (x2 - x1)* 0.3, centerY, eye, eye);
ellipse(centerX + (x2 - x1)* 0.3, centerY, eye, eye);
}
if (drawMode == 2) {
stroke(360);
fill(0);
//Ear
beginShape();
curveVertex(x1, y1);
curveVertex(x1, y1);
curveVertex(centerX - (x2 - x1)* 0.5, y1- (y4-y1)*0.2);
curveVertex(x1+ (x2 - x1)* 0.30, y1);
curveVertex(x1+ (x2 - x1)* 0.30, y1);
endShape();
beginShape();
curveVertex(x2, y2);
curveVertex(x2, y2);
curveVertex(centerX + (x2 - x1)* 0.5, y2- (y3-y2)*0.2);
curveVertex(x2 - (x2 - x1)* 0.30, y2);
curveVertex(x2 - (x2 - x1)* 0.30, y2);
endShape();
//Eyes
fill(360);
float eye = (x2 - x1)* 0.2;
arc(centerX - (x2 - x1)* 0.25, centerY - (y4 - y1) * 0.2, eye, eye, 0, radians(330));
arc(centerX + (x2 - x1)* 0.25, centerY - (y3 - y2) * 0.2, eye, eye, 0, radians(330));
//Whisker
float whisker = eye*0.2;
ellipse((x1+x4) * 0.5, centerY - (y4 - y1) * 0.07, eye, whisker);
ellipse((x1+x4) * 0.5, centerY + (y4 - y1) * 0.07, eye, whisker);
ellipse((x2+x3) * 0.5, centerY - (y3 - y2) * 0.07, eye, whisker);
ellipse((x2+x3) * 0.5, centerY + (y3 - y2) * 0.07, eye, whisker);
//Nose
float nose = eye * 0.6;
ellipse(centerX, centerY, nose, nose);
}
}
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 changeDrawMode() {
if (drawMode == 1) {
strokeWeight(1);
stroke(360);
int alph = 100;
if (random(1) > 0.75) {
fill(0, 80, 100, alph);
} else if (random(1) >0.50) {
fill(122, 80, 100, alph);
} else if (random(1) >0.25) {
fill(237, 80, 100, alph);
} else {
fill(307, 80, 100, alph);
}
}
if (drawMode == 2) {
strokeWeight(1);
stroke(360);
fill(0);
}
}
void mousePressed() {
actRandomSeed = (int)random(100000);
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
if (key == '1')drawMode = 1;
if (key == '2')drawMode = 2;
if (keyCode == UP)count += 1;
if (keyCode == DOWN)count -= 1;
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!