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"
|
href="css/index.min.css"
|
||||||
crossorigin="anonymous"/>
|
crossorigin="anonymous"/>
|
||||||
</head>
|
</head>
|
||||||
<body onload='particles()'>
|
<body onload='particles(avoidMouse = false)'>
|
||||||
<canvas id="particles"></canvas>
|
<canvas id="particles"></canvas>
|
||||||
<!-- javascript -->
|
<!-- javascript -->
|
||||||
<script
|
<script
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
function particles() {
|
function particles(avoidMouse = true) {
|
||||||
/* create particles animation
|
/* create particles animation
|
||||||
based on the amazing tutorial by 'Franks Labratory'
|
based on the amazing tutorial by 'Franks Labratory'
|
||||||
https://youtu.be/d620nV6bp0A
|
https://youtu.be/d620nV6bp0A
|
||||||
@ -56,8 +56,9 @@ function particles() {
|
|||||||
if (this.y > canvas.height || this.y < 0){
|
if (this.y > canvas.height || this.y < 0){
|
||||||
this.directionY = -this.directionY;
|
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 dx = mousePosition.x - this.x;
|
||||||
let dy = mousePosition.y - this.y;
|
let dy = mousePosition.y - this.y;
|
||||||
let distance = Math.sqrt((dx * dx) + (dy * dy));
|
let distance = Math.sqrt((dx * dx) + (dy * dy));
|
||||||
@ -75,7 +76,8 @@ function particles() {
|
|||||||
this.y -= 10;
|
this.y -= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
// move particle
|
// move particle
|
||||||
this.x += this.directionX;
|
this.x += this.directionX;
|
||||||
this.y += this.directionY;
|
this.y += this.directionY;
|
||||||
|
Loading…
Reference in New Issue
Block a user