A simple snow globe demo drawn in a html5 canvas. Press mouse button to shake the globe and release button to let it snow - then enjoy it!
_='bPb,ec.begbe};eP_c.close^k,lvar n=r2;@k,l)Z(neP^pwb pow(b,2D(new DJe).valueOf^ K_@c00)RecNl=?c2:c3;(Y,llif(!o=,o!=nl&&($=sp/z,Vx-,V0<x?x-$:x+$,y=y-U,y=0<y?y-$:y+$,r=W(~y)),5>=r+a?=nl:(r=0>y?-1*r:r,ph7as(x/r)-sp/180*p%36V`sHy=U`cosH(x,y,a22))@c11)Zfont="20px Arial"TexN"Click globe!",5,w)}setTimeouNK,wnl=null;f=!1;t=!z=1w=2h=10down_=t;d=D^ up_jsp=(D-d)/h;{do ts=={x:y:Ua: ceil(3|while(W(~Uy))>=a)}}0=4000"1=4993333"2=4EEE"G=[4CCCCBB",49999CC"];jm=MJh;rd7random;W7Wrt;p7PI;r2=2*p;wd=a.width;Q=a.heigQX=wd/2Y=Q/2;7m(/2-w3=c.creJeLearGradienN5,h,5w,z,22>iFc3.addColorStop(iG[i]mV50sw=[];K=function(Zfilli<mxFPJhZstroke+-2*|,)};;c){ m.sw[i]a.onmouse,co.for(i=arcpw(-ts.retuK()0;Style=b,e,g,wd,Q)in);0,mCcXsz$sC4"#7= @bP(F;i++)H(ph),JatKrnNt(QhtUcYVx=WsqZ.^(_`+r* j=f;|*rd~x)+';for(Y in $='~|j`_^ZWVUQNKJHF@74$ ')with(_.split($[Y]))_=join(pop());eval(_)
Xz0nYlABYixlCGMuYmVnGgQXYgIXZX07ZVBfYy5jbG9zZQQVAl4RARhrLGwIdmFyIG49cjI7QGssbClaESgYHG4bZVBecHcBYhQgCXBvdyhiLDIGRAEUKG5ldyBESmUpLnZhbHVlT2ZeIEtfQGMwDjApAlJlY04cHBkHbD0dP2MyOmMzOxEoHg5ZLB8ObA5sG2lmKCEdCANvPQssbyE9bmwmJigkPXNwL3osVg94LR4sVjA8eD94LSQ6eCskLHk9D3ktVSx5PTA8eT95LSQ6eSskLHI9VygSfnkpKSw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,y){ // begins a canvas path - helper function
c.beginPath();
c.strokeStyle=x;
c.fillStyle=y;
},
eP=function(){ // ands, strokes and fills a canvas path - helper function
c.closePath();
c.stroke();
c.fill();
},
arc=function(x,y,z,h,i,j){ // draws a canvas arc -helper function
bP(i,j);
c.arc(x,y,z,0,h);
eP();
},
pw=function(x){return m.pow(x,2)},
D=function(){return (new Date()).valueOf()},
rn=function(){ // main game loop function for drawing and all handling (saves space)
bP(c0,c0);
c.fillRect(0,0,wd,ht); // refresh background
cl=(mC)?c2:c3;
arc(cX,cY,sz,r2,cl,cl); // snow ball is white while shaking, white point in the mid
if(!mC){
for(i=0;i<mx;i++){ // draw snow
o=sw[i];
if(o!=nl){
sC=sp/z;
x=o.x-cX;
x=x>0?x-sC:x+sC;
y=o.y-cY;
y=y>0?y-sC:y+sC;
r=sq(pw(x)+pw(y));
if(r+o.s<=5) sw[i]=nl/*,nlCnt++*/;
else{
r=y<0?r*-1:r;
ph=m.asin(x/r)-sp/180*p%360;
o.x=cX+r*m.sin(ph);
o.y=cY+r*m.cos(ph);
arc(o.x,o.y,o.s,r2,c2,c2);
}
}
}
bP(c1,c1);
c.font="20px Arial";
c.fillText("Click globe!",5,w);
}
setTimeout(rn,w);
}
nl=null; // init game variables,constants and pointers
f=false;
t=true;
z=10;
w=20;
h=100;
// appends mouse and touch (mobile devices) event for player handling
a.onmousedown=function(){mC=t;d=D();};
// sets new snow object array on mouseclick and initializes movement of snow
a.onmouseup=function(){mC=f;sp=(D()-d)/h;for(i=0;i<mx;i++)do{ts=sw[i]={x:((cX+sz)-2*sz*rd()),y:((cY+sz)-2*sz*rd()),s:m.ceil(3*rd())}} while(sq(pw(cX-ts.x)+pw(cY-ts.y))>=sz-ts.s)};
c0="#000",c1="#993333";c2="#EEE"; // game colors
cG=["#CCCCBB","#9999CC"];
mC=f; // is mouse down?
m=Math;
rd=m.random;
sq=m.sqrt;
p=m.PI;
r2=2*p;
wd=a.width;
ht=a.height;
cX=wd/2;
cY=ht/2;
sz=m.min(wd,ht)/2-w; // radius ball
c3=c.createLinearGradient(5,h,50,w,z,2); // background gradient
for(i=0;i<2;i++)c3.addColorStop(i,cG[i]);
mx=500; // max snow
//nlCnt=0; // counter variable for null snow objects
sw=[];
rn();