js1k - shoot the hearts [original]
by gion_13
HTML
<!doctype html>
<html>
<head>
<title>JS1k, 1k demo submission [ID]</title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="c"></canvas>
<script>
var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218
</script>
<script>
(function(){
var w = 600,
h = 400,
R = Math.random,
score = paused = arrows = hearts_destroyed = hearts_missed = d = i = v = 0,
j,// counter
g,//gradient
aux,//guess
dM = 30,
dm = -30,
p = 5,// the degree pace
H = {},
q='black',
f = function(x){
a.font=x+'px bold Arial';
},//font
heart = function(){
this.S = 35+~(-R()*50)
this.x = w;
this.y = R() * h;
this.s = ~(-R()*5);
this.score = ~~((this.S-35)/this.s);
this.destroyed = !1;
this.id = i++;
this.h = '❤';//R()>.5?'❤':'♥';
this.dir = -1;
this.c = 'red';
H[this.id] = this;
},
arrow = function(){
heart.call(this);
with(this){S=30;h='➳';s=25;dir=1;y=173,x=115;c=q;}
this.angle = d;
this.d = this.angle*Math.PI/180;
arrows++;
},
cloud = function(){
heart.call(this);
this.o=R()*50;
this.h='☁';
this.s=1;
this.x=600;
this.c='rgba(255,255,255,.4)';
this.y=h+this.S/2;
this.S=100+R()*200;
};
heart.prototype.draw = function(){
with(this){
if(x+S<0||x-S>w||destroyed)return destroy();
a.fillStyle=c;
a.save();
f(S);
a.translate(-S/2,S/3);
...