Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created August 9, 2010 14:54
Show Gist options
  • Save hakunin/515526 to your computer and use it in GitHub Desktop.
Save hakunin/515526 to your computer and use it in GitHub Desktop.
with(document.body.style){padding=margin=0;overflow="hidden"}c=document.getElementById("c");w=c.width=this.innerWidth;h=c.height=this.innerHeight;g=c.getContext("2d");l=[];function r(b){return Math.random()*b}for(t=i=1;i++<999;)l.push([n=r(w),m=r(h),n+r(20)-9,m+r(20)-9,n+r(99)-50,m+r(99)-50]);k=[0,255,0];j=5;document.body.onmousemove=function(b){g.fillStyle="#000";g.fillRect(0,0,w,h);if(k[t]>=j){k[t]-=j;k[(t+1)%3]+=j}else t=(t+1)%3;o="rgba("+k.join(",")+",";for(i in l){m=l[i];dx=b.clientX-m[0];dy=b.clientY-m[1];d=Math.sqrt(dx*dx+dy*dy);a=75/d;if(!(a<0.15)){g.strokeStyle=o+a+")";if(a>0.6&&r(99)<3)m.g=1;if(m.g>0)g.strokeStyle="rgba(255,255,255,"+(m.g-=0.05)+")";g.beginPath();g.moveTo(m[0],m[1]);g.quadraticCurveTo(m[2]-dx/d*20,m[3]-dy/d*20,m[4]-dx/d*80,m[5]-dy/d*80);g.stroke()}}}
with(document.body.style){padding=margin=0;overflow='hidden'};
c=document.getElementById('c');
w = c.width = this.innerWidth;
h = c.height = this.innerHeight;
g = c.getContext('2d');
l = []
function r(w) {return Math.random()*w}
t = i = 1;
while (i++ < 999) {
l.push([n = r(w), m = r(h), n+r(20)-9, m+r(20)-9, n+r(99)-50, m+r(99)-50]);
}
k = [0, 255, 0];
j = 5;
document.body.onmousemove = function(e) {
g.fillStyle = '#000';
g.fillRect(0,0, w, h);
if (k[t] >= j) {
k[t] -= j;
k[(t+1)%3] += j;
} else {
t=(t+1)%3;
}
o = 'rgba('+k.join(',')+',';
for (i in l) {
m = l[i];
dx = e.clientX-m[0];
dy = e.clientY-m[1];
d = Math.sqrt(dx*dx+dy*dy);
a = 75/d;
if (a < .15) continue;
g.strokeStyle = o+(a)+')';
if (a > 0.6 && r(99)<3) m.g = 1;
if (m.g>0) {
g.strokeStyle = 'rgba(255,255,255,'+(m.g-=.05)+')'
}
g.beginPath();
g.moveTo(m[0], m[1]);
g.quadraticCurveTo(
m[2]-dx/d*20,
m[3]-dy/d*20,
m[4]-dx/d*80,
m[5]-dy/d*80
);
g.stroke();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment