- Author:
- platane
- Twitter:
- @
- GitHub:
- platane
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- platane.me
- Compo:
- canvas
- Demo link:
- https://js1k.com/2016-elemental/demo/2504
- Shortlink:
- https://js1k.com/2504
- Blog post:
- platane.github.io/swarm-post
- Bytes:
- 1024
- Chars:
- 1024
- Submission
_=' u{NclearRect(80800i=9i>2?"#aaa":i2,7,2J3,s/100;i=l{o=eH,pDqQv=w=s=t=cp,q,2.5,7)p-3*u,q-3*v,j=l;j^i!=jE(` D~ Qd, c=c?(kL,44@-.L*$exp((45-d)*(d-45)/289)vxwyk=1-$abs(d-30)/8U>0E!((i+j)%4)Ei<jE(k,.5 D y)):(k4L0@sxty/d));jv*v+w*wj/j,.4sGv/j,tGw/j,x=x-p,y=y-q,d$max(.1,sG2*xtG2*y`n,~gUU9,1760/(k*k))/k,sDtQx+uBus,y+vBvt,d<18E(s++,tt>=3?c%6+3)}requestAnimaZFrame(u)}m=Math,z=$sqrt,b=$mO,r={return 0|640*$random},l=L5,e=[],i=leH=V,y,t:i%9,u:v:c%3,;h=[V:12I12C6I20C20I6]U=3;k<9;)h[k++]=V+8y+80};n=g=a.onmouse_=(o){nKX,gKY},u1Style=+12)+",50%,60%)"J)_To(p,q)lOeTo(NlOeWidtho.0,hH. e[j].Gk*:r,Nx*x+y*y)funcZNglobalAlpha=for(begOPath;i^h[t]."hsl("+(75*s:0}=/d,()=z(=b(strokeDQ2),$m.@/(d*d)B=.92*C,V:Dx,E&&G+=H[i]Iy:Jarc(KpageL22Nc.OinQy,U,kV{xZtion^--;)_move`x=p-~y=q-+.1*';for(Y in $='~`_^ZVUQONLKJIHGEDCB@$ ')with(_.split($[Y]))_=join(pop());eval(_)
- Description
- three swarms compete to collect minerals
- Base64 encoded
Xz0nECB1GnsSTmNsZWFyUmVjdCgHBzgwBzgwMB9pPTkUAWk+Mj8iI2FhYSI6FmkCHjIsBzcDEywFMkoeMywHCHMvMTAwAzsSaT1sFH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F5LFUsa1Z7eFp0aW9uXi0tOylfbW92ZWB4PXAtfnk9cS1/Ky4xKic7Zm9yKFkgaW4gJD0nf35gX15aVlVRT05MS0pJSEdFRENCQCQfHh0cGxoZGBcWFRQTEhEQDw4MCwkIBwYFBAMCAScpd2l0aChfLnNwbGl0KCRbWV0pKV89am9pbihwb3AoKSk7ZXZhbChfKQ==
- Original source
// swarm
m=Math
z=m.sqrt
b=m.min
r = function(){ return 0|( m.random()*640 ) }
l=225
e = []
for(i=l;i--;)
e[i]={x:r(), y:r(), t:i%9, u:0, v:0, c:r()%3 ,s:0}
h = [
{x:120,y:120,s:0},
{x:60,y:200,s:0},
{x:200,y:60,s:0},
]
for(k=3;k<9;)
h[k ++]={x:r()+80, y:r() +80}
n=g=0
a.onmousemove = function(e){
n=e.pageX
g=e.pageY
}
// loop
function u (){
c.clearRect(0,0,800,800)
//draw honey pot
for( i=9;i--;){
c.globalAlpha = c.lineWidth =1
c.strokeStyle= i > 2 ? '#aaa' : 'hsl(' + ( i*75 + 12 ) + ',50%,60%)'
c.beginPath()
c.arc( h[i].x, h[i].y, 22, 0, 7 )
c.stroke()
c.beginPath()
c.lineWidth = 2
c.arc( h[i].x, h[i].y, 23, 0, h[i].s/100 )
c.stroke()
}
// fly
for( i=l;i--;){
o=e[i]
p = o.x
q = o.y
v = w = s = t = 0
// draw
c.globalAlpha = c.lineWidth = 1
c.strokeStyle= 'hsl(' + ( o.c*75 + 12 ) + ',50%,60%)'
c.beginPath()
c.arc( p, q, 2.5, 0, 7 )
c.moveTo(p, q)
c.lineTo(p - o.u *3, q - o.v *3)
c.stroke()
for( j=l;j--;)
if(i!=j){
x = p - e[j].x
y = q - e[j].y
d = z(x*x + y*y )
if ( e[j].c == o.c ) {
k = b( 22, 44 / ( d *d ) - 0.22 * m.exp( ( 45-d )*( d- 45 ) / 289 ) )
v += k*x/d
w += k*y/d
k = 1 - m.abs( d - 30 ) / 8
if ( k > 0 && !((i+j) % 4) && i<j ) {
c.globalAlpha = k
c.lineWidth = 0.5
c.moveTo( p, q )
c.lineTo( e[j].x, e[j].y )
c.stroke()
}
} else {
k = b( 40, 220 / ( d * d ) )
s += k*x/d
t += k*y/d
}
}
// limit firendship influence
// prevent from forming a firendship ball
j = z( v * v + w * w )
j = j / b( j, 0.4 )
s += v / j
t += w / j
// honey pot influence
x = h[ o.t ].x - p
y = h[ o.t ].y - q
d =z(m.max( 0.1, x*x + y*y ))
s += 2*x/d
t += 2*y/d
// pointer influence
x = p - n
y = q - g
k = z( x*x + y*y )
k = b( 9, 1760 / ( k*k ) ) / k
s += k*x
t += k*y
// physic step
o.x += (o.u = o.u * 0.92 + s * 0.1)
o.y += (o.v = o.v * 0.92 + t * 0.1)
if ( d < 18 ){
h[ o.t ].s ++
o.t = o.t >= 3 ? o.c : (r()%6)+3
}
}
// loop
requestAnimationFrame( u )
// setTimeout(u,16)
}
u()