setInterval(
function(){
render( context );
update();
}
, );
window.requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
return window.setTimeout(callback, / );
};
})();
window.requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
return window.setTimeout(callback, / );
};
})(); function calLength2(x1, y1, x2, y2) {
return Math.pow(x1 - x2, ) + Math.pow(y1 - y2, );
} function randomColor() {
var col = [, , ];
col[] = Math.random() * + ;
col[] = col[].toFixed();
col[] = Math.random() * + ;
col[] = col[].toFixed();
col[] = Math.random() * + ;
col[] = col[].toFixed();
var num = Math.floor(Math.random() * );
col[num] = ;
return "rgba(" + col[] + "," + col[] + "," + col[] + ",";
} function lerpAngle(a, b, t) {
var d = b - a;
if (d > Math.PI) d = d - * Math.PI;
if (d < -Math.PI) d = d + * Math.PI;
return a + d * t;
} function inOboundary(arrX, arrY, l, r, t, b) { //在l r t b范围内的检测
return arrX > l && arrX < r && arrY > t && arrY < b;
} function rgbColor(r, g, b) {
r = Math.round(r * );
g = Math.round(g * );
b = Math.round(b * );
return "rgba(" + r + "," + g + "," + b + ",1)";
} function rgbNum(r, g, b) {
r = Math.round(r * );
g = Math.round(g * );
b = Math.round(b * );
return "rgba(" + r + "," + g + "," + b;
} function rnd(m) {
var n = m || ;
return Math.random() * n;
} function rateRandom(m, n) {
var sum = ;
for (var i = ; i < (n - m); i++) {
sum += i; } var ran = Math.random() * sum; for (var i = ; i < (n - m); i++) {
ran -= i;
if (ran < ) {
return i - + m;
}
}
} function distance(x1, y1, x2, y2, l) {
var x = Math.abs(x1 - x2);
var y = Math.abs(y1 - y2);
if (x < l && y < l) {
return true;
}
return false;
} function AABBbox(object1, w1, h1, object2, w2, h2, overlap) {
A1 = object1.x + overlap;
B1 = object1.x + w1 - overlap;
C1 = object1.y + overlap;
D1 = object1.y + h1 - overlap; A2 = object2.x + overlap;
B2 = object2.x + w2 - overlap;
C2 = object2.y + overlap;
D2 = object2.y + h2 - overlap; if (A1 > B2 || B1 < A2 || C1 > D2 || D1 < C2) return false;
else return true;
} function dis2(x, y, x0, y0) {
var dx = x - x0;
var dy = y - y0;
return dx * dx + dy * dy;
} function rndi2(m, n) {
var a = Math.random() * (n - m) + m;
return Math.floor(a);
}