Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added destroy out_mode #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ particlesJS.load('particles-js', 'assets/particles.json', function() {
key | option type / notes | example
----|---------|------
`particles.number.value` | number | `40`
`particles.number.density.enable` | boolean | `true` / `false`
`particles.number.density.enable` | boolean | `true` / `false`
`particles.number.density.value_area` | number | `800`
`particles.color.value` | HEX (string) <br /> RGB (object) <br /> HSL (object) <br /> array selection (HEX) <br /> random (string) | `"#b61924"` <br /> `{r:182, g:25, b:36}` <br /> `{h:356, s:76, l:41}` <br /> `["#b61924", "#333333", "999999"]` <br /> `"random"`
`particles.shape.type` | string <br /> array selection | `"circle"` <br /> `"edge"` <br /> `"triangle"` <br /> `"polygon"` <br /> `"star"` <br /> `"image"` <br /> `["circle", "triangle", "image"]`
Expand All @@ -165,14 +165,14 @@ key | option type / notes | example
`particles.shape.image.width` | number <br />(for aspect ratio) | `100`
`particles.shape.image.height` | number <br />(for aspect ratio) | `100`
`particles.opacity.value` | number (0 to 1) | `0.75`
`particles.opacity.random` | boolean | `true` / `false`
`particles.opacity.anim.enable` | boolean | `true` / `false`
`particles.opacity.random` | boolean | `true` / `false`
`particles.opacity.anim.enable` | boolean | `true` / `false`
`particles.opacity.anim.speed` | number | `3`
`particles.opacity.anim.opacity_min` | number (0 to 1) | `0.25`
`particles.opacity.anim.sync` | boolean | `true` / `false`
`particles.size.value` | number | `20`
`particles.size.random` | boolean | `true` / `false`
`particles.size.anim.enable` | boolean | `true` / `false`
`particles.size.random` | boolean | `true` / `false`
`particles.size.anim.enable` | boolean | `true` / `false`
`particles.size.anim.speed` | number | `3`
`particles.size.anim.size_min` | number | `0.25`
`particles.size.anim.sync` | boolean | `true` / `false`
Expand All @@ -186,7 +186,7 @@ key | option type / notes | example
`particles.move.direction` | string | `"none"` <br /> `"top"` <br /> `"top-right"` <br /> `"right"` <br /> `"bottom-right"` <br /> `"bottom"` <br /> `"bottom-left"` <br /> `"left"` <br /> `"top-left"`
`particles.move.random` | boolean | `true` / `false`
`particles.move.straight` | boolean | `true` / `false`
`particles.move.out_mode` | string <br /> (out of canvas) | `"out"` <br /> `"bounce"`
`particles.move.out_mode` | string <br /> (out of canvas) | `"out"` <br /> `"bounce"` <br /> `"destroy"`
`particles.move.bounce` | boolean <br /> (between particles) | `true` / `false`
`particles.move.attract.enable` | boolean | `true` / `false`
`particles.move.attract.rotateX` | number | `3000`
Expand Down
89 changes: 52 additions & 37 deletions particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ var pJS = function(tag_id, params){
pJS.fn.retinaInit = function(){

if(pJS.retina_detect && window.devicePixelRatio > 1){
pJS.canvas.pxratio = window.devicePixelRatio;
pJS.canvas.pxratio = window.devicePixelRatio;
pJS.tmp.retina = true;
}
}
else{
pJS.canvas.pxratio = 1;
pJS.tmp.retina = false;
Expand Down Expand Up @@ -363,7 +363,7 @@ var pJS = function(tag_id, params){
this.vx_i = this.vx;
this.vy_i = this.vy;



/* if shape is image */

Expand Down Expand Up @@ -392,7 +392,7 @@ var pJS = function(tag_id, params){
}
}



};

Expand All @@ -402,7 +402,7 @@ var pJS = function(tag_id, params){
var p = this;

if(p.radius_bubble != undefined){
var radius = p.radius_bubble;
var radius = p.radius_bubble;
}else{
var radius = p.radius;
}
Expand Down Expand Up @@ -491,9 +491,9 @@ var pJS = function(tag_id, params){
pJS.canvas.ctx.lineWidth = pJS.particles.shape.stroke.width;
pJS.canvas.ctx.stroke();
}

pJS.canvas.ctx.fill();

};


Expand Down Expand Up @@ -566,21 +566,36 @@ var pJS = function(tag_id, params){
}
}

