Skip to content

Instantly share code, notes, and snippets.

@flox1an
Last active December 29, 2015 16:29
Show Gist options
  • Save flox1an/7697471 to your computer and use it in GitHub Desktop.
Save flox1an/7697471 to your computer and use it in GitHub Desktop.
Minimal HTML5 canvas starfield in 540bytes
<!doctype html><canvas><script>
with(Math)with(a=(c=document.body.children[0]).getContext("2d"),c.width=w=innerWidth-30,
c.height=h=innerHeight-30,p=[],r=random,a.translate(w/2,h/2),a)(f=function(){
for(rotate(.005),save(),setTransform(1,0,0,1,0,0),fillStyle="rgba(0,0,0,.3)",fillRect(0,0,w,h),
restore(),fillStyle="#fff",q=[],i=p.length;i--;)v=p[i],(abs(v[0])<w||abs(v[1])<h)&&(
fillRect(v[0]+=v[2]+=v[4],v[1]+=v[3]+=v[5],1,1),q.push(v))
for(p=q;r()<.8;)p.push([0,0,0,0,.1*r()-.05,.1*r()-.05]);requestAnimationFrame(f)})()</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment