p=510;c.width=800;c.height=500;c.style.background="#6cf";a.p=a.beginPath;a.f=a.fill;a.l=a.lineTo;function d(b,g,e,f){a.p();a.arc(b,g,e,0,Math.PI*2,true);a.closePath();a.fillStyle=f;a.f()}function sB(e){var b=this;b.x=-10;b.y=e;b.j=8;b.k=-1;b.q=h;b.g=false;b.uC=function(){b.k+=0.05;b.x+=b.j;b.y+=b.k;if(b.x>s&&b.x<460&&b.y>n-t){if(!b.g){b.e=b.y;if(b.e>n-t&&b.e<n+t){t++}else{if(b.e>n+t&&b.e<o+u){u++}else{if(b.e>o+u&&b.e<w+v){v++}}}}b.g=true}else{if(!b.g){d(b.x,b.y,10,b.q)}}}}t=50;u=70;v=100;s=400;h="#fff";function sM(){i="#000";w=p-v;o=p-(v*2+u-10);n=p-(v*2+u*2+t-20);d(s,w,v,h);d(s,o,u,h);d(s,n,t,h);d(s-(t*0.8),n-10,8,i);d(s+(t*0.4),n+10,8,i);a.p();a.moveTo(s-9,n+16);a.l(s-9,n);a.l(s-88,n+8);a.fillStyle="#F90";a.f()}z=[];sS=30;l=0;setInterval(function(){a.clearRect(0,0,c.width,c.height);t-=0.04;u-=0.06;v-=0.07;l++;if(l<=80){sS+=0.2}else{if(l==140){l=0}else{sS-=0.2}}d(580,99,sS,"#ff0");z.forEach(function(b){b.uC()});sM()},17);c.onclick=function(f){var b=f.layerY||f.offsetY;z.push(new sB(b))};
c.width = 800;
c.height = 500;
c.style.background = '#6cf';
function drawCircle(x,y,radius,color) {
a.beginPath();
// arc(x, y, radius, startAngle, endAngle, anticlockwise)
a.arc(x, y, radius, 0, Math.PI*2, true);
a.closePath();
a.fillStyle = color;
a.fill();
}
function snowball(y) {
var me = this;
me.x = -10;
me.y = y;
me.moveX = 8;
me.moveY = -1;
me.color = snowColor;
me.gone = false;
me.updateCircle = function() {
me.moveY +=.05;
me.x += me.moveX;
me.y += me.moveY;
if (me.x > snowPosX && me.x < 460 && me.y > topBallY-topBall) {
if (!me.gone) {
me.endPos = me.y;
if ( me.endPos > topBallY-topBall && me.endPos < topBallY+topBall) {
//top ball
topBall++;
} else if (me.endPos > topBallY+topBall && me.endPos < midBallY+midBall) {
//mid ball
midBall++;
} else if (me.endPos > midBallY+midBall && me.endPos < botBallY+botBall) {
//bot ball
botBall++;
}
}
me.gone = true;
} else {
if (!me.gone) drawCircle(me.x, me.y, 10, me.color);
}
};
}
topBall = 50;
midBall = 70;
botBall = 100;
snowPosX = 400;
snowColor = '#fff';
function snowman() {
eyeColor = '#000';
botBallY = 510-botBall;
midBallY = 510-(botBall*2 + midBall-10);
topBallY = 510-(botBall*2+midBall*2+topBall-20);
//bottom ball
drawCircle( snowPosX, botBallY, botBall, snowColor );
//middle ball
drawCircle( snowPosX, midBallY, midBall, snowColor );
//top ball
drawCircle( snowPosX, topBallY, topBall, snowColor );
//eyes
drawCircle( snowPosX - (topBall*.8), topBallY-10, 8, eyeColor );
drawCircle( snowPosX + (topBall*.4), topBallY+10, 8, eyeColor );
//carrot nose
a.beginPath();
a.moveTo(snowPosX-9,topBallY+16);
a.lineTo(snowPosX-9,topBallY);
a.lineTo(snowPosX-88,topBallY+8);
a.fillStyle = '#F90';
a.fill();
}
ballList = [];
sunSize = 30;
sunCounter = 0;
//main animation loop
setInterval(function(){
//clear canvas
a.clearRect(0,0,c.width,c.height);
topBall-=.04;
midBall-=.06;
botBall-=.07;
//sun
sunCounter++;
if(sunCounter<=80) {
sunSize+=.2;
} else if (sunCounter==140) {
sunCounter=0;
} else {
sunSize-=.2;
}
drawCircle(580,99,sunSize,'#ff0');
ballList.forEach(function(current){
current.updateCircle();
});
snowman();
},1000/60);
c.onclick = function(event) {
var mouseY = event.layerY || event.offsetY;
//launch snowball
ballList.push(new snowball(mouseY));
};