Skip to content

Instantly share code, notes, and snippets.

@seanmtracey
Last active March 4, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmtracey/c6bf47473075ac396230917634162c1a to your computer and use it in GitHub Desktop.
Save seanmtracey/c6bf47473075ac396230917634162c1a to your computer and use it in GitHub Desktop.
Paint with light in less than 1024 bytes.
<!DOCTYPE html>
<html>
<head>
<style>
html, body, canvas{width: 100%; height: 100%;margin:0;padding:0;}
</style>
</head>
<body>
<canvas id="canvas1"></canvas>
<script id="js1kGlobals">
window.a = document.getElementById('canvas1');
window.b = document.body;
window.c = a.getContext('2d');
window.d = document;
window.a.style.width = window.innerWidth;
window.a.style.height = window.innerHeight;
</script>
<script src="lightpaint.min.js"></script>
</body>
</html>
!function(){function i(){f.drawImage(e,0,0);for(var a=f.getImageData(0,0,vidD.width,vidD.height),b=c.getImageData(0,0,vidD.width,vidD.height),d=0,j=0,n=(g.length,a.data.length),o=0|performance.now();d<n;)a.data[d]>h&&a.data[d+1]>h&&a.data[d+2]>h?(b.data[d]=255,b.data[d+1]=0,b.data[d+2]=0,g[j]=o):a.data[d]=a.data[d+1]=a.data[d+2]=0,o-g[j]>5e3&&(b.data[d]=b.data[d+1]=b.data[d+2]=0),d+=4,j+=1;c.putImageData(b,0,0),window.requestAnimationFrame(i)}vidD=d.createElement("canvas");var e=d.createElement("video"),f=vidD.getContext("2d"),g=void 0;b.appendChild(e);var h=240;navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia,navigator.getUserMedia({video:{optional:[{minWidth:1024}]}},function(b){e.src=window.URL.createObjectURL(b),e.play(),setTimeout(function(){a.width=vidD.width=e.offsetWidth,a.height=vidD.height=e.offsetHeight,c.fillRect(0,0,vidD.width,vidD.height),g=new Uint32Array(vidD.width*vidD.height),i()},1e3)},function(){})}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment