ProcessingでGenerative art #85
ハロウィン、クリスマス、新年とかのイベントをテーマに何か作ろうと思っていたんですけどことごとく逃していたので今回は間に合った形!
Code
int count = 700;
Heart[] hearts = new Heart[count];
int drawMode = 1;
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
noLoop();
for (int i = 0; i < count; i++) {
hearts[i] = new Heart();
}
}
void draw() {
background(320, 30, 100);
for (int i = 0; i < count; i++) {
hearts[i].display();
}
}
void mousePressed() {
for (int i = 0; i < count; i++) {
hearts[i] = new Heart();
}
redraw();
}
void keyPressed(){
if(key == 's')saveFrame("####.png");
if(key == '1')drawMode = 1;
if(key == '2')drawMode = 2;
}
/-----------------------------------------------------------------
class Heart {
PVector pos;
float size;
float colHue;
float r;
float angle;
Heart() {
pos = new PVector(random(width), random(height));
r = random(1);
angle = random(-PI, PI);
if (drawMode == 1) {
colHue = random(0, 360);
}
if (drawMode == 2) {
colHue = random(290, 360);
}
}
void display() {
size = map(dist(0, 0, pos.x, pos.y), 0, sqrt(sq(width)+sq(height)), 0, 6);
pushMatrix();
translate(pos.x, pos.y);
rotate(angle);
for (float i = size; i >= 0; i -= 0.1) {
if (drawMode == 1) {
fill(map(i, size, 0, colHue-10, colHue+10), 100, 100);
}
if (drawMode == 2) {
if (r > 0.75) {
fill(colHue, map(i, size, 0, 100, 0), 100, 90);
} else if (r > 0.50) {
fill(colHue, map(i, size, 0, 0, 100), 100, 90);
} else if (r > 0.25) {
fill(colHue, 100, map(i, size, 0, 100, 0), 90);
} else {
fill(colHue, 100, map(i, size, 0, 0, 100), 90);
}
}
heart(i);
}
popMatrix();
}
void heart(float mag) {
noStroke();
beginShape();
for (int i=0; i<=360; i+=5) {
float theta = radians(i);
float x = 16 * pow(sin(theta), 3);
float y = 13 * cos(theta)
- 5 * cos(2 * theta) - 2 * cos(3*theta) - cos(4*theta);
curveVertex(x * mag, -y * mag);
}
endShape();
}
}
Happy valentine's day!
応援してくださる方!いつでもサポート受け付けてます!