- Author:
- grgrdvrt
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- grgrdvrt.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2013-spring/demo/1525
- Shortlink:
- https://js1k.com/1525
- Blog post:
- please update here!
- Bytes:
- 962
- Chars:
- 962
- Submission
function I(e){g=2*M.floor(r()*S.length/2);e.x=S[g];e.y=S[g+1];e.t=e.T=r()*r()*200;e.X=e.Y=0;e.h=80+r()*50;e.s=100*r();e.l=100*r()}P=[];S=[];M=Math;w=c.width=window.innerWidth;h=c.height=window.innerHeight;f=.95;v=.5;r=M.random;s="Type & press ENTER";u=n=0;b.style.overflow="hidden";setInterval(function(){for(i=0;i<n&&u;i++){p=P[i];p.X=f*p.X+v*(r()*2-1);p.Y=f*p.Y+v*(r()*2-1.2);a.beginPath();a.lineCap="round";a.lineWidth=5*(p.t/p.T);a.strokeStyle="hsl("+p.h+","+p.s+"%,"+p.l+"%)";a.moveTo(p.x,p.y);a.lineTo(p.x+=p.X,p.y+=p.Y);a.stroke();--p.t<0?I(p):0}},30);b.onkeyup=function(e){k=e.keyCode;c.width=c.width;u=0;if(k==32||k>64&&k<91)s+=String.fromCharCode(k);if(k==8)s=s.substr(0,s.length-1);a.font="bold "+.2*h+"px sans-serif";a.fillText(s,M.max(0,.5*(w-a.measureText(s).width)),.7*h,w);if(!n)s="",n=300;if(k==13){d=a.getImageData(0,0,u=w,h).data;for(S.length=i=0;i<d.length/4;i++)if(d[4*i+3])S.push(i%w,M.floor(i/w));for(i=0;i<n;i++)I(P[i]={})}};b.onkeyup({})
- Description
- Type, press enter and let Mother Nature do the job
- Base64 encoded
ZnVuY3Rpb24gSShlKXtnPTIqTS5mbG9vcihyKCkqUy5sZW5ndGgvMik7ZS54PVNbZ107ZS55PVNbZysxXTtlLnQ9ZS5UPXIoKSpyKCkqMjAwO2UuWD1lLlk9MDtlLmg9ODArcigpKjUwO2Uucz0xMDAqcigpO2UubD0xMD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spSShQW2ldPXt9KX19O2Iub25rZXl1cCh7fSk=
- Original source
P=[]//particles
S=[]//start positions
M=Math
w=c.width=window.innerWidth
h=c.height=window.innerHeight
f=0.95//friction
v=0.5//max speed
r=M.random
s="Type & press ENTER"
u=n=0
b.style.overflow="hidden"
//initialize a particle
function I(p)
{
//get a start position
g=2*M.floor(r()*S.length/2);
p.x=S[g]
p.y=S[g+1]
//lifetime
p.t=p.T=r()*r()*200
//velocity
p.X=p.Y=0
//color
p.h=80+r()*50
p.s=100*r()
p.l=100*r()
}
setInterval(function ()
{
for(i=0;i<n&&u;i++)
{
p=P[i]
//set velocity
p.X=f*p.X+v*(r()*2-1)
p.Y=f*p.Y+v*(r()*2-1.2)
a.beginPath()
a.lineCap="round"
a.lineWidth=5*(p.t/p.T)
a.strokeStyle="hsl("+p.h+","+p.s+"%,"+p.l+"%)"
a.moveTo(p.x,p.y)
a.lineTo(p.x+=p.X,p.y+=p.Y)
a.stroke()
--p.t<0?I(p):0//reset when lifetime is under 0
}
},30)
b.onkeyup=function(e)
{
k=e.keyCode
c.width=c.width
u=0
//[a-z] space
if(k==32||(k>64&&k<91))s+=String.fromCharCode(k)
//backspace
if(k==8)s=s.substr(0,s.length-1)
//draw text
a.font="bold "+(0.2*h)+"px sans-serif"
a.fillText(s,M.max(0,0.5*(w-a.measureText(s).width)),0.7*h,w);
if(!n)s="",n=300;
//enter
if(k==13)
{
//compute start positions
d=a.getImageData(0,0,u=w,h).data
for(S.length=i=0;i<d.length/4;i++)
if(d[4*i+3]) S.push(i%w,M.floor(i/w))
//init particles
for(i=0;i<n;i++)I(P[i]={})
}
}
b.onkeyup({})//init text