-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.js
43 lines (36 loc) · 1.23 KB
/
tools.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
/*
* Particle generators, polygon drawers and other utility classes.
* Copyright: lanseg, 2012
*/
/*
* Simple particle generator. Defined by segment, maximum generated points and
* minimal delay in milliseconds between point generation
*/
function LineGenerator(segment, mp, delay){
this.segment = segment;
this.maxPoints = mp;
this.delay = delay;
this.generated = 0;
this.lastPTime = 0;
/*
* amount - number of DPoints to be randomly generated along the segment
* speed - speed of each point
*/
this.generate = function(speed, amount) {
var time = new Date().getTime();
var k = arguments.length == 0 ? 1 : speed;
var result = [];
var pp = arguments.length == 2 ? amount : 1;
if (this.generated < this.maxPoints &&
(time - this.lastPTime) >= this.delay) {
this.lastPTime = time;
while (pp > 0 && this.generated < this.maxPoints) {
this.generated++;
pp--;
var p = this.segment.randomPoint();
result.push (new math.DPoint(p.x, p.y, this.segment.line.norm().scale(k)));
}
}
return result;
}
}