allow for speed=0

This commit is contained in:
Asif Bacchus 2020-04-08 07:27:02 -06:00
parent 384589e9a2
commit 3983287420
2 changed files with 7 additions and 5 deletions

View File

@ -8,7 +8,7 @@
href="css/index.min.css" href="css/index.min.css"
crossorigin="anonymous"/> crossorigin="anonymous"/>
</head> </head>
<body onload='particles(avoidMouse=false)'> <body onload='particles(avoidMouse=false, speed=5)'>
<canvas id="particles"></canvas> <canvas id="particles"></canvas>
<!-- javascript --> <!-- javascript -->
<script <script

View File

@ -20,7 +20,7 @@ function particles(){
canvas.height = window.innerHeight; canvas.height = window.innerHeight;
let particlesArray; let particlesArray;
speed = speed / 100; // index speed to base 100 = 1 speed = (speed !== 0) ? (speed / 100) : 0; // index speed to base 100 = 1
// get mouse position // get mouse position
let mousePosition ={ let mousePosition ={
@ -84,8 +84,10 @@ function particles(){
} }
// move particle // move particle
if (speed !== 0) {
this.x += this.directionX * speed; this.x += this.directionX * speed;
this.y += this.directionY * speed; this.y += this.directionY * speed;
}
// draw particle // draw particle
this.draw(); this.draw();
@ -224,7 +226,7 @@ function particles(){
if (typeof speed == 'undefined'){ if (typeof speed == 'undefined'){
speed = 50; speed = 50;
} }
if (Number.isInteger(speed) && (1 <= speed && speed <= 1000)){ if (Number.isInteger(speed) && (0 <= speed && speed <= 1000)){
speed; speed;
} }
else{ else{