add connection and connection density params

This commit is contained in:
Asif Bacchus 2020-04-08 07:21:24 -06:00
parent 99ddb6793f
commit 384589e9a2

View File

@ -114,7 +114,7 @@ function particles(){
for (let a = 0; a < particlesArray.length; a++){ for (let a = 0; a < particlesArray.length; a++){
for (let b = a; b < particlesArray.length; b++){ for (let b = a; b < particlesArray.length; b++){
let distance = ((particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x)) + ((particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y)); let distance = ((particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x)) + ((particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y));
if (distance < (canvas.width / 10) * (canvas.height / 10)){ if (distance < (canvas.width / connectionDensity) * (canvas.height / connectionDensity)){
opacityValue = 1 - (distance / 20000); opacityValue = 1 - (distance / 20000);
// change colour on 'hover' if hover = true (default) // change colour on 'hover' if hover = true (default)
if(hover){ if(hover){
@ -154,8 +154,10 @@ function particles(){
for (let i = 0; i < particlesArray.length; i++){ for (let i = 0; i < particlesArray.length; i++){
particlesArray[i].update(); particlesArray[i].update();
} }
if(connections){
connect(); connect();
} }
}
// resize event // resize event
window.addEventListener('resize', function(){ window.addEventListener('resize', function(){
@ -197,6 +199,28 @@ function particles(){
console.log("'sizeMultiplier' must be a finite number. Using default of '3'"); console.log("'sizeMultiplier' must be a finite number. Using default of '3'");
}; };
if (typeof connections == 'undefined'){
connections = true;
}
else if (typeof connections === 'boolean'){
connections;
}
else{
connections = true;
console.log("'connections' must be either 'true' or 'false'. Using default of 'true'");
}
if (typeof connectionDensity == 'undefined'){
connectionDensity = 7;
}
else if (Number.isFinite(connectionDensity) && connectionDensity > 1){
connectionDensity;
}
else{
connectionDensity = 7;
console.log("'connectionDensity' must be a finite number greater than 1. Using default of '7'");
}
if (typeof speed == 'undefined'){ if (typeof speed == 'undefined'){
speed = 50; speed = 50;
} }