_="SD^dVStope=20f=41,E=40gDStylehDRecti=j=2J=2*j,p={_v:0},tHmH.6,M=M`h,C=[],z20>z;zv5>v;vj+z*J,_2+v*J;z26>z;z5+z~W_f-j-random()*j-2;u=()=>{Z$aaaB4G=cre`eLearGr^ient(E,6$888'.1,$999'1,$111'GE,806p=s(ip.yU,q=p.y+f,$333BqC)<q?U:q>%0<pK=p,U1>H>ENeH6<t++,|splice(k,1Q;kkk{if(Ne){12;contue}lllL=C[l],k!=l~+*<J*J%@-)>W<?(L=K-K/1~67~(-e)/(E-eQL):K,<q%<q%<@pQ)}ZC)$edcb09save( VDrgba(.3) OYH,<q OY=4begP`h(arc(Nx,,j,2*PI(restore();i.02,fontD20px serifText(t,130requestAnim`ionFrame(u)},u(d.^dEventListener('clicka=>{0<t%Y<et--,|unshift({x:X,_Y-j)});Ny0,),for(%(L.yffset*m sh^owNx-(L.xQc[g]=K=C[k],,c[h](|push({x:,v:0})G[S]((-(Qfill<|length;c.=0;+j.v+=',++)a.o00in$'#%&&@abs(B'80D='H=1NK.Q))UpVColorW1.5*jZk ^ad_y:`at|C.~*(M.";for(Y in $="~|`_^ZWVUQNHDB@%$ ")with(_.split($[Y]))_=join(pop());eval(_)
/*
C = coins array
cy = coin loop y pos
S = addColorStop
e = pusher size
E = edge start
f=pusher min size
f = pusher position
g = 'fillStyle'
G=edge gradient
h = 'fillRect'
i = loop iteration
j = coin size = 20;
J = j*2
k = key used in loops
l = key used in coin loops
u() = update loop
M = Math
m = velocity multiplier
p = pusher object
q = pusher pos + pusher min
r() = function to return random int (pass in max)
t=player coin count
v,w
z = coin loop iterator
*/
S='addColorStop';
e=200;
f=41;
E=400;
g='fillStyle';
h='fillRect';
i=0;
j=20;
J=j*2;
p={y:0,v:0};
t=10;
m=1.6;
M=Math;
//r=n=>{return M.floor((M.random() * n)+1);}
//Generate coins
C=[];
//Random
/*
for(z=0;z<100;z++){
cns.push({
x: r(800),
y: 200 + r(200-j),
v:0
})
}
*/
//Non random
for(z=0;z<20;z++){
for(v=0;v<5;v++){
C.push({
x:j+(z*(J)),
y:200 + (v* (J) ),
v:0
});
}
}
//Add some coins to the pusher
for(z=0;z<26;z++){
C.push({
x:5+j+(z*(j*1.5)),
y:(f-j) -(M.random() * j) -2,
v:0
});
}
u=()=>{
//Clear / Draw Background
c[g]='#aaa';
c[h](0,0,800,400);
//Draw edge
G=c.createLinearGradient(0,E,0,600);
G[S](0,"#888");
G[S](.1,"#999");
G[S](1,"#111");
c[g] = G;
c[h](0,E,800,600);
//Calc pusher veloc / pos
p.v = M.sin(i);
p.y = p.y + (p.v*m);
//Pusher pos + pusher min
q=p.y+f;
//Draw the pusher
c[g]='#333';
c[h](0,0,800,q);
//Stationary Coins
for(k in C){
K = C[k];
//Coins are on pusher - move with it
if(K.y + j < q) K.y += p.v*m;
//Push the coins if more than half off the pusher
else if(q > K.y && p.v > 0) {
K.v = p.v;
K.y += p.v*m;
}
//Check touching edge of screen
if(K.y < 1) K.y = 1;
//If over edge - set flag
if(K.y + j > E) K.e=1;
//Remove coins that have fallen out of the screen and Increase coin count
if(K.y > 600){
t++;
C.splice(k,1);
}
}
for(k=0;k<C.length;k++){
K = C[k];
//Ignore if fallen off edge - increase veloc
if(K.e){
K.y += 12;
continue;
}
for(l=0;l<C.length;l++){
L = C[l];
if( k!=l &&
//Check coins overlapping
((K.x+j) - (L.x+j) ) * ((K.x+j) - (L.x+j)) + ((K.y+j) - (L.y+j)) * ((K.y+j) - (L.y+j)) <
J * J
){
//Absorb velocity from other coin (no velocity whilst on pusher)
//Only move if less than a quarter overlapping (allows some coins to pile up)
if(M.abs(K.y - L.y) > j*1.5) {
//Make sure velocity is always absorbed from the coin above
if(K.y < L.y){
//L.v = K.v;
//L.v = K.v - ((K.v / 100) * ((k/C.length) * 100))
//Velocity gets less further down the screen - last number is percentage to reduce power by
L.v = K.v - ((K.v / 100) * (((L.y - e) / (E-e) ) * 67));
L.y += L.v*m;
}
else {
//K.v=L.v;
//K.v = L.v - ((K.v / 100) * (((K.y - e) / (E-e) ) * 70));
K.y += K.v*m ;
}
//Both Coins on pusher, reverse the velocity the coin has absorbed from the pusher so it stays still
if(K.y < q && L.y < q && K.y < L.y) L.y += M.abs(p.v*m);
}
}
}
}
for(k in C){
K = C[k];
//c[g] = 'rgb(237, 203, 9)';
//c[g] = '#ff0';
c[g] = '#edcb09';
//If coin on pusher - different colour and add shadow
c.save();
//c.shadowColor = 'rgba(0,0,0,.3)';
c.shadowColor = 'rgba(0,0,0,.3)';
//c.shadowColor = '#888';
c.shadowOffsetY = 1;
if(K.y < q){
//c[g]='rgb(247, 213, 19)';
//c[g]='#f7d513';
c.shadowOffsetY = 4;
}
c.beginPath();
c.arc(K.x, K.y+j, j, 0, 2*M.PI);
c.fill();
c.restore();
//Text
//c[g] = '#d5b301';
//c.fillText(M.round( C[k].v * 10 ) / 10, C[k].x-6, C[k].y+26);
//c.fillText('£', K.x-6, K.y+26);
}
i+=.02;
//if(pC<1) c[g] = '#ff0000';
c.font = '20px serif';
c.fillText(t, 10, 30);
requestAnimationFrame(u);
};
u();
d.addEventListener('click', W=>{
if(t>0 && W.offsetY < e){
t--;
C.unshift({x: W.offsetX, y:W.offsetY-j, v:0});
}
});