Skip to content

Instantly share code, notes, and snippets.

@TBD
Created May 3, 2011 23:02
Show Gist options
  • Save TBD/954440 to your computer and use it in GitHub Desktop.
Save TBD/954440 to your computer and use it in GitHub Desktop.
JS1k winner by @KeenBlaze unpacked by @tbdr
<html>
<head>
<title>JS1k, 1k demo submission [984]</title>
<meta charset="utf-8">
</head>
<body marginwidth="0" marginheight="0">
<canvas id="c" width="1000" height="800"></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>
// start of submission //
w = c.width = 1e3,
h = c.height = 800,
W = 50,
l = 3 / W,
r = 40,
p = h / 3,
X = [],
oX = [],
Q = [],
Y = [],
oY = [],
T = [],
S = [],
ondblclick = G = function(a) {
Z = W;
while (Z--) oX[Z] = X[Z] = w / 2 - 16 * Z,
oY[Z] = Y[Z] = I = J = V = 0,
b = Z < 4,
b | a < 0 && (Q[Z] = b ? (Z & 2) * 300 + 200: 900, T[Z] = b ? (Z & 1) * 350 + 200: 70 * (Z - 3), S[Z] = b ? 2: Z - 5)
},
G(Z = -1),
onmousedown = function(a) {
Z = 9
},
onmouseup = function(a) {
Z = -1
},
onmousemove = function(a) {
Q[Z] = I = a.pageX,
T[Z] = J = a.pageY
}
setInterval(function(){
a.clearRect(0, 0, w, h),
a.shadowColor = "#000",
a.shadowBlur = 3;
for (i = 1; i < W; i++) X[i] += .995 * ((t = X[i]) - oX[i]),
oX[i] = t,
Y[i] += .995 * ((t = Y[i]) - oY[i]) + .5,
oY[i] = t;
j = W;
while (j--) {
for (i = 1; i < W; i++) {
k = 7;
while (k--) x = X[i] - Q[k],
y = Y[i] - T[k],
d = 1 - r / Math.sqrt(x * x + y * y),
m = S[k] * 2,
m < 3 && (d < 0 && (X[i] -= (x + m * y) * d, Y[i] -= (y - m * x) * d), x += I - X[i], y += J - Y[i], Z > 0 & Math.sqrt(x * x + y * y) < r && (Z = V = k)),
i - W + m - V > 2 & d < 0 && S[k]++;
x = X[i] - X[i - 1],
y = Y[i] - Y[i - 1],
X[i] -= k = x * (m = .7 - .7 * l * p / Math.sqrt(x * x + y * y)),
Y[i] -= _ = y * m,
i > 1 && (X[i - 1] += k, Y[i - 1] += _)
}
s = S[j],
b = s == 0,
g = s > 1,
a.fillStyle = b ? "#f58": g ? "#ef6": "#be5",
a.font = (b ? 76: g ? r: 65) + "pt lucida sans unicode",
s < 3 & j < 7 && a.fillText(b ? "○": s > 0 ? g ? "★": "↺": "↻", Q[j] - (g ? 28: r), T[j] + (b ? 29: g ? 21: 32))
}
for (i = 1; i < W; i++) a.strokeStyle = i > W - 2 ? "#cde": "#abc",
a.beginPath(a.lineWidth = 13),
a.moveTo(X[i - 1], Y[i - 1]),
a.stroke(a.lineTo(X[i], Y[i]))
},30)
// end of submission //
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment