Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/particle.js
1330 views
1
/*==============================================================================
2
Init
3
==============================================================================*/
4
$.Particle = function( opt ) {
5
for( var k in opt ) {
6
this[k] = opt[k];
7
}
8
};
9
10
/*==============================================================================
11
Update
12
==============================================================================*/
13
$.Particle.prototype.update = function( i ) {
14
/*==============================================================================
15
Apply Forces
16
==============================================================================*/
17
this.x += Math.cos( this.direction ) * ( this.speed * $.dt );
18
this.y += Math.sin( this.direction ) * ( this.speed * $.dt );
19
this.ex = this.x - Math.cos( this.direction ) * this.speed;
20
this.ey = this.y - Math.sin( this.direction ) * this.speed;
21
this.speed *= this.friction;
22
23
/*==============================================================================
24
Lock Bounds
25
==============================================================================*/
26
if( !$.util.pointInRect( this.ex, this.ey, 0, 0, $.ww, $.wh ) || this.speed <= 0.05 ) {
27
this.parent.splice( i, 1 );
28
}
29
30
/*==============================================================================
31
Update View
32
==============================================================================*/
33
if( $.util.pointInRect( this.ex, this.ey, -$.screen.x, -$.screen.y, $.cw, $.ch ) ) {
34
this.inView = 1;
35
} else {
36
this.inView = 0;
37
}
38
};
39
40
/*==============================================================================
41
Render
42
==============================================================================*/
43
$.Particle.prototype.render = function( i ) {
44
if( this.inView ) {
45
$.ctxmg.beginPath();
46
$.ctxmg.moveTo( this.x, this.y );
47
$.ctxmg.lineTo( this.ex, this.ey );
48
$.ctxmg.lineWidth = this.lineWidth;
49
$.ctxmg.strokeStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + $.util.rand( 50, 100 ) + '%, 1)';
50
$.ctxmg.stroke();
51
}
52
}
53