@andresclua/perlindom 0.0.6 → 0.1.0

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.
@@ -1,138 +0,0 @@
1
- var D = Object.defineProperty;
2
- var z = (c) => {
3
- throw TypeError(c);
4
- };
5
- var H = (c, t, s) => t in c ? D(c, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : c[t] = s;
6
- var S = (c, t, s) => H(c, typeof t != "symbol" ? t + "" : t, s), j = (c, t, s) => t.has(c) || z("Cannot " + s);
7
- var A = (c, t, s) => t.has(c) ? z("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(c) : t.set(c, s);
8
- var n = (c, t, s) => (j(c, t, "access private method"), s);
9
- var r, E, I, d, P, f, W, C, T, B;
10
- const l = class l {
11
- constructor({
12
- element: t,
13
- x: s = null,
14
- y: e = null,
15
- speed: h = 0.01,
16
- seed: o = 0,
17
- lerpSpeed: i = 0.1,
18
- preserveBaseTranslation: a = !1
19
- // <-- si querés mantener la traslación base
20
- }) {
21
- A(this, f);
22
- S(this, "animate", () => {
23
- var t, s, e, h, o, i, a, m, g, p, u, R;
24
- if (this.lerpFactor !== this.targetLerpFactor && (this.lerpFactor = n(this, f, C).call(this, this.lerpFactor, this.targetLerpFactor, this.lerpSpeed), Math.abs(this.lerpFactor - this.targetLerpFactor) < 1e-3 && (this.lerpFactor = this.targetLerpFactor)), this.lerpFactor > 0) {
25
- this.time += this.speed * this.lerpFactor;
26
- const x = this.noise.perlin2(this.time, 0), b = this.noise.perlin2(this.time, 100);
27
- if (this.el) {
28
- let F, y, v, L;
29
- if (this.hasPercentages) {
30
- const Y = this.el.parentElement || document.body, $ = Y.clientWidth, M = Y.clientHeight;
31
- this.xRange && (F = n(t = l, r, d).call(t, this.xRange.min) ? n(s = l, r, P).call(s, this.xRange.min, $) : this.xRange.min, y = n(e = l, r, d).call(e, this.xRange.max) ? n(h = l, r, P).call(h, this.xRange.max, $) : this.xRange.max), this.yRange && (v = n(o = l, r, d).call(o, this.yRange.min) ? n(i = l, r, P).call(i, this.yRange.min, M) : this.yRange.min, L = n(a = l, r, d).call(a, this.yRange.max) ? n(m = l, r, P).call(m, this.yRange.max, M) : this.yRange.max);
32
- } else
33
- F = (g = this.xRange) == null ? void 0 : g.min, y = (p = this.xRange) == null ? void 0 : p.max, v = (u = this.yRange) == null ? void 0 : u.min, L = (R = this.yRange) == null ? void 0 : R.max;
34
- const X = this.xRange ? n(this, f, T).call(this, x, -1, 1, F, y) : 0, w = this.yRange ? n(this, f, T).call(this, b, -1, 1, v, L) : 0;
35
- this.lastX = X, this.lastY = w, this.el.style.transform = `translate3d(${X}px, ${w}px, 0) ${this.baseTransform}`.trim();
36
- } else {
37
- const F = this.xRange ? n(this, f, T).call(this, x, -1, 1, this.xRange.min, this.xRange.max) : 0, y = this.yRange ? n(this, f, T).call(this, b, -1, 1, this.yRange.min, this.yRange.max) : 0;
38
- this.lastX = F, this.lastY = y;
39
- }
40
- }
41
- (this.lerpFactor > 0 || this.targetLerpFactor > 0) && (this.raf = requestAnimationFrame(this.animate));
42
- });
43
- var m, g, p, u;
44
- if (this.el = t, this.xRange = s, this.yRange = e, this.speed = h, this.time = o, this.isPlaying = !0, this.lerpFactor = 1, this.lerpSpeed = i, this.targetLerpFactor = 1, this.lastX = 0, this.lastY = 0, this.preserveBaseTranslation = a, this.hasPercentages = !!(s && (n(m = l, r, d).call(m, s.min) || n(g = l, r, d).call(g, s.max)) || e && (n(p = l, r, d).call(p, e.min) || n(u = l, r, d).call(u, e.max))), t) {
45
- const R = window.getComputedStyle(t);
46
- R.position === "static" && (t.style.position = "relative"), this.originalInlineTransform = t.style.transform || "", this.baseTransform = n(this, f, B).call(this, R.transform, this.preserveBaseTranslation), this.hasPercentages && (this.handleResize = this.handleResize.bind(this), window.addEventListener("resize", this.handleResize));
47
- } else
48
- this.originalInlineTransform = "", this.baseTransform = "";
49
- this.animate = this.animate.bind(this), this.init(o);
50
- }
51
- init(t) {
52
- var s;
53
- this.noise = n(this, f, W).call(this, n(s = l, r, I).call(s, t)), this.isPlaying = !0, this.lerpFactor = 1, this.targetLerpFactor = 1, this.raf = requestAnimationFrame(this.animate);
54
- }
55
- // Permite refrescar el transform base si cambian clases/estilos en runtime
56
- refreshBaseTransform(t = this.preserveBaseTranslation) {
57
- if (!this.el) return;
58
- const s = window.getComputedStyle(this.el);
59
- this.baseTransform = n(this, f, B).call(this, s.transform, t);
60
- }
61
- // Handle window resize for percentage-based values
62
- handleResize() {
63
- }
64
- pause() {
65
- this.isPlaying && (this.targetLerpFactor = 0, this.isPlaying = !1);
66
- }
67
- play() {
68
- this.isPlaying || (this.targetLerpFactor = 1, this.isPlaying = !0, this.lerpFactor === 0 && (this.raf = requestAnimationFrame(this.animate)));
69
- }
70
- destroy() {
71
- cancelAnimationFrame(this.raf), this.el && (this.el.style.transform = this.originalInlineTransform || ""), this.hasPercentages && window.removeEventListener("resize", this.handleResize);
72
- }
73
- };
74
- r = new WeakSet(), E = function(t) {
75
- return function() {
76
- let s = t += 1831565813;
77
- return s = Math.imul(s ^ s >>> 15, s | 1), s ^= s + Math.imul(s ^ s >>> 7, s | 61), ((s ^ s >>> 14) >>> 0) / 4294967296;
78
- };
79
- }, I = function(t = 0) {
80
- var h;
81
- const s = Array.from({ length: 256 }, (o, i) => i), e = n(h = l, r, E).call(h, t);
82
- for (let o = 255; o > 0; o--) {
83
- const i = Math.floor(e() * (o + 1));
84
- [s[o], s[i]] = [s[i], s[o]];
85
- }
86
- return s.concat(s);
87
- }, d = function(t) {
88
- return typeof t == "string" && t.endsWith("%");
89
- }, P = function(t, s) {
90
- var h;
91
- return n(h = l, r, d).call(h, t) ? parseFloat(t) / 100 * s : t;
92
- }, f = new WeakSet(), W = function(t) {
93
- const s = (i) => i * i * i * (i * (i * 6 - 15) + 10), e = (i, a, m) => a + i * (m - a), h = (i, a, m) => {
94
- const g = i & 15, p = g < 8 ? a : m, u = g < 4 ? m : g === 12 || g === 14 ? a : 0;
95
- return (g & 1 ? -p : p) + (g & 2 ? -u : u);
96
- }, o = (i, a) => i & 1 ? -a : a;
97
- return {
98
- // Original 1D Perlin noise function
99
- perlin1(i) {
100
- const a = Math.floor(i) & 255;
101
- i -= Math.floor(i);
102
- const m = s(i);
103
- return e(m, o(t[a], i), o(t[a + 1], i - 1));
104
- },
105
- // New 2D Perlin noise function
106
- perlin2(i, a) {
107
- const m = Math.floor(i) & 255, g = Math.floor(a) & 255;
108
- i -= Math.floor(i), a -= Math.floor(a);
109
- const p = s(i), u = s(a), R = t[m] + g, x = t[m + 1] + g, b = t[R], F = t[R + 1], y = t[x], v = t[x + 1];
110
- return e(
111
- u,
112
- e(p, h(t[b], i, a), h(t[y], i - 1, a)),
113
- e(p, h(t[F], i, a - 1), h(t[v], i - 1, a - 1))
114
- );
115
- }
116
- };
117
- }, C = function(t, s, e) {
118
- return t + e * (s - t);
119
- }, T = function(t, s, e, h, o) {
120
- return (t - s) * (o - h) / (e - s) + h;
121
- }, // Quita o preserva la traslación del transform base en 2D según flag
122
- B = function(t, s = !1) {
123
- if (!t || t === "none") return "";
124
- try {
125
- const e = new DOMMatrixReadOnly(t);
126
- if (e.is2D) {
127
- const h = s ? e.e : 0, o = s ? e.f : 0;
128
- return `matrix(${e.a}, ${e.b}, ${e.c}, ${e.d}, ${h}, ${o})`;
129
- } else
130
- return t;
131
- } catch {
132
- return t;
133
- }
134
- }, A(l, r);
135
- let q = l;
136
- export {
137
- q as default
138
- };
@@ -1 +0,0 @@
1
- (function(h,s){typeof exports=="object"&&typeof module<"u"?module.exports=s():typeof define=="function"&&define.amd?define(s):(h=typeof globalThis<"u"?globalThis:h||self,h.PerlinDOM=s())})(this,function(){"use strict";var j=Object.defineProperty;var S=h=>{throw TypeError(h)};var C=(h,s,u)=>s in h?j(h,s,{enumerable:!0,configurable:!0,writable:!0,value:u}):h[s]=u;var q=(h,s,u)=>C(h,typeof s!="symbol"?s+"":s,u),H=(h,s,u)=>s.has(h)||S("Cannot "+u);var B=(h,s,u)=>s.has(h)?S("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(h):s.set(h,u);var r=(h,s,u)=>(H(h,s,"access private method"),u);var s,D,E,R,P,g,I,W,b,X;const c=class c{constructor({element:t,x:i=null,y:n=null,speed:o=.01,seed:l=0,lerpSpeed:e=.1,preserveBaseTranslation:a=!1}){B(this,g);q(this,"animate",()=>{var t,i,n,o,l,e,a,m,f,p,d,y;if(this.lerpFactor!==this.targetLerpFactor&&(this.lerpFactor=r(this,g,W).call(this,this.lerpFactor,this.targetLerpFactor,this.lerpSpeed),Math.abs(this.lerpFactor-this.targetLerpFactor)<.001&&(this.lerpFactor=this.targetLerpFactor)),this.lerpFactor>0){this.time+=this.speed*this.lerpFactor;const T=this.noise.perlin2(this.time,0),L=this.noise.perlin2(this.time,100);if(this.el){let F,x,v,A;if(this.hasPercentages){const Y=this.el.parentElement||document.body,$=Y.clientWidth,z=Y.clientHeight;this.xRange&&(F=r(t=c,s,R).call(t,this.xRange.min)?r(i=c,s,P).call(i,this.xRange.min,$):this.xRange.min,x=r(n=c,s,R).call(n,this.xRange.max)?r(o=c,s,P).call(o,this.xRange.max,$):this.xRange.max),this.yRange&&(v=r(l=c,s,R).call(l,this.yRange.min)?r(e=c,s,P).call(e,this.yRange.min,z):this.yRange.min,A=r(a=c,s,R).call(a,this.yRange.max)?r(m=c,s,P).call(m,this.yRange.max,z):this.yRange.max)}else F=(f=this.xRange)==null?void 0:f.min,x=(p=this.xRange)==null?void 0:p.max,v=(d=this.yRange)==null?void 0:d.min,A=(y=this.yRange)==null?void 0:y.max;const w=this.xRange?r(this,g,b).call(this,T,-1,1,F,x):0,M=this.yRange?r(this,g,b).call(this,L,-1,1,v,A):0;this.lastX=w,this.lastY=M,this.el.style.transform=`translate3d(${w}px, ${M}px, 0) ${this.baseTransform}`.trim()}else{const F=this.xRange?r(this,g,b).call(this,T,-1,1,this.xRange.min,this.xRange.max):0,x=this.yRange?r(this,g,b).call(this,L,-1,1,this.yRange.min,this.yRange.max):0;this.lastX=F,this.lastY=x}}(this.lerpFactor>0||this.targetLerpFactor>0)&&(this.raf=requestAnimationFrame(this.animate))});var m,f,p,d;if(this.el=t,this.xRange=i,this.yRange=n,this.speed=o,this.time=l,this.isPlaying=!0,this.lerpFactor=1,this.lerpSpeed=e,this.targetLerpFactor=1,this.lastX=0,this.lastY=0,this.preserveBaseTranslation=a,this.hasPercentages=!!(i&&(r(m=c,s,R).call(m,i.min)||r(f=c,s,R).call(f,i.max))||n&&(r(p=c,s,R).call(p,n.min)||r(d=c,s,R).call(d,n.max))),t){const y=window.getComputedStyle(t);y.position==="static"&&(t.style.position="relative"),this.originalInlineTransform=t.style.transform||"",this.baseTransform=r(this,g,X).call(this,y.transform,this.preserveBaseTranslation),this.hasPercentages&&(this.handleResize=this.handleResize.bind(this),window.addEventListener("resize",this.handleResize))}else this.originalInlineTransform="",this.baseTransform="";this.animate=this.animate.bind(this),this.init(l)}init(t){var i;this.noise=r(this,g,I).call(this,r(i=c,s,E).call(i,t)),this.isPlaying=!0,this.lerpFactor=1,this.targetLerpFactor=1,this.raf=requestAnimationFrame(this.animate)}refreshBaseTransform(t=this.preserveBaseTranslation){if(!this.el)return;const i=window.getComputedStyle(this.el);this.baseTransform=r(this,g,X).call(this,i.transform,t)}handleResize(){}pause(){this.isPlaying&&(this.targetLerpFactor=0,this.isPlaying=!1)}play(){this.isPlaying||(this.targetLerpFactor=1,this.isPlaying=!0,this.lerpFactor===0&&(this.raf=requestAnimationFrame(this.animate)))}destroy(){cancelAnimationFrame(this.raf),this.el&&(this.el.style.transform=this.originalInlineTransform||""),this.hasPercentages&&window.removeEventListener("resize",this.handleResize)}};s=new WeakSet,D=function(t){return function(){let i=t+=1831565813;return i=Math.imul(i^i>>>15,i|1),i^=i+Math.imul(i^i>>>7,i|61),((i^i>>>14)>>>0)/4294967296}},E=function(t=0){var o;const i=Array.from({length:256},(l,e)=>e),n=r(o=c,s,D).call(o,t);for(let l=255;l>0;l--){const e=Math.floor(n()*(l+1));[i[l],i[e]]=[i[e],i[l]]}return i.concat(i)},R=function(t){return typeof t=="string"&&t.endsWith("%")},P=function(t,i){var o;return r(o=c,s,R).call(o,t)?parseFloat(t)/100*i:t},g=new WeakSet,I=function(t){const i=e=>e*e*e*(e*(e*6-15)+10),n=(e,a,m)=>a+e*(m-a),o=(e,a,m)=>{const f=e&15,p=f<8?a:m,d=f<4?m:f===12||f===14?a:0;return(f&1?-p:p)+(f&2?-d:d)},l=(e,a)=>e&1?-a:a;return{perlin1(e){const a=Math.floor(e)&255;e-=Math.floor(e);const m=i(e);return n(m,l(t[a],e),l(t[a+1],e-1))},perlin2(e,a){const m=Math.floor(e)&255,f=Math.floor(a)&255;e-=Math.floor(e),a-=Math.floor(a);const p=i(e),d=i(a),y=t[m]+f,T=t[m+1]+f,L=t[y],F=t[y+1],x=t[T],v=t[T+1];return n(d,n(p,o(t[L],e,a),o(t[x],e-1,a)),n(p,o(t[F],e,a-1),o(t[v],e-1,a-1)))}}},W=function(t,i,n){return t+n*(i-t)},b=function(t,i,n,o,l){return(t-i)*(l-o)/(n-i)+o},X=function(t,i=!1){if(!t||t==="none")return"";try{const n=new DOMMatrixReadOnly(t);if(n.is2D){const o=i?n.e:0,l=i?n.f:0;return`matrix(${n.a}, ${n.b}, ${n.c}, ${n.d}, ${o}, ${l})`}else return t}catch{return t}},B(c,s);let h=c;return h});
@@ -1,391 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>PerlinDOM Examples</title>
7
- <style>
8
- body {
9
- font-family: 'Arial', sans-serif;
10
- line-height: 1.6;
11
- color: #333;
12
- max-width: 1200px;
13
- margin: 0 auto;
14
- padding: 20px;
15
- }
16
-
17
- h1, h2 {
18
- color: #2c3e50;
19
- }
20
-
21
- .example-container {
22
- margin-bottom: 40px;
23
- border: 1px solid #ddd;
24
- border-radius: 8px;
25
- padding: 20px;
26
- position: relative;
27
- overflow: hidden;
28
- height: 300px;
29
- background-color: #f9f9f9;
30
- }
31
-
32
- .code-block {
33
- background-color: #f5f5f5;
34
- padding: 15px;
35
- border-radius: 5px;
36
- overflow-x: auto;
37
- margin-bottom: 20px;
38
- font-family: monospace;
39
- font-size: 14px;
40
- }
41
-
42
- /* Example 1: Basic Animation */
43
- .basic-element {
44
- width: 80px;
45
- height: 80px;
46
- background-color: #3498db;
47
- border-radius: 50%;
48
- position: absolute;
49
- left: 50%;
50
- top: 50%;
51
- transform: translate(-50%, -50%);
52
- filter: blur(5px);
53
- }
54
-
55
- /* Example 2: Horizontal Only */
56
- .horizontal-element {
57
- width: 60px;
58
- height: 60px;
59
- background-color: #e74c3c;
60
- border-radius: 10px;
61
- position: absolute;
62
- left: 50%;
63
- top: 50%;
64
- transform: translate(-50%, -50%);
65
- }
66
-
67
- /* Example 3: Multiple Elements */
68
- .particle {
69
- width: 30px;
70
- height: 30px;
71
- background-color: #2ecc71;
72
- border-radius: 50%;
73
- position: absolute;
74
- opacity: 0.7;
75
- }
76
-
77
- /* Example 4: Background Effect */
78
- .bg-container {
79
- background-color: #34495e;
80
- position: relative;
81
- }
82
-
83
- .bg-element {
84
- position: absolute;
85
- border-radius: 50%;
86
- background-color: rgba(255, 255, 255, 0.1);
87
- }
88
-
89
- .bg-element-1 {
90
- width: 100px;
91
- height: 100px;
92
- left: 20%;
93
- top: 30%;
94
- }
95
-
96
- .bg-element-2 {
97
- width: 150px;
98
- height: 150px;
99
- left: 60%;
100
- top: 50%;
101
- }
102
-
103
- .bg-element-3 {
104
- width: 80px;
105
- height: 80px;
106
- left: 40%;
107
- top: 70%;
108
- }
109
-
110
- .content {
111
- position: relative;
112
- z-index: 10;
113
- color: white;
114
- text-align: center;
115
- padding-top: 120px;
116
- }
117
-
118
- /* Example 5: Interactive Element */
119
- .interactive-container {
120
- display: flex;
121
- justify-content: space-between;
122
- }
123
-
124
- .controls {
125
- width: 40%;
126
- }
127
-
128
- .preview {
129
- width: 55%;
130
- height: 200px;
131
- border: 1px solid #ddd;
132
- border-radius: 5px;
133
- position: relative;
134
- overflow: hidden;
135
- }
136
-
137
- .interactive-element {
138
- width: 50px;
139
- height: 50px;
140
- background-color: #9b59b6;
141
- border-radius: 50%;
142
- position: absolute;
143
- left: 50%;
144
- top: 50%;
145
- transform: translate(-50%, -50%);
146
- }
147
-
148
- .control-group {
149
- margin-bottom: 15px;
150
- }
151
-
152
- label {
153
- display: block;
154
- margin-bottom: 5px;
155
- font-weight: bold;
156
- }
157
-
158
- input[type="range"] {
159
- width: 100%;
160
- }
161
-
162
- .value-display {
163
- font-size: 12px;
164
- color: #666;
165
- }
166
- </style>
167
- </head>
168
- <body>
169
- <h1>PerlinDOM Examples</h1>
170
- <p>This page demonstrates various ways to use the PerlinDOM library for creating smooth, organic animations.</p>
171
-
172
- <div style="background-color: #e3f2fd; padding: 15px; border-radius: 5px; margin-bottom: 20px; border-left: 5px solid #2196f3;">
173
- <h3 style="margin-top: 0; color: #0d47a1;">New Feature: Percentage-Based Values</h3>
174
- <p>PerlinDOM now supports percentage-based values for responsive animations that adapt to container size.</p>
175
- <p><a href="../src/percentage-example.html" style="color: #1976d2; font-weight: bold;">View Percentage-Based Examples →</a></p>
176
- </div>
177
-
178
- <!-- Example 1: Basic Animation -->
179
- <h2>1. Basic Animation</h2>
180
- <div class="code-block">
181
- const basicAnimation = new PerlinDOM({<br>
182
- &nbsp;&nbsp;element: document.querySelector('.basic-element'),<br>
183
- &nbsp;&nbsp;x: { min: -50, max: 50 },<br>
184
- &nbsp;&nbsp;y: { min: -50, max: 50 },<br>
185
- &nbsp;&nbsp;speed: 0.01,<br>
186
- &nbsp;&nbsp;seed: 123<br>
187
- });
188
- </div>
189
- <div class="example-container">
190
- <div class="basic-element"></div>
191
- </div>
192
-
193
- <!-- Example 2: Horizontal Only -->
194
- <h2>2. Horizontal-Only Movement</h2>
195
- <div class="code-block">
196
- const horizontalAnimation = new PerlinDOM({<br>
197
- &nbsp;&nbsp;element: document.querySelector('.horizontal-element'),<br>
198
- &nbsp;&nbsp;x: { min: -100, max: 100 },<br>
199
- &nbsp;&nbsp;y: null, // No vertical movement<br>
200
- &nbsp;&nbsp;speed: 0.02<br>
201
- });
202
- </div>
203
- <div class="example-container">
204
- <div class="horizontal-element"></div>
205
- </div>
206
-
207
- <!-- Example 3: Multiple Elements -->
208
- <h2>3. Multiple Elements with Different Seeds</h2>
209
- <div class="code-block">
210
- document.querySelectorAll('.particle').forEach((el, index) => {<br>
211
- &nbsp;&nbsp;new PerlinDOM({<br>
212
- &nbsp;&nbsp;&nbsp;&nbsp;element: el,<br>
213
- &nbsp;&nbsp;&nbsp;&nbsp;x: { min: -100, max: 100 },<br>
214
- &nbsp;&nbsp;&nbsp;&nbsp;y: { min: -100, max: 100 },<br>
215
- &nbsp;&nbsp;&nbsp;&nbsp;speed: 0.01,<br>
216
- &nbsp;&nbsp;&nbsp;&nbsp;seed: index * 100 // Different seed for each element<br>
217
- &nbsp;&nbsp;});<br>
218
- });
219
- </div>
220
- <div class="example-container">
221
- <div class="particle" style="left: 30%; top: 30%"></div>
222
- <div class="particle" style="left: 50%; top: 50%"></div>
223
- <div class="particle" style="left: 70%; top: 70%"></div>
224
- <div class="particle" style="left: 30%; top: 70%"></div>
225
- <div class="particle" style="left: 70%; top: 30%"></div>
226
- </div>
227
-
228
- <!-- Example 4: Background Effect -->
229
- <h2>4. Creating a Background Effect</h2>
230
- <div class="code-block">
231
- document.querySelectorAll('.bg-element').forEach(el => {<br>
232
- &nbsp;&nbsp;new PerlinDOM({<br>
233
- &nbsp;&nbsp;&nbsp;&nbsp;element: el,<br>
234
- &nbsp;&nbsp;&nbsp;&nbsp;x: { min: -10, max: 10 },<br>
235
- &nbsp;&nbsp;&nbsp;&nbsp;y: { min: -10, max: 10 },<br>
236
- &nbsp;&nbsp;&nbsp;&nbsp;speed: 0.002, // Very slow movement<br>
237
- &nbsp;&nbsp;&nbsp;&nbsp;seed: Math.random() * 2000<br>
238
- &nbsp;&nbsp;});<br>
239
- });
240
- </div>
241
- <div class="example-container bg-container">
242
- <div class="bg-element bg-element-1"></div>
243
- <div class="bg-element bg-element-2"></div>
244
- <div class="bg-element bg-element-3"></div>
245
- <div class="content">
246
- <h3>Subtle Background Animation</h3>
247
- <p>Perfect for creating depth in UI elements</p>
248
- </div>
249
- </div>
250
-
251
- <!-- Example 5: Interactive Controls -->
252
- <h2>5. Interactive Controls</h2>
253
- <div class="code-block">
254
- // Create the animation with initial settings<br>
255
- const interactiveAnimation = new PerlinDOM({<br>
256
- &nbsp;&nbsp;element: document.querySelector('.interactive-element'),<br>
257
- &nbsp;&nbsp;x: { min: -50, max: 50 },<br>
258
- &nbsp;&nbsp;y: { min: -50, max: 50 },<br>
259
- &nbsp;&nbsp;speed: 0.01,<br>
260
- &nbsp;&nbsp;seed: 0<br>
261
- });<br><br>
262
-
263
- // Update settings based on user input<br>
264
- speedControl.addEventListener('input', () => {<br>
265
- &nbsp;&nbsp;// Stop current animation<br>
266
- &nbsp;&nbsp;interactiveAnimation.destroy();<br>
267
- &nbsp;&nbsp;<br>
268
- &nbsp;&nbsp;// Reinitialize with new settings<br>
269
- &nbsp;&nbsp;interactiveAnimation.speed = parseFloat(speedControl.value);<br>
270
- &nbsp;&nbsp;interactiveAnimation.init(seedControl.value);<br>
271
- });
272
- </div>
273
- <div class="example-container">
274
- <div class="interactive-container">
275
- <div class="controls">
276
- <div class="control-group">
277
- <label for="x-range">X Range:</label>
278
- <input type="range" id="x-range" min="0" max="100" value="50">
279
- <div class="value-display">-50 to 50</div>
280
- </div>
281
-
282
- <div class="control-group">
283
- <label for="y-range">Y Range:</label>
284
- <input type="range" id="y-range" min="0" max="100" value="50">
285
- <div class="value-display">-50 to 50</div>
286
- </div>
287
-
288
- <div class="control-group">
289
- <label for="speed">Speed:</label>
290
- <input type="range" id="speed" min="0.001" max="0.05" step="0.001" value="0.01">
291
- <div class="value-display">0.01</div>
292
- </div>
293
-
294
- <div class="control-group">
295
- <label for="seed">Seed:</label>
296
- <input type="range" id="seed" min="0" max="1000" step="1" value="0">
297
- <div class="value-display">0</div>
298
- </div>
299
- </div>
300
-
301
- <div class="preview">
302
- <div class="interactive-element"></div>
303
- </div>
304
- </div>
305
- </div>
306
-
307
- <!-- Load PerlinDOM library -->
308
- <script type="module">
309
- import PerlinDOM from '../dist/perlindom.es.js';
310
-
311
- // Example 1: Basic Animation
312
- const basicAnimation = new PerlinDOM({
313
- element: document.querySelector('.basic-element'),
314
- x: { min: -50, max: 50 },
315
- y: { min: -50, max: 50 },
316
- speed: 0.01,
317
- seed: 123
318
- });
319
-
320
- // Example 2: Horizontal Only
321
- const horizontalAnimation = new PerlinDOM({
322
- element: document.querySelector('.horizontal-element'),
323
- x: { min: -100, max: 100 },
324
- y: null, // No vertical movement
325
- speed: 0.02
326
- });
327
-
328
- // Example 3: Multiple Elements
329
- document.querySelectorAll('.particle').forEach((el, index) => {
330
- new PerlinDOM({
331
- element: el,
332
- x: { min: -100, max: 100 },
333
- y: { min: -100, max: 100 },
334
- speed: 0.01,
335
- seed: index * 100 // Different seed for each element
336
- });
337
- });
338
-
339
- // Example 4: Background Effect
340
- document.querySelectorAll('.bg-element').forEach(el => {
341
- new PerlinDOM({
342
- element: el,
343
- x: { min: -10, max: 10 },
344
- y: { min: -10, max: 10 },
345
- speed: 0.002, // Very slow movement
346
- seed: Math.random() * 2000
347
- });
348
- });
349
-
350
- // Example 5: Interactive Controls
351
- let interactiveAnimation;
352
-
353
- function initInteractiveAnimation() {
354
- // Destroy previous instance if it exists
355
- if (interactiveAnimation) {
356
- interactiveAnimation.destroy();
357
- }
358
-
359
- // Get current values
360
- const xRange = parseInt(document.getElementById('x-range').value);
361
- const yRange = parseInt(document.getElementById('y-range').value);
362
- const speed = parseFloat(document.getElementById('speed').value);
363
- const seed = parseInt(document.getElementById('seed').value);
364
-
365
- // Create new instance
366
- interactiveAnimation = new PerlinDOM({
367
- element: document.querySelector('.interactive-element'),
368
- x: { min: -xRange, max: xRange },
369
- y: { min: -yRange, max: yRange },
370
- speed: speed,
371
- seed: seed
372
- });
373
-
374
- // Update displays
375
- document.querySelector('#x-range + .value-display').textContent = `-${xRange} to ${xRange}`;
376
- document.querySelector('#y-range + .value-display').textContent = `-${yRange} to ${yRange}`;
377
- document.querySelector('#speed + .value-display').textContent = speed.toFixed(3);
378
- document.querySelector('#seed + .value-display').textContent = seed;
379
- }
380
-
381
- // Initialize
382
- initInteractiveAnimation();
383
-
384
- // Add event listeners
385
- document.getElementById('x-range').addEventListener('input', initInteractiveAnimation);
386
- document.getElementById('y-range').addEventListener('input', initInteractiveAnimation);
387
- document.getElementById('speed').addEventListener('input', initInteractiveAnimation);
388
- document.getElementById('seed').addEventListener('input', initInteractiveAnimation);
389
- </script>
390
- </body>
391
- </html>
package/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>