Skip to content

Commit efad15e

Browse files
Merge pull request VincentGarreau#29 from VincentGarreau/dev
dev - 1.0.3
2 parents b1da10f + 777e8e3 commit efad15e

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
particles.min.js

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "particles.js",
33
"main": "particles.js",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"homepage": "https://github.com/VincentGarreau/particles.js",
66
"authors": [
77
"Vincent Garreau <vin.garreau@gmail.com>"

particles.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* MIT license: http://opensource.org/licenses/MIT
44
/* GitHub : https://github.com/VincentGarreau/particles.js
55
/* How to use? : Check the GitHub README
6-
/* v1.0.2
6+
/* v1.0.3
77
/* ----------------------------------------------- */
88

99
function launchParticlesJS(tag_id, params){
@@ -129,12 +129,14 @@ function launchParticlesJS(tag_id, params){
129129
/* detect retina */
130130
if(pJS.retina_detect && window.devicePixelRatio > 1){
131131
pJS.retina = true;
132-
pJS.canvas.w = pJS.canvas.el.offsetWidth*2;
133-
pJS.canvas.h = pJS.canvas.el.offsetHeight*2;
134-
pJS.particles.anim.speed = pJS.particles.anim.speed*2;
135-
pJS.particles.line_linked.distance = pJS.particles.line_linked.distance*2;
136-
pJS.particles.line_linked.width = pJS.particles.line_linked.width*2;
137-
pJS.interactivity.mouse.distance = pJS.interactivity.mouse.distance*2;
132+
133+
pJS.canvas.pxratio = window.devicePixelRatio
134+
pJS.canvas.w = pJS.canvas.el.offsetWidth * pJS.canvas.pxratio;
135+
pJS.canvas.h = pJS.canvas.el.offsetHeight * pJS.canvas.pxratio;
136+
pJS.particles.anim.speed = pJS.particles.anim.speed * pJS.canvas.pxratio;
137+
pJS.particles.line_linked.distance = pJS.particles.line_linked.distance * pJS.canvas.pxratio;
138+
pJS.particles.line_linked.width = pJS.particles.line_linked.width * pJS.canvas.pxratio;
139+
pJS.interactivity.mouse.distance = pJS.interactivity.mouse.distance * pJS.canvas.pxratio;
138140
}
139141

140142

@@ -155,8 +157,8 @@ function launchParticlesJS(tag_id, params){
155157

156158
/* resize canvas */
157159
if(pJS.retina){
158-
pJS.canvas.w *= 2;
159-
pJS.canvas.h *= 2;
160+
pJS.canvas.w *= pJS.canvas.pxratio;
161+
pJS.canvas.h *= pJS.canvas.pxratio;
160162
}
161163

162164
pJS.canvas.el.width = pJS.canvas.w;
@@ -192,7 +194,7 @@ function launchParticlesJS(tag_id, params){
192194

193195
/* size */
194196
this.radius = (pJS.particles.size_random ? Math.random() : 1) * pJS.particles.size;
195-
if (pJS.retina) this.radius *= 2;
197+
if (pJS.retina) this.radius *= pJS.canvas.pxratio;
196198

197199
/* color */
198200
this.color = color;
@@ -219,9 +221,9 @@ function launchParticlesJS(tag_id, params){
219221
break;
220222

221223
case 'triangle':
222-
pJS.canvas.ctx.moveTo(this.x,this.y);
223-
pJS.canvas.ctx.lineTo(this.x+this.radius,this.y+this.radius*2);
224-
pJS.canvas.ctx.lineTo(this.x-this.radius,this.y+this.radius*2);
224+
pJS.canvas.ctx.moveTo(this.x,this.y-this.radius);
225+
pJS.canvas.ctx.lineTo(this.x+this.radius,this.y+this.radius);
226+
pJS.canvas.ctx.lineTo(this.x-this.radius,this.y+this.radius);
225227
pJS.canvas.ctx.closePath();
226228
break;
227229
}
@@ -343,13 +345,14 @@ function launchParticlesJS(tag_id, params){
343345

344346
/* el on mousemove */
345347
detect_el.onmousemove = function(e){
348+
346349
if(detect_el == window){
347350
var pos_x = e.clientX,
348351
pos_y = e.clientY;
349352
}
350353
else{
351-
var pos_x = e.offsetX,
352-
pos_y = e.offsetY;
354+
var pos_x = e.offsetX||e.clientX,
355+
pos_y = e.offsetY||e.clientY;
353356
}
354357

355358
if(pJS){
@@ -358,8 +361,8 @@ function launchParticlesJS(tag_id, params){
358361
pJS.interactivity.mouse.pos_y = pos_y;
359362

360363
if(pJS.retina){
361-
pJS.interactivity.mouse.pos_x *= 2;
362-
pJS.interactivity.mouse.pos_y *= 2;
364+
pJS.interactivity.mouse.pos_x *= pJS.canvas.pxratio;
365+
pJS.interactivity.mouse.pos_y *= pJS.canvas.pxratio;
363366
}
364367

365368
pJS.interactivity.status = 'mousemove';

particles.min.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)