6
6
/* ----------------------------------------------- */
7
7
8
8
function launchParticlesJS ( tag_id , params ) {
9
+ var canvas_el = document . querySelector ( '#' + tag_id + ' > canvas' ) ;
9
10
10
11
/* particles.js variables with default values */
11
12
pJS = {
12
13
canvas : {
13
- el : document . querySelector ( '#' + tag_id + ' > canvas' ) ,
14
- w : document . querySelector ( '#' + tag_id + ' > canvas' ) . offsetWidth ,
15
- h : document . querySelector ( '#' + tag_id + ' > canvas' ) . offsetHeight
14
+ el : canvas_el ,
15
+ w : canvas_el . offsetWidth ,
16
+ h : canvas_el . offsetHeight
16
17
} ,
17
18
particles : {
18
19
color : '#fff' ,
@@ -98,17 +99,15 @@ function launchParticlesJS(tag_id, params){
98
99
pJS . particles . line_linked . color_rgb_line = hexToRgb ( pJS . particles . line_linked . color ) ;
99
100
100
101
/* detect retina */
101
- if ( pJS . retina_detect ) {
102
- if ( window . devicePixelRatio > 1 ) {
103
- pJS . retina = true ;
104
- pJS . canvas . w = pJS . canvas . el . offsetWidth * 2 ;
105
- pJS . canvas . h = pJS . canvas . el . offsetHeight * 2 ;
106
- pJS . particles . anim . speed = pJS . particles . anim . speed * 2 ;
107
- pJS . particles . line_linked . distance = pJS . particles . line_linked . distance * 2 ;
108
- pJS . particles . line_linked . width = pJS . particles . line_linked . width * 2 ;
109
- pJS . interactivity . mouse . distance = pJS . interactivity . mouse . distance * 2 ;
110
- }
111
- } ;
102
+ if ( pJS . retina_detect && window . devicePixelRatio > 1 ) {
103
+ pJS . retina = true ;
104
+ pJS . canvas . w = pJS . canvas . el . offsetWidth * 2 ;
105
+ pJS . canvas . h = pJS . canvas . el . offsetHeight * 2 ;
106
+ pJS . particles . anim . speed = pJS . particles . anim . speed * 2 ;
107
+ pJS . particles . line_linked . distance = pJS . particles . line_linked . distance * 2 ;
108
+ pJS . particles . line_linked . width = pJS . particles . line_linked . width * 2 ;
109
+ pJS . interactivity . mouse . distance = pJS . interactivity . mouse . distance * 2 ;
110
+ }
112
111
113
112
114
113
/* ---------- CANVAS functions ------------ */
@@ -122,14 +121,15 @@ function launchParticlesJS(tag_id, params){
122
121
pJS . canvas . el . height = pJS . canvas . h ;
123
122
124
123
window . onresize = function ( ) {
124
+ pJS . canvas . w = pJS . canvas . el . offsetWidth ;
125
+ pJS . canvas . h = pJS . canvas . el . offsetHeight ;
126
+
125
127
/* resize canvas */
126
128
if ( pJS . retina ) {
127
- pJS . canvas . w = pJS . canvas . el . offsetWidth * 2 ;
128
- pJS . canvas . h = pJS . canvas . el . offsetHeight * 2 ;
129
- } else {
130
- pJS . canvas . w = pJS . canvas . el . offsetWidth ;
131
- pJS . canvas . h = pJS . canvas . el . offsetHeight ;
129
+ pJS . canvas . w *= 2 ;
130
+ pJS . canvas . h *= 2 ;
132
131
}
132
+
133
133
pJS . canvas . el . width = pJS . canvas . w ;
134
134
pJS . canvas . el . height = pJS . canvas . h ;
135
135
@@ -161,19 +161,8 @@ function launchParticlesJS(tag_id, params){
161
161
this . y = Math . random ( ) * pJS . canvas . h ;
162
162
163
163
/* size */
164
- if ( pJS . retina ) {
165
- if ( pJS . particles . size_random ) {
166
- this . radius = Math . random ( ) * pJS . particles . size * 2 ;
167
- } else {
168
- this . radius = pJS . particles . size * 2 ;
169
- }
170
- } else {
171
- if ( pJS . particles . size_random ) {
172
- this . radius = Math . random ( ) * pJS . particles . size * 1 ;
173
- } else {
174
- this . radius = pJS . particles . size * 1 ;
175
- }
176
- }
164
+ this . radius = ( pJS . particles . size_random ? Math . random ( ) : 1 ) * pJS . particles . size ;
165
+ if ( pJS . retina ) this . radius *= 2 ;
177
166
178
167
/* color */
179
168
this . color = color ;
@@ -302,9 +291,9 @@ function launchParticlesJS(tag_id, params){
302
291
303
292
/* condensed particles */
304
293
if ( pJS . particles . line_linked . condensed_mode . enable ) {
305
- var dx = p1 . x - p2 . x ;
306
- dy = p1 . y - p2 . y ;
307
- var ax = dx / ( pJS . particles . line_linked . condensed_mode . rotateX * 1000 ) ,
294
+ var dx = p1 . x - p2 . x ,
295
+ dy = p1 . y - p2 . y ,
296
+ ax = dx / ( pJS . particles . line_linked . condensed_mode . rotateX * 1000 ) ,
308
297
ay = dy / ( pJS . particles . line_linked . condensed_mode . rotateY * 1000 ) ;
309
298
// p1.vx -= ax;
310
299
// p1.vy -= ay;
@@ -323,13 +312,14 @@ function launchParticlesJS(tag_id, params){
323
312
}
324
313
325
314
detect_el . onmousemove = function ( e ) {
315
+ pJS . interactivity . mouse . pos_x = e . pageX ;
316
+ pJS . interactivity . mouse . pos_y = e . pageY ;
317
+
326
318
if ( pJS . retina ) {
327
- pJS . interactivity . mouse . pos_x = e . pageX * 2 ;
328
- pJS . interactivity . mouse . pos_y = e . pageY * 2 ;
329
- } else {
330
- pJS . interactivity . mouse . pos_x = e . pageX ;
331
- pJS . interactivity . mouse . pos_y = e . pageY ;
319
+ pJS . interactivity . mouse . pos_x *= 2 ;
320
+ pJS . interactivity . mouse . pos_y *= 2 ;
332
321
}
322
+
333
323
pJS . interactivity . status = 'mousemove' ;
334
324
}
335
325
detect_el . onmouseleave = function ( e ) {
0 commit comments