canvasparticles-js 3.2.15 → 3.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/canvasParticles.js +25 -20
- package/canvasParticles.mjs +25 -20
- package/package.json +30 -30
package/README.md
CHANGED
|
@@ -131,7 +131,6 @@ particles.stop()
|
|
|
131
131
|
|
|
132
132
|
```js
|
|
133
133
|
const particles = new CanvasParticles(selector, options)
|
|
134
|
-
particles.options.particles.color = 'blue'
|
|
135
134
|
|
|
136
135
|
// Required usage of setter for options.background and options.particles.color
|
|
137
136
|
particles.setBackground('red')
|
package/canvasParticles.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* Canvas Particles JS
|
|
6
6
|
*
|
|
7
7
|
* @class CanvasParticles
|
|
8
|
-
* @version 3.2.
|
|
8
|
+
* @version 3.2.17
|
|
9
9
|
*/
|
|
10
10
|
class CanvasParticles {
|
|
11
|
-
static version = '3.2.
|
|
12
|
-
animating = false
|
|
11
|
+
static version = '3.2.17'
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Creates a new CanvasParticles instance.
|
|
@@ -26,6 +25,18 @@ class CanvasParticles {
|
|
|
26
25
|
// Get 2d drawing functions
|
|
27
26
|
this.ctx = this.canvas.getContext('2d')
|
|
28
27
|
|
|
28
|
+
this.animating = false
|
|
29
|
+
this.formatOptions(options)
|
|
30
|
+
|
|
31
|
+
// Event handling
|
|
32
|
+
window.addEventListener('resize', this.resizeCanvas)
|
|
33
|
+
this.resizeCanvas()
|
|
34
|
+
|
|
35
|
+
window.addEventListener('mousemove', this.updateMousePos)
|
|
36
|
+
window.addEventListener('scroll', this.updateMousePos)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
formatOptions = options => {
|
|
29
40
|
// Format and store options
|
|
30
41
|
this.options = {
|
|
31
42
|
background: options.background ?? false,
|
|
@@ -72,29 +83,23 @@ class CanvasParticles {
|
|
|
72
83
|
if (isNaN(this.options.gravity.pulling)) this.options.gravity.pulling = 0
|
|
73
84
|
if (isNaN(this.options.gravity.friction)) this.options.gravity.friction = 0.9
|
|
74
85
|
|
|
75
|
-
this.setBackground(this.options.background)
|
|
76
|
-
this.setParticleColor(this.options.particles.color)
|
|
77
|
-
|
|
78
86
|
// Transform distance multiplier to absolute distance
|
|
79
87
|
this.options.mouse.connectDist = this.options.particles.connectDist * this.options.mouse.connectDistMult
|
|
80
88
|
delete this.options.mouse.connectDistMult
|
|
81
89
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
this.setBackground(this.options.background)
|
|
91
|
+
this.setParticleColor(this.options.particles.color)
|
|
92
|
+
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
updateMousePos = event => {
|
|
95
|
+
if (!this.animating) return
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
this.mouseX = this.clientX - this.canvas.offsetLeft + window.scrollX
|
|
94
|
-
this.mouseY = this.clientY - this.canvas.offsetTop + window.scrollY
|
|
97
|
+
if (event instanceof MouseEvent) {
|
|
98
|
+
this.clientX = event.clientX
|
|
99
|
+
this.clientY = event.clientY
|
|
95
100
|
}
|
|
96
|
-
window.
|
|
97
|
-
window.
|
|
101
|
+
this.mouseX = this.clientX - this.canvas.offsetLeft + window.scrollX
|
|
102
|
+
this.mouseY = this.clientY - this.canvas.offsetTop + window.scrollY
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
resizeCanvas = () => {
|
|
@@ -120,7 +125,7 @@ class CanvasParticles {
|
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
/**
|
|
123
|
-
* Remove all particles and
|
|
128
|
+
* Remove all particles and generate new ones.
|
|
124
129
|
* The amount of new particles will match 'options.particles.ppm'
|
|
125
130
|
* */
|
|
126
131
|
newParticles = () => {
|
package/canvasParticles.mjs
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* Canvas Particles JS
|
|
6
6
|
*
|
|
7
7
|
* @module CanvasParticles
|
|
8
|
-
* @version 3.2.
|
|
8
|
+
* @version 3.2.17
|
|
9
9
|
*/
|
|
10
10
|
export default class CanvasParticles {
|
|
11
|
-
static version = '3.2.
|
|
12
|
-
animating = false
|
|
11
|
+
static version = '3.2.17'
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Creates a new CanvasParticles instance.
|
|
@@ -26,6 +25,18 @@ export default class CanvasParticles {
|
|
|
26
25
|
// Get 2d drawing functions
|
|
27
26
|
this.ctx = this.canvas.getContext('2d')
|
|
28
27
|
|
|
28
|
+
this.animating = false
|
|
29
|
+
this.formatOptions(options)
|
|
30
|
+
|
|
31
|
+
// Event handling
|
|
32
|
+
window.addEventListener('resize', this.resizeCanvas)
|
|
33
|
+
this.resizeCanvas()
|
|
34
|
+
|
|
35
|
+
window.addEventListener('mousemove', this.updateMousePos)
|
|
36
|
+
window.addEventListener('scroll', this.updateMousePos)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
formatOptions = options => {
|
|
29
40
|
// Format and store options
|
|
30
41
|
this.options = {
|
|
31
42
|
background: options.background ?? false,
|
|
@@ -72,29 +83,23 @@ export default class CanvasParticles {
|
|
|
72
83
|
if (isNaN(this.options.gravity.pulling)) this.options.gravity.pulling = 0
|
|
73
84
|
if (isNaN(this.options.gravity.friction)) this.options.gravity.friction = 0.9
|
|
74
85
|
|
|
75
|
-
this.setBackground(this.options.background)
|
|
76
|
-
this.setParticleColor(this.options.particles.color)
|
|
77
|
-
|
|
78
86
|
// Transform distance multiplier to absolute distance
|
|
79
87
|
this.options.mouse.connectDist = this.options.particles.connectDist * this.options.mouse.connectDistMult
|
|
80
88
|
delete this.options.mouse.connectDistMult
|
|
81
89
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
this.setBackground(this.options.background)
|
|
91
|
+
this.setParticleColor(this.options.particles.color)
|
|
92
|
+
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
updateMousePos = event => {
|
|
95
|
+
if (!this.animating) return
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
this.mouseX = this.clientX - this.canvas.offsetLeft + window.scrollX
|
|
94
|
-
this.mouseY = this.clientY - this.canvas.offsetTop + window.scrollY
|
|
97
|
+
if (event instanceof MouseEvent) {
|
|
98
|
+
this.clientX = event.clientX
|
|
99
|
+
this.clientY = event.clientY
|
|
95
100
|
}
|
|
96
|
-
window.
|
|
97
|
-
window.
|
|
101
|
+
this.mouseX = this.clientX - this.canvas.offsetLeft + window.scrollX
|
|
102
|
+
this.mouseY = this.clientY - this.canvas.offsetTop + window.scrollY
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
resizeCanvas = () => {
|
|
@@ -120,7 +125,7 @@ export default class CanvasParticles {
|
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
/**
|
|
123
|
-
* Remove all particles and
|
|
128
|
+
* Remove all particles and generate new ones.
|
|
124
129
|
* The amount of new particles will match 'options.particles.ppm'
|
|
125
130
|
* */
|
|
126
131
|
newParticles = () => {
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "canvasparticles-js",
|
|
3
|
-
"version": "3.2.
|
|
4
|
-
"description": "In an HTML canvas, a bunch of floating particles connected with lines when they approach eachother. Creating a fun and interactive background.",
|
|
5
|
-
"main": "canvasParticles.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/Khoeckman/canvasParticles.git"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"front-end",
|
|
13
|
-
"frontend",
|
|
14
|
-
"canvas",
|
|
15
|
-
"particles",
|
|
16
|
-
"particle",
|
|
17
|
-
"animation",
|
|
18
|
-
"animated",
|
|
19
|
-
"javascript",
|
|
20
|
-
"js",
|
|
21
|
-
"html5",
|
|
22
|
-
"html"
|
|
23
|
-
],
|
|
24
|
-
"author": "Kyle Hoeckman",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/Khoeckman/canvasParticles/issues"
|
|
28
|
-
},
|
|
29
|
-
"homepage": "http://kylehoeckman.great-site.net/canvas-particles/"
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "canvasparticles-js",
|
|
3
|
+
"version": "3.2.17",
|
|
4
|
+
"description": "In an HTML canvas, a bunch of floating particles connected with lines when they approach eachother. Creating a fun and interactive background.",
|
|
5
|
+
"main": "canvasParticles.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Khoeckman/canvasParticles.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"canvas",
|
|
15
|
+
"particles",
|
|
16
|
+
"particle",
|
|
17
|
+
"animation",
|
|
18
|
+
"animated",
|
|
19
|
+
"javascript",
|
|
20
|
+
"js",
|
|
21
|
+
"html5",
|
|
22
|
+
"html"
|
|
23
|
+
],
|
|
24
|
+
"author": "Kyle Hoeckman",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Khoeckman/canvasParticles/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "http://kylehoeckman.great-site.net/canvas-particles/"
|
|
30
|
+
}
|