s="~Hy |=0 `a. _=' ^30 @UA( ?color :zV &c. %6y $;for(G #)} !Dh. Z/=-2} Yif( X.fill W0, V6x Unew T=7( Qspeed L); K9random() Ja.width H6g. Gvar Fa.height D;6 z){ 9Math. 7function 6this.".split(" ");d="7 A(a,b:=aDy=bDcTczreturn @V-&x,%-&y#DbTc:-=&xDy-=&y}DjTc:+=&xDy+=&y}DkTzreturn 9sqrt(V*V+%*%#DeTc:/=cDy/=c}DfT:=%|}DiTzYisNaN(V+%):=%|}}}7 B(az6a=@W0)Dh=@K-0.5,K-0.5)Dg=@K*J,K*F)DdTbz6`i()!j(6aLQ=6h.k(LYQ>4z6h.e(Q/4LQ=4}Hj(6h)D`f(LYHx<0zHx|!xZelse{YHx>JzHx=J!xZ}Y~<0z~|!yZelse{Y~>Fz~=F!yZ}?=9round(Q*128LbXStyle_rgba('+(?-50)+','+(^0-?)+',W1)';b.beginPath(Lb.arc(Hx,~,Q+2,W9PI*2,falseLbX(#}gc_globalComgOperation';U(7 System(zGa=document.getElementById('c'LJ=F=^0;Gc=`getContext('2d'LGd=[]$b|;b<^;b++zd.push(UB(a)#setInterval(7(zc[gc]_source-over';cXStyle_rgba(WWW0.2)';cXRect(WWJ,FLc[gc]_lighter'$l=Wg=^;l<g;l++zGf=d[l]$h=l+1;h<^;h++zGe=d[h];Gk=f.g.c(e.gLk.e(9pow(9max(1Wk.k()),3)/5Le.`j(kLf.`b(k#f.d(c#},40#L";do{p=d.length;for(i=0;i<s.length;i++){q=s[i];d = d.replace(q[0], q.substr(1,99))}}while(p!=d.length)eval(d)
function Vector(x, y){
this.x = x;
this.y = y;
this.sub = function(other){
return new Vector(
this.x - other.x,
this.y - other.y
);
}
this.isub = function(other){
this.x -= other.x;
this.y -= other.y;
}
this.iadd = function(other){
this.x += other.x;
this.y += other.y;
}
this.size = function(){
return Math.sqrt(this.x*this.x + this.y*this.y);
}
this.idiv = function(scalar){
this.x /= scalar;
this.y /= scalar;
}
this.zero = function(){
this.x = this.y = 0;
}
this.validate = function(){
if(isNaN(this.x+this.y)){
this.x = this.y = 0;
}
}
}
function Particle(canvas){
this.acceleration = new Vector(0, 0);
this.velocity = new Vector(
Math.random() - 0.5,
Math.random() - 0.5
)
this.position = new Vector(
Math.random() * canvas.width,
Math.random() * canvas.height
)
this.step = function(context){
this.acceleration.validate();
this.velocity.iadd(this.acceleration);
speed = this.velocity.size();
if(speed > 4){
this.velocity.idiv(speed/4);
speed = 4;
}
this.position.iadd(this.velocity);
this.acceleration.zero();
// border bounce
if(this.position.x < 0){
this.position.x = 0;
this.velocity.x /= -2;
}
else if(this.position.x > canvas.width){
this.position.x = canvas.width;
this.velocity.x /= -2;
}
if(this.position.y < 0){
this.position.y = 0;
this.velocity.y /= -2;
}
else if(this.position.y > canvas.height){
this.position.y = canvas.height;
this.velocity.y /= -2;
}
color = Math.round(speed*128);
context.fillStyle = 'rgba(' + (color-50) + ',' + (300-color) + ',0,1)';
context.beginPath();
context.arc(this.position.x, this.position.y, speed+2, 0, Math.PI*2, false);
context.fill();
}
}
gc='globalCompositionOperation';
new (function System(){
var canvas = document.getElementById('c');
canvas.width = canvas.height = 300;
var context = canvas.getContext('2d');
var particles = [];
for(var i=0; i<30; i++){
particles.push(new Particle(canvas));
}
setInterval(function(){
// fading
context[gc] = 'source-over';
context.fillStyle = 'rgba(0,0,0,0.2)';
context.fillRect(0, 0, canvas.width, canvas.height);
// dot drawing style
context[gc] = 'lighter';
// nbody code acceleration accumulation
for(var i=0, il=30; i<il; i++){
var a = particles[i];
for(var j=i+1; j<30; j++){
var b = particles[j];
var vec = a.position.sub(b.position);
vec.idiv(Math.pow(Math.max(10, vec.size()), 3)/5); // scale the vector to the inverse square distance
b.acceleration.iadd(vec);
a.acceleration.isub(vec);
}
a.step(context);
}
}, 40);
})