@erikwatson/snowfall 3.0.3 → 3.1.1
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 +54 -13
- package/dist/snowfall.min.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -15,34 +15,75 @@ displayed over the top. [Check out this example](http://erikwatson.me/?snow).
|
|
|
15
15
|
- Density of snowflakes looks correct even when the window is resized.
|
|
16
16
|
- Small, with no dependencies.
|
|
17
17
|
|
|
18
|
-
## Instructions
|
|
18
|
+
## Instructions - Package Manager
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### Install it
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
|
-
# if you're using yarn
|
|
23
|
+
# if you're using yarn install with
|
|
24
24
|
yarn add @erikwatson/snowfall
|
|
25
25
|
|
|
26
|
-
# if you're using npm
|
|
26
|
+
# if you're using npm install with
|
|
27
27
|
npm install @erikwatson/snowfall
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
### Use it
|
|
31
|
+
|
|
32
|
+
Add a div with an ID of `snow-container` to your page. You will need to set the
|
|
33
|
+
width and height of this yourself using CSS.
|
|
31
34
|
|
|
32
35
|
```html
|
|
33
|
-
<!-- You are expected to size and position this yourself with CSS -->
|
|
34
36
|
<div id="snow-container"></div>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then, at the bottom of your page body add the following.
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<script
|
|
43
|
+
type="text/javascript"
|
|
44
|
+
src="./node_modules/@erikwatson/snowfall/dist/snowfall.min.js"
|
|
45
|
+
></script>
|
|
46
|
+
<script>
|
|
47
|
+
// You can change the defaults by passing in a config object here
|
|
48
|
+
// Use the Visual Config Editor to create one
|
|
49
|
+
snowfall.start()
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**WARNING:** You should symlink to the .js file rather than have a publicly
|
|
54
|
+
accessible node_modules folder. It is this way here just to keep example simple.
|
|
55
|
+
|
|
56
|
+
## Instructions - CDN
|
|
35
57
|
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
First, add a div with an ID of `snow-container` to your page. You will need to
|
|
59
|
+
set the width and height of this yourself using CSS.
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<div id="snow-container"></div>
|
|
38
63
|
```
|
|
39
64
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
snowfall.
|
|
65
|
+
Then, at the bottom of your page body add the following.
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<script src="https://cdn.jsdelivr.net/npm/@erikwatson/snowfall/dist/snowfall.min.js"></script>
|
|
69
|
+
<script>
|
|
70
|
+
// You can change the defaults by passing in a config object here
|
|
71
|
+
// Use the Visual Config Editor to create one
|
|
72
|
+
snowfall.start()
|
|
73
|
+
</script>
|
|
44
74
|
```
|
|
45
75
|
|
|
46
|
-
|
|
76
|
+
### Specify Version
|
|
77
|
+
|
|
78
|
+
It is not recommended to always use the latest version, especially in
|
|
79
|
+
production. You can change the CDN url to specify control over the version using
|
|
80
|
+
the `@version` syntax like so.
|
|
81
|
+
|
|
82
|
+
- **latest release**: https://cdn.jsdelivr.net/npm/@erikwatson/snowfall/dist/snowfall.min.js
|
|
83
|
+
- **major release**: https://cdn.jsdelivr.net/npm/@erikwatson/snowfall@3/dist/snowfall.min.js
|
|
84
|
+
- **minor release**: https://cdn.jsdelivr.net/npm/@erikwatson/snowfall@3.1/dist/snowfall.min.js
|
|
85
|
+
- **patch release**: https://cdn.jsdelivr.net/npm/@erikwatson/snowfall@3.0.1/dist/snowfall.min.js
|
|
86
|
+
|
|
87
|
+
## Author
|
|
47
88
|
|
|
48
89
|
- [Erik Watson](http://erikwatson.me)
|
package/dist/snowfall.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.snowfall=function(
|
|
1
|
+
window.snowfall=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){const i=n(1),{lerp:r}=n(2),o=document.querySelector("#snow-container"),a=document.createElement("canvas"),d=a.getContext("2d");let s=i.create(0,.7),l=i.create(0,0),c=200,u=[],f="#0d0014",h="#8d90b7",y="#ffffff",g=1,p=.02,v=!1,m=!1;function w(e,t){(s=i.fromDegrees(e)).multiplyScalar(t)}function x(e,t){(l=i.fromDegrees(e)).multiplyScalar(t)}function S(){a.width=o.offsetWidth,a.height=o.offsetHeight,u=O(q())}function b(){u.forEach(e=>{z.x=l.x,z.y=l.y,z.multiplyScalar(e.size+e.random),e.pos.add(z),P.x=s.x,P.y=s.y,P.multiplyScalar(e.size+e.random),e.pos.add(P);const t=e.noise;let n=i.create(g*Math.sin(p*M+t),0);e.pos.add(n),e.pos.x>a.width&&(e.pos.x=0),e.pos.x<0&&(e.pos.x=a.width),e.pos.y>a.height&&(e.pos.y=e.pos.y-a.height,e.pos.x=Math.random()*a.width),e.pos.y<0&&(e.pos.y=a.height-e.pos.y,e.pos.x=Math.random()*a.width),e.renderedSize<e.size&&(e.renderedSize=r(e.renderedSize,e.size,.025))}),previousPageYOffset=window.pageYOffset,M+=1,function(){d.clearRect(0,0,a.width,a.height),f&&(d.fillStyle=f,d.fillRect(0,0,a.width,a.height));const e=u.filter(e=>e.size>=7),t=u.filter(e=>e.size<7);d.fillStyle=h,t.forEach(e=>{d.beginPath(),j(e.pos,e.renderedSize),d.fill()}),d.fillStyle=y,e.forEach(e=>{d.beginPath(),j(e.pos,e.renderedSize),d.fill()})}(),window.requestAnimationFrame(b)}let M=0;const z=i.create(0,0),P=i.create(0,0);function O(e){let t=[];for(;e--;){const e=3+5*Math.random(),n=!0===v?0:e;t.push({pos:i.create(Math.random()*a.width,Math.random()*a.height),size:e,renderedSize:n,noise:10*Math.random(),amplitude:2*Math.random(),frequency:.01*Math.random(),random:Math.random()})}return t}function q(){const e=a.width*a.height;return Math.round(c*(e/2073600))}function j(e,t){d.arc(e.x,e.y,t,0,2*Math.PI,!1)}function _(){u=O(q())}e.exports={setAmplitude:function(e){g=e},setBackground:function(e){f=e},setDensity:function(e){c=e,_()},setFade:function(e){v=e,_()},setScroll:function(e){m=e},setFrequency:function(e){p=e},setGravity:w,setPrimary:function(e){h=e},setSecondary:function(e){y=e},setWind:x,start:function(e={}){void 0!==e.bg&&(f=e.bg),void 0!==e.primary&&(h=e.primary),void 0!==e.secondary&&(y=e.secondary),void 0!==e.density&&(c=e.density),void 0!==e.fadeIn&&(v=e.fadeIn),void 0!==e.scroll&&(m=e.scroll),void 0!==e.wave&&(void 0!==e.wave.amplitude&&(g=e.wave.amplitude),void 0!==e.wave.frequency&&(p=e.wave.frequency)),void 0!==e.gravity&&(void 0!==e.gravity.angle&&void 0!==e.gravity.strength&&w(e.gravity.angle,e.gravity.strength),void 0!==e.gravity.angle&&void 0===e.gravity.strength&&w(e.gravity.angle,.7),void 0===e.gravity.angle&&void 0!==e.gravity.strength&&w(90,e.gravity.strength)),void 0!==e.wind&&(void 0!==e.wind.angle&&void 0!==e.wind.strength&&x(e.wind.angle,e.wind.strength),void 0!==e.wind.angle&&void 0===e.wind.strength&&x(e.wind.angle,0),void 0===e.wind.angle&&void 0!==e.wind.strength&&x(0,e.wind.strength)),a.width=o.offsetWidth,a.height=o.offsetHeight,o.appendChild(a),u=O(q()),window.onresize=S,window.requestAnimationFrame(b)}}},function(e,t){function n(e,t){let r=e,o=t;const a=()=>Math.sqrt(r*r+o*o),d=e=>{r*=e,o*=e},s=()=>{let e=a();r/=e,o/=e};return{add:e=>{r+=e.x,o+=e.y},addScalar:e=>{r+=e,o+=e},clone:i,divide:e=>{r/=e.x,o/=e.y},divideScalar:e=>{r/=e,o/=e},dot:e=>r*e.x+o*e.y,getLength:a,getOpposite:e=>n(-e.x,-e.y),getPerp:()=>n(-o,r),isEqualTo:e=>r==e.x&&o==e.y,multiply:e=>{r*=e.x,o*=e.y},multiplyScalar:d,normalise:s,setLength:e=>{s(),d(e)},subtract:e=>{r-=e.x,o-=e.y},subtractScalar:e=>{r-=e,o-=e},set x(e){r=e},get x(){return r},set y(e){o=e},get y(){return o}}}const i=e=>n(e.x,e.y);e.exports={clone:i,create:n,fromDegrees:e=>{const t=e*(Math.PI/180);return n(Math.cos(t),Math.sin(t))}}},function(e,t){e.exports={lerp:function(e,t,n){return e*(1-n)+t*n}}}]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erikwatson/snowfall",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Nice snow in a JS Canvas.",
|
|
5
5
|
"main": "dist/snowfall.min.js",
|
|
6
6
|
"repository": "git@github.com:erikwatson/snowfall.js.git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"build": "yarn webpack --config ./webpack.development.js",
|
|
17
17
|
"build:production": "yarn webpack --config ./webpack.production.js",
|
|
18
18
|
"build:all": "yarn build && yarn build:production",
|
|
19
|
+
"build:docs": "yarn jsdoc src/snowfall.js -d ./docs README.md",
|
|
19
20
|
"watch": "yarn run build --watch",
|
|
20
21
|
"pub": "yarn build:all && npm publish"
|
|
21
22
|
},
|