Generative Art #196
Code
void setup() {
size(800, 800);
pixelDensity(2);
noLoop();
}
void draw() {
background(255);
rectRec(0, 0, width);
}
void rectRec(float x, float y, float s) {
int c = int(random(2, 4));
float ss = s/c;
for (int i=0; i<c; i++) {
for (int j=0; j<c; j++) {
if (random(1) < 0.5 && ss > 100) {
rectRec(x+i*ss, y+j*ss, ss);
} else {
float xx = x+i*ss+ss*0.5;
float yy = y+j*ss+ss*0.5;
fill(getCol(), 100);
stroke(255);
rect(x+i*ss, y+j*ss, ss, ss);
push();
translate(xx, yy);
rotate(int(random(4))*HALF_PI);
form(0, 0, ss);
pop();
}
}
}
}
void form(float x, float y, float s) {
float off = s*0.1;
color col = getCol();
float earX = s*0.3;
float earY = -s*0.35;
float earS = s*0.42;
float earA = PI*0.2;
float eyeX = s*0.245;
float eyeY = -s*0.01;
float eyeS = s*0.2;
float eyeA = PI*0.10;
float noseY = s*0.1;
float noseS = s*0.2;
float mouthS = s*0.25;
float mouthY = noseY+s*0.07;
push();
translate(x, y+off);
//Ear
noStroke();
fill(col, 10);
push();
translate(earX, earY);
rotate(earA);
grdCircle(0, 0, earS, earS*0.8);
pop();
push();
translate(-earX, earY);
rotate(-earA);
grdCircle(0, 0, earS, earS*0.8);
pop();
//Face
fill(col, 25);
grdCircle(0, 0, s, s*0.8);
//Nose
fill(255, 5);
grdCircle(0, 0+s*0.2, s*0.7, s*0.4);
fill(0);
ellipse(0, noseY, noseS, noseS*0.5);
//Mouth
noFill();
stroke(0);
strokeWeight(s*0.01);
line(0, noseY, 0, mouthY);
beginShape();
curveVertex(mouthS, -mouthY);
curveVertex(mouthS, mouthY);
curveVertex(mouthS/2, mouthY*1.4);
curveVertex(0, mouthY);
curveVertex(0, -mouthY);
endShape();
beginShape();
curveVertex(-mouthS, -mouthY);
curveVertex(-mouthS, mouthY);
curveVertex(-mouthS/2, mouthY*1.4);
curveVertex(0, mouthY);
curveVertex(0, -mouthY);
endShape();
//Eyes
noStroke();
push();
translate(0-eyeX, eyeY);
rotate(-eyeA);
fill(0);
ellipse(0, 0, eyeS, eyeS*0.5);
fill(255, 230);
ellipse(s*0.025, -s*0.015, eyeS*0.25, eyeS*0.25);
pop();
push();
translate(0+eyeX, eyeY);
rotate(eyeA);
fill(0);
ellipse(0, 0, eyeS, eyeS*0.5);
fill(255, 230);
ellipse(-s*0.025, -s*0.015, eyeS*0.25, eyeS*0.25);
pop();
pop();
}
void grdCircle(float x, float y, float w, float h) {
int c = 100;
noStroke();
push();
translate(x, y);
for (int i=0; i<c; i++) {
float a = map(i, 0, c-1, 0, PI);
arc(0, 0, w, h, (PI*1.5)-a, (PI*1.5)+a, CHORD);
}
pop();
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
int[] colors = {#ffbe0b, #fb5607, #ff006e, #8338ec, #25768d};
int getCol() {
return colors[(int)random(colors.length)];
}
再帰的に分割した正方形にクマを召喚しました。
こういう目、鼻、口、顔とひとつひとつ作っていく気合の打ち込み系は一度作っておくと便利。
そのまま使ってもいいし、派生させることもできる。
メリークリスマス。
Happy coding!!
応援してくださる方!いつでもサポート受け付けてます!