@@ -18,8 +18,9 @@ function launchParticlesJS(tag_id, params){
18
18
h : canvas_el . offsetHeight
19
19
} ,
20
20
particles : {
21
- color : '#fff' ,
22
- color_random : false ,
21
+ color : {
22
+ value : '#fff' // "#ffaa44", "['#ffaa44', '#ffffaa', '#445500']" or "random"
23
+ } ,
23
24
shape : {
24
25
type : 'circle' , // "circle", "edge", "triangle", "polygon", "star" or "image"
25
26
nb_sides : 5 , // 5+
@@ -108,7 +109,7 @@ function launchParticlesJS(tag_id, params){
108
109
}
109
110
110
111
/* convert hex colors to rgb */
111
- pJS . particles . color_rgb = hexToRgb ( pJS . particles . color ) ;
112
+ // pJS.particles.color.rgb = hexToRgb(pJS.particles.color.value );
112
113
pJS . particles . line_linked . color_rgb_line = hexToRgb ( pJS . particles . line_linked . color ) ;
113
114
114
115
/* detect retina */
@@ -214,19 +215,21 @@ function launchParticlesJS(tag_id, params){
214
215
if ( pJS . retina ) this . radius *= pJS . canvas . pxratio ;
215
216
216
217
/* color */
217
- if ( pJS . particles . color_random === true ) {
218
- this . color = {
218
+ this . color = { } ;
219
+ if ( typeof ( color . value ) == 'object' ) {
220
+ var color_selected = color . value [ Math . floor ( Math . random ( ) * pJS . particles . color . value . length ) ] ;
221
+ this . color . rgb = hexToRgb ( color_selected ) ;
222
+ }
223
+ else if ( color . value == 'random' ) {
224
+ this . color . rgb = {
219
225
r : ( Math . floor ( Math . random ( ) * ( 255 - 0 + 1 ) ) + 0 ) ,
220
226
g : ( Math . floor ( Math . random ( ) * ( 255 - 0 + 1 ) ) + 0 ) ,
221
227
b : ( Math . floor ( Math . random ( ) * ( 255 - 0 + 1 ) ) + 0 )
222
228
}
223
- }
224
- else if ( pJS . particles . color_random instanceof Array ) {
225
- this . color = pJS . particles . color_random [ Math . floor ( Math . random ( ) * pJS . particles . color_random . length ) ] ;
226
- this . color = hexToRgb ( this . color ) ;
227
229
}
228
230
else {
229
231
this . color = color ;
232
+ this . color . rgb = hexToRgb ( this . color . value ) ;
230
233
}
231
234
232
235
/* opacity */
@@ -258,29 +261,31 @@ function launchParticlesJS(tag_id, params){
258
261
259
262
pJS . fn . particle . prototype . draw = function ( ) {
260
263
261
- pJS . canvas . ctx . fillStyle = 'rgba(' + this . color . r + ',' + this . color . g + ',' + this . color . b + ',' + this . opacity + ')' ;
264
+ var t = this ;
265
+
266
+ pJS . canvas . ctx . fillStyle = 'rgba(' + t . color . rgb . r + ',' + t . color . rgb . g + ',' + t . color . rgb . b + ',' + t . opacity + ')' ;
262
267
pJS . canvas . ctx . beginPath ( ) ;
263
268
264
269
switch ( pJS . particles . shape . type ) {
265
270
266
271
case 'circle' :
267
- pJS . canvas . ctx . arc ( this . x , this . y , this . radius , 0 , Math . PI * 2 , false ) ;
272
+ pJS . canvas . ctx . arc ( t . x , t . y , t . radius , 0 , Math . PI * 2 , false ) ;
268
273
break ;
269
274
270
275
case 'edge' :
271
- pJS . canvas . ctx . rect ( this . x - this . radius , this . y - this . radius , this . radius * 2 , this . radius * 2 ) ;
276
+ pJS . canvas . ctx . rect ( t . x - t . radius , t . y - t . radius , t . radius * 2 , t . radius * 2 ) ;
272
277
break ;
273
278
274
279
case 'triangle' :
275
- pJS . fn . vendors . drawShape ( pJS . canvas . ctx , this . x - this . radius , this . y + this . radius / 1.66 , this . radius * 2 , 3 , 2 ) ;
280
+ pJS . fn . vendors . drawShape ( pJS . canvas . ctx , t . x - t . radius , t . y + t . radius / 1.66 , t . radius * 2 , 3 , 2 ) ;
276
281
break ;
277
282
278
283
case 'polygon' :
279
284
pJS . fn . vendors . drawShape (
280
285
pJS . canvas . ctx ,
281
- this . x - this . radius / ( pJS . particles . shape . nb_sides / 3.5 ) , // startX
282
- this . y - this . radius / ( 2.66 / 3.5 ) , // startY
283
- this . radius * 2.66 / ( pJS . particles . shape . nb_sides / 3 ) , // sideLength
286
+ t . x - t . radius / ( pJS . particles . shape . nb_sides / 3.5 ) , // startX
287
+ t . y - t . radius / ( 2.66 / 3.5 ) , // startY
288
+ t . radius * 2.66 / ( pJS . particles . shape . nb_sides / 3 ) , // sideLength
284
289
pJS . particles . shape . nb_sides , // sideCountNumerator
285
290
1 // sideCountDenominator
286
291
) ;
@@ -289,18 +294,16 @@ function launchParticlesJS(tag_id, params){
289
294
case 'star' :
290
295
pJS . fn . vendors . drawShape (
291
296
pJS . canvas . ctx ,
292
- this . x - this . radius * 2 / ( pJS . particles . shape . nb_sides / 4 ) , // startX
293
- this . y - this . radius / ( 2 * 2.66 / 3.5 ) , // startY
294
- this . radius * 2 * 2.66 / ( pJS . particles . shape . nb_sides / 3 ) , // sideLength
297
+ t . x - t . radius * 2 / ( pJS . particles . shape . nb_sides / 4 ) , // startX
298
+ t . y - t . radius / ( 2 * 2.66 / 3.5 ) , // startY
299
+ t . radius * 2 * 2.66 / ( pJS . particles . shape . nb_sides / 3 ) , // sideLength
295
300
pJS . particles . shape . nb_sides , // sideCountNumerator
296
301
2 // sideCountDenominator
297
302
) ;
298
303
break ;
299
304
300
305
case 'image' :
301
306
302
- var t = this ;
303
-
304
307
function createImgObj ( img_type ) {
305
308
306
309
// SVG
@@ -314,10 +317,10 @@ function launchParticlesJS(tag_id, params){
314
317
var svgXml = data . currentTarget . response ,
315
318
rgbHex = / # ( [ 0 - 9 A - F ] { 3 , 6 } ) / gi,
316
319
coloredSvgXml = svgXml . replace ( rgbHex , function ( m , r , g , b ) {
317
- return 'rgba(' + t . color . r + ','
318
- + t . color . g + ','
319
- + t . color . b + ','
320
- + t . opacity + ')'
320
+ return 'rgba(' + t . color . rgb . r + ','
321
+ + t . color . rgb . g + ','
322
+ + t . color . rgb . b + ','
323
+ + t . opacity + ')'
321
324
} ) ;
322
325
323
326
var svg = new Blob ( [ coloredSvgXml ] , { type : 'image/svg+xml;charset=utf-8' } ) ,
@@ -374,7 +377,7 @@ function launchParticlesJS(tag_id, params){
374
377
375
378
pJS . fn . particlesCreate = function ( ) {
376
379
for ( var i = 0 ; i < pJS . particles . nb ; i ++ ) {
377
- pJS . particles . array . push ( new pJS . fn . particle ( pJS . particles . color_rgb , pJS . particles . opacity . opacity ) ) ;
380
+ pJS . particles . array . push ( new pJS . fn . particle ( pJS . particles . color , pJS . particles . opacity . opacity ) ) ;
378
381
}
379
382
} ;
380
383
@@ -450,7 +453,8 @@ function launchParticlesJS(tag_id, params){
450
453
/* draw each particle */
451
454
for ( var i = 0 ; i < pJS . particles . array . length ; i ++ ) {
452
455
var p = pJS . particles . array [ i ] ;
453
- p . draw ( 'rgba(' + p . color . r + ',' + p . color . g + ',' + p . color . b + ',' + p . opacity + ')' ) ;
456
+ //console.log(p.color.rgb);
457
+ p . draw ( 'rgba(' + p . color . rgb . r + ',' + p . color . rgb . g + ',' + p . color . rgb . b + ',' + p . opacity + ')' ) ;
454
458
}
455
459
456
460
} ;
@@ -565,7 +569,7 @@ function launchParticlesJS(tag_id, params){
565
569
for ( var i = 0 ; i < nb ; i ++ ) {
566
570
pJS . particles . array . push (
567
571
new pJS . fn . particle (
568
- pJS . particles . color_rgb ,
572
+ pJS . particles . color ,
569
573
pJS . particles . opacity . opacity ,
570
574
{
571
575
'x' : pos ? pos . pos_x : Math . random ( ) * pJS . canvas . w ,
0 commit comments