console
var H = window.innerHeight,W = window.innerWidth,sin = Math.sin,cos =Math.cos,PI = Math.PI;
var _canvas = new Canvas("canvas",W,H);
var canvas = _canvas.canvas,ctx = _canvas.ctx;
var obj = {balls:[]},num = 10;
function Ball(x0,y0,r,vx){
this.x0 = x0;
this.y0 = y0;
this.x = x0;
this.y = y0;
this.r = r;
this.vx = vx;
this.vy = 0;
this.g = 1000;
this.f = 50;
this.st = +new Date - 20;
this.lt = +new Date - 20;
this.runX = 1;
this.runY = 1;
this.vxarr = [];
this.rgb = [random(100,255,1),random(100,255,1),random(100,255,1)]
}
function init(){
while(num--){
obj.balls.push(new Ball(random(100,W-100),random(100,H-100),random(10,30,1),random(400,800,1,1)));
}
run();
}
function run(){
for(var x in obj.balls){
var v = obj.balls[x];
var now = +new Date;
if(v.runX){
if(v.vx<0) v.f = Math.abs(v.f)*(-1);
else v.f = Math.abs(v.f);
var sx = v.vx*(now-v.lt)/1000-v.f*(now-v.lt)*(now-v.st)/1000000-v.f/2*(now-v.lt)*(now-v.lt)/1000000;
v.x+=sx;
v.sx = sx;
if(Math.abs(sx)<0.01 || Math.abs(v.vx)<Math.abs(v.f)*(now-v.st)/1000){
v.runX = 0;
}
}
if(v.runY){
if(v.vy>=0) v.f = -Math.abs(v.f);
else v.f = Math.abs(v.f);
v.vy += (v.f*5+v.g)*(now-v.lt)/1000;
var ds = v.vy*(now-v.lt)/1000;
v.y+=ds;
if(v.y > H-v.r ){
v.y = H-v.r;
if(Math.abs(v.vy)<10) v.runY = 0;
}
}
if(v.runX || v.runY) v.lt = now;
}
colliding();
render();
requestAnimationFrame(run)
}
function colliding(){
var l = obj.balls.length
if(l){
for(var i=0;i<l;i++){
var b0 = obj.balls[i];
if(b0.x<b0.r || b0.x>W-b0.r) b0.vx = -b0.vx;
if(b0.y<b0.r || b0.y>=H-b0.r) b0.vy = -b0.vy;
for(var j = i+1;j<l;j++){
}
}
}
}
function render(){
ctx.clearRect(0,0,W,H);
for(var x in obj.balls){
var v = obj.balls[x];
ctx.beginPath();
ctx.fillStyle="rgb("+v.rgb[0]+","+v.rgb[1]+","+v.rgb[2]+")";
ctx.arc(v.x,v.y,v.r,0,2*Math.PI);
ctx.fill();
ctx.closePath();
}
}
function distans(x1,y1,x2,y2){
return Math.sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
}
function random(min,max,intval,minus){
var res = Math.random()*(max-min)+min;
res = intval ? parseInt(res) : res;
return minus ? (Math.random()>0.5 ? res : -res) : res;
}
function constantAcceleration(v0,a,st,dt){
var s = v0*t
}
init();
<script src="http://raw.githack.com/BiyugWv/codess/master/codes.js"></script>