Skip to content

Instantly share code, notes, and snippets.

@gunn
Created February 17, 2016 08:08
Show Gist options
  • Save gunn/192a1447a90d535e133e to your computer and use it in GitHub Desktop.
Save gunn/192a1447a90d535e133e to your computer and use it in GitHub Desktop.
Slightly de-minified from my js1k entry.
<!doctype html>
<html>
<head>
<title>JS1k</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>
with(c) {
width = height = d = 700;
b.bgColor = e = C = Q = K = 0;
A = Z = 1;
onmousemove = function(f) {
U = f.pageX - offsetLeft;
V = f.pageY;
m();
}
style.display = "block";
style.margin = "auto";
}
U = V = 200;
eval(top.location.search.replace(/[\?&]/g, ";"));
p = b.onclick = function() {
Q = 1 == K % 2;
A = Z = 0.15;
0 == K % 5 && (A = 1);
1 == K % 5 && (Z = 1);
2 < K % 5 && (A = Z = 1);
K++
};
p();
m = function(f) {
i = t = X = 0;
0 == (C += 3) % 20 && top.history.replaceState(0, 0, "?U=" + U + "&V=" + V + "&C=" + C + "&K=" + K);
a.fillStyle = "hsla(0,100%,0%," + A * Z + ")";
a.fillRect(0, 0, d, d);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
Q && !e && navigator.getUserMedia({
audio: !0
}, function(f) {
t = new(top.audioContext || top.webkitAudioContext || top.mozAudioContext || top.msAudioContext);
e = t.createAnalyser();
t.createMediaStreamSource(f).connect(e)
}, function() {});
if (Q && e) {
for (e.getByteFrequencyData(k = new Uint8Array(f = e.frequencyBinCount)); i < ~~(f / 6); i++) t += k[i + ~~(f / 4)];
t /= i
}
t = t ? (t + 45) / 100 : 1;
p = U / 100 - 3.5;
a.strokeStyle = "hsla(" + C + ",100%,50%," + A + ")";
a.beginPath();
for (i = 2E3; i--;) y = i / (3 * ~~((V + 15) / 30)), x = 60 * (Math.sin(y) * p + Math.cos(i / 9) * t) + d / 2, y = 60 * (Math.cos(y) * p + Math.sin(i / 9) * t) + d / 2, X && (a.moveTo(X, f), a.lineTo(x, y)), X = x, f = y;
a.stroke()
};
m();
setInterval(m, 50);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment