JavaScript
语言:
JaveScriptBabelCoffeeScript
确定
(function(window, document, undefined) {
var canvas, ctx, height, width, bounds,
center, mouse, hover = false,
mouseDown = false,
props, particles,
stats, gui;
var Vector2 = function(x, y) {
x = x || 0;
y = y || 0;
this.x = x;
this.y = y;
return this;
};
Vector2.prototype.add = function(vec) {
this.x += vec.x;
this.y += vec.y;
};
Vector2.prototype.sub = function(vec) {
this.x -= vec.x;
this.y -= vec.y;
};
Vector2.prototype.lerp = function(to, amount) {
amount = amount || 0.05;
this.x = (1 - amount) * this.x + amount * to.x;
this.y = (1 - amount) * this.y + amount * to.y;
};
Vector2.prototype.distanceTo = function(vec) {
return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
};
Vector2.prototype.angleTo = function(vec, format) {
format = format || 'rad';
var angle = format === 'rad' ? Math.atan2(vec.y - this.y, vec.x - this.x) :
format === 'deg' ? Math.atan2(vec.y - this.y, vec.x - this.x) * 180 / Math.PI :
undefined;
return angle;
};
var Particle = function() {
this.size = props.minSize,
this.velocity = new Vector2(
1 - Math.random() * 2,</