-
Notifications
You must be signed in to change notification settings - Fork 1
/
gravity.js
66 lines (44 loc) · 1.33 KB
/
gravity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Gravity
*/
var Humble = {};
Humble.Gravity = {};
Humble.Gravity.gravity = function () {
this.id = 'gravity';
this.canvas = null;
this.context = null;
this.width = 600;
this.height = 480;
this.constructor();
};
Humble.Gravity.gravity.prototype = {
constructor : function () {
this._initCanvas();
var context = this.context,
controller = new Humble.Gravity.Particle.controller(context),
model = controller.getModel();
for (i = 0; i < 1000; i++) {
var x, y, r;
x = Math.floor(Math.random() * this.width);
y = Math.floor(Math.random() * this.height);
r = Math.floor(10 - Math.log(Math.random() * 1000));
model.addParticle(x, y, r);
}
var d = new Date(),
start = d.getTime(),
end = 0;
controller.render();
d = new Date();
end = d.getTime();
// console.log('Render Time: '+(end-start));
this.controller = controller;
},
_initCanvas : function () {
var canvas = document.getElementById(this.id),
context = canvas.getContext('2d');
canvas.width = this.width;
canvas.height = this.height;
this.canvas = canvas;
this.context = context;
}
};