@andresclua/perlindom 0.0.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/dist/PerlinDOM.es.js +98 -0
- package/dist/PerlinDOM.umd.js +1 -0
- package/docs/examples.html +385 -0
- package/package.json +33 -0
- package/public/vite.svg +1 -0
- package/readme.md +271 -0
- package/src/examples.html +515 -0
- package/src/index.html +655 -0
- package/src/js/PerlinDom.js +215 -0
- package/src/js/PerlinSVG.js +190 -0
- package/src/js/animated-button.js +40 -0
- package/src/js/basic-examples.js +43 -0
- package/src/js/index.js +13 -0
- package/src/js/interactive-controls.js +43 -0
- package/src/js/pause-play.js +33 -0
- package/src/js/triangle-animation.js +48 -0
- package/src/scss/style.scss +20 -0
- package/vite.config.js +36 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var y = (r) => {
|
|
3
|
+
throw TypeError(r);
|
|
4
|
+
};
|
|
5
|
+
var $ = (r, t, i) => t in r ? S(r, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[t] = i;
|
|
6
|
+
var M = (r, t, i) => $(r, typeof t != "symbol" ? t + "" : t, i), j = (r, t, i) => t.has(r) || y("Cannot " + i);
|
|
7
|
+
var F = (r, t, i) => t.has(r) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, i);
|
|
8
|
+
var f = (r, t, i) => (j(r, t, "access private method"), i);
|
|
9
|
+
var g, X, R, c, Y, B, d;
|
|
10
|
+
const u = class u {
|
|
11
|
+
constructor({
|
|
12
|
+
element: t,
|
|
13
|
+
x: i = null,
|
|
14
|
+
y: a = null,
|
|
15
|
+
speed: n = 0.01,
|
|
16
|
+
seed: o = 0,
|
|
17
|
+
lerpSpeed: s = 0.1
|
|
18
|
+
}) {
|
|
19
|
+
F(this, c);
|
|
20
|
+
M(this, "animate", () => {
|
|
21
|
+
if (this.lerpFactor !== this.targetLerpFactor && (this.lerpFactor = f(this, c, B).call(this, this.lerpFactor, this.targetLerpFactor, this.lerpSpeed), Math.abs(this.lerpFactor - this.targetLerpFactor) < 1e-3 && (this.lerpFactor = this.targetLerpFactor)), this.lerpFactor > 0) {
|
|
22
|
+
this.time += this.speed * this.lerpFactor;
|
|
23
|
+
const t = this.noise.perlin2(this.time, 0), i = this.noise.perlin2(this.time, 100), a = this.xRange ? f(this, c, d).call(this, t, -1, 1, this.xRange.min, this.xRange.max) : 0, n = this.yRange ? f(this, c, d).call(this, i, -1, 1, this.yRange.min, this.yRange.max) : 0;
|
|
24
|
+
this.lastX = a, this.lastY = n, this.el && (this.el.style.left = `${this.initialX + a}px`, this.el.style.top = `${this.initialY + n}px`);
|
|
25
|
+
}
|
|
26
|
+
(this.lerpFactor > 0 || this.targetLerpFactor > 0) && (this.raf = requestAnimationFrame(this.animate));
|
|
27
|
+
});
|
|
28
|
+
this.el = t, this.xRange = i, this.yRange = a, this.speed = n, this.time = o, this.isPlaying = !0, this.lerpFactor = 1, this.lerpSpeed = s, this.targetLerpFactor = 1, this.lastX = 0, this.lastY = 0, t ? (this.initialX = t.offsetLeft, this.initialY = t.offsetTop) : (this.initialX = 0, this.initialY = 0), this.animate = this.animate.bind(this), this.init(o);
|
|
29
|
+
}
|
|
30
|
+
init(t) {
|
|
31
|
+
var i;
|
|
32
|
+
this.noise = f(this, c, Y).call(this, f(i = u, g, R).call(i, t)), this.isPlaying = !0, this.lerpFactor = 1, this.targetLerpFactor = 1, this.raf = requestAnimationFrame(this.animate), console.log("PerlinDOM initialized");
|
|
33
|
+
}
|
|
34
|
+
pause() {
|
|
35
|
+
this.isPlaying && (this.targetLerpFactor = 0, this.isPlaying = !1, console.log("PerlinDOM pausing..."));
|
|
36
|
+
}
|
|
37
|
+
play() {
|
|
38
|
+
this.isPlaying || (this.targetLerpFactor = 1, this.isPlaying = !0, this.lerpFactor === 0 && (this.raf = requestAnimationFrame(this.animate)), console.log("PerlinDOM playing..."));
|
|
39
|
+
}
|
|
40
|
+
destroy() {
|
|
41
|
+
cancelAnimationFrame(this.raf);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
g = new WeakSet(), X = function(t) {
|
|
45
|
+
return function() {
|
|
46
|
+
let i = t += 1831565813;
|
|
47
|
+
return i = Math.imul(i ^ i >>> 15, i | 1), i ^= i + Math.imul(i ^ i >>> 7, i | 61), ((i ^ i >>> 14) >>> 0) / 4294967296;
|
|
48
|
+
};
|
|
49
|
+
}, R = function(t = 0) {
|
|
50
|
+
var n;
|
|
51
|
+
const i = Array.from({ length: 256 }, (o, s) => s), a = f(n = u, g, X).call(n, t);
|
|
52
|
+
for (let o = 255; o > 0; o--) {
|
|
53
|
+
const s = Math.floor(a() * (o + 1));
|
|
54
|
+
[i[o], i[s]] = [i[s], i[o]];
|
|
55
|
+
}
|
|
56
|
+
return i.concat(i);
|
|
57
|
+
}, c = new WeakSet(), Y = function(t) {
|
|
58
|
+
const i = (s) => s * s * s * (s * (s * 6 - 15) + 10), a = (s, e, h) => e + s * (h - e), n = (s, e, h) => {
|
|
59
|
+
const l = s & 15, p = l < 8 ? e : h, m = l < 4 ? h : l === 12 || l === 14 ? e : 0;
|
|
60
|
+
return (l & 1 ? -p : p) + (l & 2 ? -m : m);
|
|
61
|
+
}, o = (s, e) => s & 1 ? -e : e;
|
|
62
|
+
return {
|
|
63
|
+
// Original 1D Perlin noise function
|
|
64
|
+
perlin1(s) {
|
|
65
|
+
const e = Math.floor(s) & 255;
|
|
66
|
+
s -= Math.floor(s);
|
|
67
|
+
const h = i(s);
|
|
68
|
+
return a(h, o(t[e], s), o(t[e + 1], s - 1));
|
|
69
|
+
},
|
|
70
|
+
// New 2D Perlin noise function
|
|
71
|
+
perlin2(s, e) {
|
|
72
|
+
const h = Math.floor(s) & 255, l = Math.floor(e) & 255;
|
|
73
|
+
s -= Math.floor(s), e -= Math.floor(e);
|
|
74
|
+
const p = i(s), m = i(e), A = t[h] + l, L = t[h + 1] + l, b = t[A], v = t[A + 1], q = t[L], D = t[L + 1];
|
|
75
|
+
return a(
|
|
76
|
+
m,
|
|
77
|
+
a(
|
|
78
|
+
p,
|
|
79
|
+
n(t[b], s, e),
|
|
80
|
+
n(t[q], s - 1, e)
|
|
81
|
+
),
|
|
82
|
+
a(
|
|
83
|
+
p,
|
|
84
|
+
n(t[v], s, e - 1),
|
|
85
|
+
n(t[D], s - 1, e - 1)
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, B = function(t, i, a) {
|
|
91
|
+
return t + a * (i - t);
|
|
92
|
+
}, d = function(t, i, a, n, o) {
|
|
93
|
+
return (t - i) * (o - n) / (a - i) + n;
|
|
94
|
+
}, F(u, g);
|
|
95
|
+
let P = u;
|
|
96
|
+
export {
|
|
97
|
+
P as default
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(r,e){typeof exports=="object"&&typeof module<"u"?module.exports=e():typeof define=="function"&&define.amd?define(e):(r=typeof globalThis<"u"?globalThis:r||self,r.PerlinDOM=e())})(this,function(){"use strict";var T=Object.defineProperty;var M=r=>{throw TypeError(r)};var j=(r,e,l)=>e in r?T(r,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):r[e]=l;var P=(r,e,l)=>j(r,typeof e!="symbol"?e+"":e,l),O=(r,e,l)=>e.has(r)||M("Cannot "+l);var d=(r,e,l)=>e.has(r)?M("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,l);var u=(r,e,l)=>(O(r,e,"access private method"),l);var e,X,R,c,Y,b,y;const g=class g{constructor({element:s,x:t=null,y:a=null,speed:o=.01,seed:h=0,lerpSpeed:i=.1}){d(this,c);P(this,"animate",()=>{if(this.lerpFactor!==this.targetLerpFactor&&(this.lerpFactor=u(this,c,b).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 s=this.noise.perlin2(this.time,0),t=this.noise.perlin2(this.time,100),a=this.xRange?u(this,c,y).call(this,s,-1,1,this.xRange.min,this.xRange.max):0,o=this.yRange?u(this,c,y).call(this,t,-1,1,this.yRange.min,this.yRange.max):0;this.lastX=a,this.lastY=o,this.el&&(this.el.style.left=`${this.initialX+a}px`,this.el.style.top=`${this.initialY+o}px`)}(this.lerpFactor>0||this.targetLerpFactor>0)&&(this.raf=requestAnimationFrame(this.animate))});this.el=s,this.xRange=t,this.yRange=a,this.speed=o,this.time=h,this.isPlaying=!0,this.lerpFactor=1,this.lerpSpeed=i,this.targetLerpFactor=1,this.lastX=0,this.lastY=0,s?(this.initialX=s.offsetLeft,this.initialY=s.offsetTop):(this.initialX=0,this.initialY=0),this.animate=this.animate.bind(this),this.init(h)}init(s){var t;this.noise=u(this,c,Y).call(this,u(t=g,e,R).call(t,s)),this.isPlaying=!0,this.lerpFactor=1,this.targetLerpFactor=1,this.raf=requestAnimationFrame(this.animate),console.log("PerlinDOM initialized")}pause(){this.isPlaying&&(this.targetLerpFactor=0,this.isPlaying=!1,console.log("PerlinDOM pausing..."))}play(){this.isPlaying||(this.targetLerpFactor=1,this.isPlaying=!0,this.lerpFactor===0&&(this.raf=requestAnimationFrame(this.animate)),console.log("PerlinDOM playing..."))}destroy(){cancelAnimationFrame(this.raf)}};e=new WeakSet,X=function(s){return function(){let t=s+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}},R=function(s=0){var o;const t=Array.from({length:256},(h,i)=>i),a=u(o=g,e,X).call(o,s);for(let h=255;h>0;h--){const i=Math.floor(a()*(h+1));[t[h],t[i]]=[t[i],t[h]]}return t.concat(t)},c=new WeakSet,Y=function(s){const t=i=>i*i*i*(i*(i*6-15)+10),a=(i,n,f)=>n+i*(f-n),o=(i,n,f)=>{const p=i&15,m=p<8?n:f,F=p<4?f:p===12||p===14?n:0;return(p&1?-m:m)+(p&2?-F:F)},h=(i,n)=>i&1?-n:n;return{perlin1(i){const n=Math.floor(i)&255;i-=Math.floor(i);const f=t(i);return a(f,h(s[n],i),h(s[n+1],i-1))},perlin2(i,n){const f=Math.floor(i)&255,p=Math.floor(n)&255;i-=Math.floor(i),n-=Math.floor(n);const m=t(i),F=t(n),A=s[f]+p,L=s[f+1]+p,B=s[A],v=s[A+1],D=s[L],q=s[L+1];return a(F,a(m,o(s[B],i,n),o(s[D],i-1,n)),a(m,o(s[v],i,n-1),o(s[q],i-1,n-1)))}}},b=function(s,t,a){return s+a*(t-s)},y=function(s,t,a,o,h){return(s-t)*(h-o)/(a-t)+o},d(g,e);let r=g;return r});
|
|
@@ -0,0 +1,385 @@
|
|
|
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
|
+
<!-- Example 1: Basic Animation -->
|
|
173
|
+
<h2>1. Basic Animation</h2>
|
|
174
|
+
<div class="code-block">
|
|
175
|
+
const basicAnimation = new PerlinDOM({<br>
|
|
176
|
+
element: document.querySelector('.basic-element'),<br>
|
|
177
|
+
x: { min: -50, max: 50 },<br>
|
|
178
|
+
y: { min: -50, max: 50 },<br>
|
|
179
|
+
speed: 0.01,<br>
|
|
180
|
+
seed: 123<br>
|
|
181
|
+
});
|
|
182
|
+
</div>
|
|
183
|
+
<div class="example-container">
|
|
184
|
+
<div class="basic-element"></div>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<!-- Example 2: Horizontal Only -->
|
|
188
|
+
<h2>2. Horizontal-Only Movement</h2>
|
|
189
|
+
<div class="code-block">
|
|
190
|
+
const horizontalAnimation = new PerlinDOM({<br>
|
|
191
|
+
element: document.querySelector('.horizontal-element'),<br>
|
|
192
|
+
x: { min: -100, max: 100 },<br>
|
|
193
|
+
y: null, // No vertical movement<br>
|
|
194
|
+
speed: 0.02<br>
|
|
195
|
+
});
|
|
196
|
+
</div>
|
|
197
|
+
<div class="example-container">
|
|
198
|
+
<div class="horizontal-element"></div>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<!-- Example 3: Multiple Elements -->
|
|
202
|
+
<h2>3. Multiple Elements with Different Seeds</h2>
|
|
203
|
+
<div class="code-block">
|
|
204
|
+
document.querySelectorAll('.particle').forEach((el, index) => {<br>
|
|
205
|
+
new PerlinDOM({<br>
|
|
206
|
+
element: el,<br>
|
|
207
|
+
x: { min: -100, max: 100 },<br>
|
|
208
|
+
y: { min: -100, max: 100 },<br>
|
|
209
|
+
speed: 0.01,<br>
|
|
210
|
+
seed: index * 100 // Different seed for each element<br>
|
|
211
|
+
});<br>
|
|
212
|
+
});
|
|
213
|
+
</div>
|
|
214
|
+
<div class="example-container">
|
|
215
|
+
<div class="particle" style="left: 30%; top: 30%"></div>
|
|
216
|
+
<div class="particle" style="left: 50%; top: 50%"></div>
|
|
217
|
+
<div class="particle" style="left: 70%; top: 70%"></div>
|
|
218
|
+
<div class="particle" style="left: 30%; top: 70%"></div>
|
|
219
|
+
<div class="particle" style="left: 70%; top: 30%"></div>
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<!-- Example 4: Background Effect -->
|
|
223
|
+
<h2>4. Creating a Background Effect</h2>
|
|
224
|
+
<div class="code-block">
|
|
225
|
+
document.querySelectorAll('.bg-element').forEach(el => {<br>
|
|
226
|
+
new PerlinDOM({<br>
|
|
227
|
+
element: el,<br>
|
|
228
|
+
x: { min: -10, max: 10 },<br>
|
|
229
|
+
y: { min: -10, max: 10 },<br>
|
|
230
|
+
speed: 0.002, // Very slow movement<br>
|
|
231
|
+
seed: Math.random() * 2000<br>
|
|
232
|
+
});<br>
|
|
233
|
+
});
|
|
234
|
+
</div>
|
|
235
|
+
<div class="example-container bg-container">
|
|
236
|
+
<div class="bg-element bg-element-1"></div>
|
|
237
|
+
<div class="bg-element bg-element-2"></div>
|
|
238
|
+
<div class="bg-element bg-element-3"></div>
|
|
239
|
+
<div class="content">
|
|
240
|
+
<h3>Subtle Background Animation</h3>
|
|
241
|
+
<p>Perfect for creating depth in UI elements</p>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
|
|
245
|
+
<!-- Example 5: Interactive Controls -->
|
|
246
|
+
<h2>5. Interactive Controls</h2>
|
|
247
|
+
<div class="code-block">
|
|
248
|
+
// Create the animation with initial settings<br>
|
|
249
|
+
const interactiveAnimation = new PerlinDOM({<br>
|
|
250
|
+
element: document.querySelector('.interactive-element'),<br>
|
|
251
|
+
x: { min: -50, max: 50 },<br>
|
|
252
|
+
y: { min: -50, max: 50 },<br>
|
|
253
|
+
speed: 0.01,<br>
|
|
254
|
+
seed: 0<br>
|
|
255
|
+
});<br><br>
|
|
256
|
+
|
|
257
|
+
// Update settings based on user input<br>
|
|
258
|
+
speedControl.addEventListener('input', () => {<br>
|
|
259
|
+
// Stop current animation<br>
|
|
260
|
+
interactiveAnimation.destroy();<br>
|
|
261
|
+
<br>
|
|
262
|
+
// Reinitialize with new settings<br>
|
|
263
|
+
interactiveAnimation.speed = parseFloat(speedControl.value);<br>
|
|
264
|
+
interactiveAnimation.init(seedControl.value);<br>
|
|
265
|
+
});
|
|
266
|
+
</div>
|
|
267
|
+
<div class="example-container">
|
|
268
|
+
<div class="interactive-container">
|
|
269
|
+
<div class="controls">
|
|
270
|
+
<div class="control-group">
|
|
271
|
+
<label for="x-range">X Range:</label>
|
|
272
|
+
<input type="range" id="x-range" min="0" max="100" value="50">
|
|
273
|
+
<div class="value-display">-50 to 50</div>
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
<div class="control-group">
|
|
277
|
+
<label for="y-range">Y Range:</label>
|
|
278
|
+
<input type="range" id="y-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="speed">Speed:</label>
|
|
284
|
+
<input type="range" id="speed" min="0.001" max="0.05" step="0.001" value="0.01">
|
|
285
|
+
<div class="value-display">0.01</div>
|
|
286
|
+
</div>
|
|
287
|
+
|
|
288
|
+
<div class="control-group">
|
|
289
|
+
<label for="seed">Seed:</label>
|
|
290
|
+
<input type="range" id="seed" min="0" max="1000" step="1" value="0">
|
|
291
|
+
<div class="value-display">0</div>
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
|
|
295
|
+
<div class="preview">
|
|
296
|
+
<div class="interactive-element"></div>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<!-- Load PerlinDOM library -->
|
|
302
|
+
<script type="module">
|
|
303
|
+
import PerlinDOM from '../dist/perlindom.es.js';
|
|
304
|
+
|
|
305
|
+
// Example 1: Basic Animation
|
|
306
|
+
const basicAnimation = new PerlinDOM({
|
|
307
|
+
element: document.querySelector('.basic-element'),
|
|
308
|
+
x: { min: -50, max: 50 },
|
|
309
|
+
y: { min: -50, max: 50 },
|
|
310
|
+
speed: 0.01,
|
|
311
|
+
seed: 123
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Example 2: Horizontal Only
|
|
315
|
+
const horizontalAnimation = new PerlinDOM({
|
|
316
|
+
element: document.querySelector('.horizontal-element'),
|
|
317
|
+
x: { min: -100, max: 100 },
|
|
318
|
+
y: null, // No vertical movement
|
|
319
|
+
speed: 0.02
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Example 3: Multiple Elements
|
|
323
|
+
document.querySelectorAll('.particle').forEach((el, index) => {
|
|
324
|
+
new PerlinDOM({
|
|
325
|
+
element: el,
|
|
326
|
+
x: { min: -100, max: 100 },
|
|
327
|
+
y: { min: -100, max: 100 },
|
|
328
|
+
speed: 0.01,
|
|
329
|
+
seed: index * 100 // Different seed for each element
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Example 4: Background Effect
|
|
334
|
+
document.querySelectorAll('.bg-element').forEach(el => {
|
|
335
|
+
new PerlinDOM({
|
|
336
|
+
element: el,
|
|
337
|
+
x: { min: -10, max: 10 },
|
|
338
|
+
y: { min: -10, max: 10 },
|
|
339
|
+
speed: 0.002, // Very slow movement
|
|
340
|
+
seed: Math.random() * 2000
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Example 5: Interactive Controls
|
|
345
|
+
let interactiveAnimation;
|
|
346
|
+
|
|
347
|
+
function initInteractiveAnimation() {
|
|
348
|
+
// Destroy previous instance if it exists
|
|
349
|
+
if (interactiveAnimation) {
|
|
350
|
+
interactiveAnimation.destroy();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Get current values
|
|
354
|
+
const xRange = parseInt(document.getElementById('x-range').value);
|
|
355
|
+
const yRange = parseInt(document.getElementById('y-range').value);
|
|
356
|
+
const speed = parseFloat(document.getElementById('speed').value);
|
|
357
|
+
const seed = parseInt(document.getElementById('seed').value);
|
|
358
|
+
|
|
359
|
+
// Create new instance
|
|
360
|
+
interactiveAnimation = new PerlinDOM({
|
|
361
|
+
element: document.querySelector('.interactive-element'),
|
|
362
|
+
x: { min: -xRange, max: xRange },
|
|
363
|
+
y: { min: -yRange, max: yRange },
|
|
364
|
+
speed: speed,
|
|
365
|
+
seed: seed
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// Update displays
|
|
369
|
+
document.querySelector('#x-range + .value-display').textContent = `-${xRange} to ${xRange}`;
|
|
370
|
+
document.querySelector('#y-range + .value-display').textContent = `-${yRange} to ${yRange}`;
|
|
371
|
+
document.querySelector('#speed + .value-display').textContent = speed.toFixed(3);
|
|
372
|
+
document.querySelector('#seed + .value-display').textContent = seed;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Initialize
|
|
376
|
+
initInteractiveAnimation();
|
|
377
|
+
|
|
378
|
+
// Add event listeners
|
|
379
|
+
document.getElementById('x-range').addEventListener('input', initInteractiveAnimation);
|
|
380
|
+
document.getElementById('y-range').addEventListener('input', initInteractiveAnimation);
|
|
381
|
+
document.getElementById('speed').addEventListener('input', initInteractiveAnimation);
|
|
382
|
+
document.getElementById('seed').addEventListener('input', initInteractiveAnimation);
|
|
383
|
+
</script>
|
|
384
|
+
</body>
|
|
385
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andresclua/perlindom",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "A lightweight JavaScript library for creating smooth, organic animations for DOM elements using Perlin noise",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/perlindom.umd.js",
|
|
8
|
+
"module": "./dist/perlindom.es.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/perlindom.es.js",
|
|
12
|
+
"require": "./dist/perlindom.umd.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"animation",
|
|
17
|
+
"perlin",
|
|
18
|
+
"noise",
|
|
19
|
+
"dom",
|
|
20
|
+
"javascript",
|
|
21
|
+
"motion",
|
|
22
|
+
"ui"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "vite",
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"preview": "vite preview"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"sass": "^1.80.6",
|
|
31
|
+
"vite": "^5.4.10"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/public/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
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>
|