set mouse avoidance via parameter, default enabled
This commit is contained in:
parent
6b165f24da
commit
bf5321eec5
@ -8,7 +8,7 @@
|
||||
href="css/index.min.css"
|
||||
crossorigin="anonymous"/>
|
||||
</head>
|
||||
<body onload='particles()'>
|
||||
<body onload='particles(avoidMouse = false)'>
|
||||
<canvas id="particles"></canvas>
|
||||
<!-- javascript -->
|
||||
<script
|
||||
|
@ -1,4 +1,4 @@
|
||||
function particles() {
|
||||
function particles(avoidMouse = true) {
|
||||
/* create particles animation
|
||||
based on the amazing tutorial by 'Franks Labratory'
|
||||
https://youtu.be/d620nV6bp0A
|
||||
@ -56,8 +56,9 @@ function particles() {
|
||||
if (this.y > canvas.height || this.y < 0){
|
||||
this.directionY = -this.directionY;
|
||||
}
|
||||
/*
|
||||
// collision detection between mouse and particles
|
||||
|
||||
// avoid the mouse if avoidMouse = true (default)
|
||||
if (avoidMouse){
|
||||
let dx = mousePosition.x - this.x;
|
||||
let dy = mousePosition.y - this.y;
|
||||
let distance = Math.sqrt((dx * dx) + (dy * dy));
|
||||
@ -75,7 +76,8 @@ function particles() {
|
||||
this.y -= 10;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// move particle
|
||||
this.x += this.directionX;
|
||||
this.y += this.directionY;
|
||||
|
Loading…
Reference in New Issue
Block a user