if(p.x - p.radius > pJS.canvas.w){
p.x = new_pos.x_left;
p.y = Math.random() * pJS.canvas.h;
}
else if(p.x + p.radius < 0){
p.x = new_pos.x_right;
p.y = Math.random() * pJS.canvas.h;
}
if(p.y - p.radius > pJS.canvas.h){
p.y = new_pos.y_top;
p.x = Math.random() * pJS.canvas.w;
}
else if(p.y + p.radius < 0){
p.y = new_pos.y_bottom;
p.x = Math.random() * pJS.canvas.w;
/* remove the particle from the array if it is out of canvas */
if(pJS.particles.move.out_mode == 'destroy'){
if(p.x - p.radius > pJS.canvas.w ||
p.x + p.radius < 0 ||
p.y - p.radius > pJS.canvas.h ||
p.y + p.radius < 0){
pJS.particles.array.splice(i, 1);

/* remove the canvas if the arary is empty */
if(pJS.particles.array.length == 0){
pJS.fn.vendors.destroypJS();
}
}
}else{
if(p.x - p.radius > pJS.canvas.w){
p.x = new_pos.x_left;
p.y = Math.random() * pJS.canvas.h;
}
else if(p.x + p.radius < 0){
p.x = new_pos.x_right;
p.y = Math.random() * pJS.canvas.h;
}
if(p.y - p.radius > pJS.canvas.h){
p.y = new_pos.y_top;
p.x = Math.random() * pJS.canvas.w;
}
else if(p.y + p.radius < 0){
p.y = new_pos.y_bottom;
p.x = Math.random() * pJS.canvas.w;
}
}

/* out of canvas modes */
Expand Down Expand Up @@ -664,7 +679,7 @@ var pJS = function(tag_id, params){
pJS.tmp.count_svg = 0;
pJS.fn.particlesEmpty();
pJS.fn.canvasClear();

/* restart */
pJS.fn.vendors.start();

Expand All @@ -684,14 +699,14 @@ var pJS = function(tag_id, params){

var opacity_line = pJS.particles.line_linked.opacity - (dist / (1/pJS.particles.line_linked.opacity)) / pJS.particles.line_linked.distance;

if(opacity_line > 0){
if(opacity_line > 0){

/* style */
var color_line = pJS.particles.line_linked.color_rgb_line;
pJS.canvas.ctx.strokeStyle = 'rgba('+color_line.r+','+color_line.g+','+color_line.b+','+opacity_line+')';
pJS.canvas.ctx.lineWidth = pJS.particles.line_linked.width;
//pJS.canvas.ctx.lineCap = 'round'; /* performance issue */

/* path */
pJS.canvas.ctx.beginPath();
pJS.canvas.ctx.moveTo(p1.x, p1.y);
Expand Down Expand Up @@ -725,7 +740,7 @@ var pJS = function(tag_id, params){
p2.vy += ay;

}


}

Expand Down Expand Up @@ -805,7 +820,7 @@ var pJS = function(tag_id, params){
if(dist_mouse <= pJS.interactivity.modes.bubble.distance){

if(ratio >= 0 && pJS.interactivity.status == 'mousemove'){

/* size */
if(pJS.interactivity.modes.bubble.size != pJS.particles.size.value){

Expand Down Expand Up @@ -854,7 +869,7 @@ var pJS = function(tag_id, params){
if(pJS.interactivity.status == 'mouseleave'){
init();
}

}

/* on click event */
Expand Down Expand Up @@ -933,7 +948,7 @@ var pJS = function(tag_id, params){
repulseRadius = pJS.interactivity.modes.repulse.distance,
velocity = 100,
repulseFactor = clamp((1/repulseRadius)*(-1*Math.pow(dist_mouse/repulseRadius,2)+1)*repulseRadius*velocity, 0, 50);

var pos = {
x: p.x + normVec.x * repulseFactor,
y: p.y + normVec.y * repulseFactor
Expand All @@ -946,7 +961,7 @@ var pJS = function(tag_id, params){
p.x = pos.x;
p.y = pos.y;
}

}


Expand Down Expand Up @@ -1001,15 +1016,15 @@ var pJS = function(tag_id, params){
// }else{
// process();
// }


}else{

if(pJS.tmp.repulse_clicking == false){

p.vx = p.vx_i;
p.vy = p.vy_i;

}

}
Expand Down Expand Up @@ -1039,7 +1054,7 @@ var pJS = function(tag_id, params){
pJS.canvas.ctx.strokeStyle = 'rgba('+color_line.r+','+color_line.g+','+color_line.b+','+opacity_line+')';
pJS.canvas.ctx.lineWidth = pJS.particles.line_linked.width;
//pJS.canvas.ctx.lineCap = 'round'; /* performance issue */

/* path */
pJS.canvas.ctx.beginPath();
pJS.canvas.ctx.moveTo(p.x, p.y);
Expand Down Expand Up @@ -1155,7 +1170,7 @@ var pJS = function(tag_id, params){
}

});

}


Expand Down Expand Up @@ -1359,7 +1374,7 @@ var pJS = function(tag_id, params){
pJS.fn.vendors.init();
pJS.fn.vendors.draw();
}

}

}else{
Expand Down Expand Up @@ -1406,7 +1421,7 @@ var pJS = function(tag_id, params){
pJS.fn.vendors.eventsListeners();

pJS.fn.vendors.start();



};
Expand Down