10/02/11 18:41:50
<!doctype html><html><head><script>
var w=300,h=300,p=10000,x=[],y=[],vx=[],vy=[],cr=[],cg=[],cb=[],a,b,i,u,v,t,c,d,e,f;
onload=function(){a=document.getElementById("c").getContext("2d");
b=a.createImageData(w,h);d=a.createImageData(w,h);e=0;for(i=0;i<p;i++){
x[i]=Math.random()*w;y[i]=Math.random()*h;vx[i]=Math.random()*10-5;vy[i]=Math.random()*10-5;
cr[i]=(Math.random()*256)|0;cg[i]=(Math.random()*256)|0;cb[i]=(Math.random()*256)|0;}
setInterval(function(){e++;if(e%2==0){c=b.data;f=d.data}else{c=d.data;f=b.data}
for(i=0;i<p;i++){u=x[i];v=y[i];t=((u|0)+(v|0)*w)<<2;f[t]=0;f[t+1]=0;f[t+2]=0;
f[t+3]=0;u+=vx[i];v+=vy[i];if(u<0)u=w;if(v<0)v=h;if(u>w)u=0;if(v>h) v=0;t=((u|0)+(v|0)*w)<<2;
x[i]=u;y[i]=v;c[t]=cr[i];c[t+1]=cg[i];c[t+2]=cb[i];c[t+3]=255;}if(e%2==0) a.putImageData(b,0,0);
else a.putImageData(d,0,0);},-1);}
</script></head><body><canvas id="c" width="300" height="300" style="background-color:black;"></canvas>
</body></html>