xxxxxxxxxx
162
var snowflakes = [];
var c = 100;
var clicks = 0;
var s = 1;
var melt = 0;
var fFrame = 0;
function setup() {
createCanvas(400, 400);
// textAlign(CENTER);
textSize(20);
angleMode(DEGREES);
}
function mouseClicked() {
if (frameCount >= 600) {
snowflakes.push(new Snowflake());
clicks += 5;
}
}
function draw() {
background(0, 200, 255);
fill(c + clicks);
noStroke();
rect(0, 300, width, 100);
if (frameCount < 600) {
var xSun = map(frameCount, 0, 600, 0, width);
var ySun = map(frameCount, 0, 600, 0, 180);
s = map(frameCount, 0, 600, 90, 0);
f = map(frameCount, 0, 600, 0, 70);
push();
noStroke();
fill(0, 255, 255);
ellipse(100, 360, ySun + 80, ySun / 1.6 - 10); // base puddle animation
pop();
push();
translate(100, 330);
scale(sin(s));
snowman();
pop();
push()
translate(100, 330 + f);
face();
pop();
noStroke();
fill('yellow');
ellipse(0 + xSun, 150 - 100 * sin(ySun), 50);
stroke(0);
fill(255);
ellipse(210, 190, 200, 100);
fill(0);
if (frameCount < 100)
text("What a nice day!", 150, 180, 150);
else
text("Uh oh.....", 150, 180, 150);
} else if (frameCount < 1000) {
fill(255);
stroke(0);
ellipse(210, 200, 200, 100);
fill(0);
if (frameCount < 800)
text("Will you help put me back together?", 150, 180, 150);
else if (frameCount < 1000)
text("It's too warm.. Click to make it snow.", 150, 180, 150);
// else if (frameCount < 1200)
// text("Then help put me back together.", 150, 180, 150);
noStroke();
fill(0 + clicks, 255, 255);
ellipse(220, 350, 100, 50); // head puddle
ellipse(180, 360, 100, 50); // mid-section puddle
ellipse(100, 350, 120, 60); // base puddle
if (clicks < 255) { // draw face in puddle
fill(0);
ellipse(210, 340, 10, 5);
ellipse(230, 340, 10, 5);
fill('orange');
triangle(220, 350, 240, 351, 220, 355);
}
}
if (frameCount > 1000) {
fill(0 + clicks, 255, 255);
ellipse(220, 350, 100, 50); // head puddle
ellipse(180, 360, 100, 50); // mid-section puddle
ellipse(100, 350, 120, 60); // base puddle
if (clicks < 255) { // draw face in puddle
fill(0);
ellipse(210, 340, 10, 5);
ellipse(230, 340, 10, 5);
fill('orange');
triangle(220, 350, 240, 351, 220, 355);
} else if (clicks == 255) {
fFrame = frameCount;
} else if (clicks > 255) { // draw snowman
push();
translate(100, 330);
snowman();
face();
pop();
fill(255);
ellipse(210, 190, 200, 100);
fill(0);
if (frameCount-fFrame < 300)
text("Phew! Thanks for your help!", 150, 180, 150);
else if (frameCount-fFrame > 300)
text("Have a Happy Holidays! =)", 150, 180, 150);
}
for (var i = 0; i < snowflakes.length; i++) {
snowflakes[i].move();
snowflakes[i].display();
if (snowflakes[i].y > height) {
snowflakes.splice(i, 1);
}
}
}
}
function snowman() {
stroke(0);
fill(255);
ellipse(0, 0, 90); // bottom section (100, 330)
ellipse(0, -40, 70); // middle section - goal (100, 290)
ellipse(0, -70, 60); // face section - goal (100, 260)
fill(0);
}
function face() {
fill(0);
ellipse(-10, -80, 10, 5);
ellipse(10, -80, 10, 5);
noFill();
// stroke(0);
// arc(0, -68, 20, 15, 0, PI);
fill('orange');
triangle(0, -70, 30, -69, 0, -65);
}
function Snowflake() {
this.x = mouseX;
this.y = mouseY;
this.display = function() {
noStroke();
fill(255);
ellipse(this.x, this.y, 10, 10);
}
this.move = function() {
this.x += random(-.2, .2);
this.y += .5;
}
}