Generative Art #110
Code
PShape face;
void setup() {
size(840, 840);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
noLoop();
face = loadShape("girl.svg");
shapeMode(CENTER);
face.disableStyle();
}
void draw() {
background(360);
squareRec(0, 0, width, 4);
}
void squareRec(float x, float y, float s, int n) {
stroke(0);
strokeWeight(1);
fill(getCol());
square(x, y, s);
fill(#ffffff, 70);
square(x, y, s);
shapes(x, y, s);
n--;
if (n >= 0) {
float probability = map(n, 0, 3, 0.5, 0);
float hs = s/2;
if (random(1) > probability) {
squareRec(x, y, hs, n);
squareRec(x+hs, y, hs, n);
squareRec(x+hs, y+hs, hs, n);
squareRec(x, y+hs, hs, n);
}
}
}
void shapes(float x, float y, float s) {
float hs = s/2;
pushMatrix();
fill(getCol());
translate(x + hs, y + hs);
if (random(1) > 3.0/4.0) {
rect(-hs, -hs, hs, s);
rect(0, -hs, hs, s);
fill(0, 10);
stroke(0);
circle(-hs * 0.2, 0, s*0.1);
circle(hs * 0.2, 0, s*0.1);
} else if (random(1) > 2.0/4.0) {
float shift = hs *0.65;
stroke(getCol());
strokeWeight(s*0.3);
line(-shift, -shift, shift, shift);
line(-shift, shift, shift, -shift);
} else if (random(1) > 1.0/4.0) {
face(-hs, -hs, s);
} else {
circleRec(0, 0, s, 3);
}
popMatrix();
}
void face(float x, float y, float s) {
color col = getCol();
int count = 2;
fill(col);
noStroke();
shape(face, x+s*0.5, y+s*0.5, s, s-2);
circleRec(x+s*0.35, y+s*0.5, s*0.23, count);
circleRec(x+s*0.65, y+s*0.5, s*0.23, count);
strokeWeight(1);
stroke(col);
noFill();
beginShape();
if (random(1) > 0.66) {
vertex(x+s*0.35, y+s*0.7);
vertex(x+s*0.5, y+s*0.65);
vertex(x+s*0.65, y+s*0.7);
} else if (random(1) > 0.33) {
vertex(x+s*0.45, y+s*0.65);
vertex(x+s*0.55, y+s*0.65);
} else {
vertex(x+s*0.35, y+s*0.65);
vertex(x+s*0.5, y+s*0.7);
vertex(x+s*0.65, y+s*0.65);
}
endShape();
}
void circleRec(float posX, float posY, float d, int n) {
pushMatrix();
noStroke();
float randomD = random(d);
translate(posX, posY);
fill(getCol());
circle(0, 0, d-2);
n--;
if (n >= 0) {
rotate(random(PI));
pushMatrix();
circleRec(0 - (d - randomD)/2, 0, randomD, n);
popMatrix();
circleRec(0 - d/2 + randomD + (d - randomD)/2, 0, d - randomD, n);
}
popMatrix();
}
int[] colors = {#E8AF34, #DB33C5, #2D65ED, #3FE5BD, #E53F66};
int getCol() {
return colors[(int)random(colors.length)];
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
void mousePressed() {
redraw();
}
初めてSVGを組み込んでみた。
アホみたいな感想だけど拡大してもぼやけないってすごいよ。しかもstroke()もfill()も効くんだぜ?
いやほんとベクター画像パネェよ。
女の子のテーマはミディアムヘアのうち巻きが鎖骨にかかってるのすごく美しいよねってとこから。
画像はInkscapeで作った。初めて使ったから時間はかかったが、なんとか使えそう。
Processingでコード化が難しい形は自分で作ってしまえばいいのだ。
これはかなり自由度が高くなった。
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!