@sarmal/core 0.12.0 → 0.13.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.
- package/dist/auto-init.cjs +114 -82
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.d.cts +1 -2
- package/dist/auto-init.d.ts +1 -2
- package/dist/auto-init.js +113 -81
- package/dist/auto-init.js.map +1 -1
- package/dist/curves/artemis2.cjs +10 -7
- package/dist/curves/artemis2.d.cts +1 -1
- package/dist/curves/artemis2.d.ts +1 -1
- package/dist/curves/artemis2.js +9 -6
- package/dist/curves/astroid.cjs +4 -4
- package/dist/curves/astroid.d.cts +1 -1
- package/dist/curves/astroid.d.ts +1 -1
- package/dist/curves/astroid.js +3 -3
- package/dist/curves/deltoid.cjs +4 -4
- package/dist/curves/deltoid.d.cts +1 -1
- package/dist/curves/deltoid.d.ts +1 -1
- package/dist/curves/deltoid.js +3 -3
- package/dist/curves/epicycloid3.cjs +4 -4
- package/dist/curves/epicycloid3.d.cts +1 -1
- package/dist/curves/epicycloid3.d.ts +1 -1
- package/dist/curves/epicycloid3.js +3 -3
- package/dist/curves/epitrochoid7.cjs +5 -5
- package/dist/curves/epitrochoid7.d.cts +1 -1
- package/dist/curves/epitrochoid7.d.ts +1 -1
- package/dist/curves/epitrochoid7.js +4 -4
- package/dist/curves/index.cjs +32 -28
- package/dist/curves/index.d.cts +21 -21
- package/dist/curves/index.d.ts +21 -21
- package/dist/curves/index.js +44 -28
- package/dist/curves/lame.cjs +6 -5
- package/dist/curves/lame.d.cts +1 -1
- package/dist/curves/lame.d.ts +1 -1
- package/dist/curves/lame.js +5 -4
- package/dist/curves/lissajous32.cjs +4 -4
- package/dist/curves/lissajous32.d.cts +1 -1
- package/dist/curves/lissajous32.d.ts +1 -1
- package/dist/curves/lissajous32.js +3 -3
- package/dist/curves/lissajous43.cjs +4 -4
- package/dist/curves/lissajous43.d.cts +1 -1
- package/dist/curves/lissajous43.d.ts +1 -1
- package/dist/curves/lissajous43.js +3 -3
- package/dist/curves/rose3.cjs +4 -4
- package/dist/curves/rose3.d.cts +1 -1
- package/dist/curves/rose3.d.ts +1 -1
- package/dist/curves/rose3.js +3 -3
- package/dist/curves/rose5.cjs +4 -4
- package/dist/curves/rose5.d.cts +1 -1
- package/dist/curves/rose5.d.ts +1 -1
- package/dist/curves/rose5.js +3 -3
- package/dist/index.cjs +135 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -34
- package/dist/index.d.ts +69 -34
- package/dist/index.js +152 -87
- package/dist/index.js.map +1 -1
- package/dist/types-BW0bpL1Z.d.cts +290 -0
- package/dist/types-BW0bpL1Z.d.ts +290 -0
- package/package.json +1 -1
- package/dist/types-BzgdhxE0.d.cts +0 -260
- package/dist/types-BzgdhxE0.d.ts +0 -260
package/dist/auto-init.js
CHANGED
|
@@ -61,13 +61,13 @@ function resolveCurve(curveDef) {
|
|
|
61
61
|
period,
|
|
62
62
|
speed,
|
|
63
63
|
skeleton: curveDef.skeleton,
|
|
64
|
-
skeletonFn: curveDef.skeletonFn
|
|
64
|
+
skeletonFn: curveDef.skeletonFn,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
function createEngine(curveDef, trailLength = 120) {
|
|
68
68
|
if (!Number.isFinite(trailLength) || trailLength <= 0) {
|
|
69
69
|
throw new RangeError(
|
|
70
|
-
`[sarmal] trailLength must be a positive finite number, got ${trailLength}
|
|
70
|
+
`[sarmal] trailLength must be a positive finite number, got ${trailLength}`,
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
let curve = resolveCurve(curveDef);
|
|
@@ -108,7 +108,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
108
108
|
actualTime += deltaTime;
|
|
109
109
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
110
110
|
const a = curve.fn(t, actualTime, EMPTY_PARAMS);
|
|
111
|
-
const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
|
|
111
|
+
const tB = _morphStrategy === "normalized" ? (t / curve.period) * morphCurveB.period : t;
|
|
112
112
|
const b = morphCurveB.fn(tB, actualTime, EMPTY_PARAMS);
|
|
113
113
|
trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
|
|
114
114
|
} else {
|
|
@@ -132,14 +132,14 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
132
132
|
trail.clear();
|
|
133
133
|
},
|
|
134
134
|
jump(newT, { clearTrail = false } = {}) {
|
|
135
|
-
t = (newT % curve.period + curve.period) % curve.period;
|
|
135
|
+
t = ((newT % curve.period) + curve.period) % curve.period;
|
|
136
136
|
if (clearTrail) {
|
|
137
137
|
trail.clear();
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
|
|
141
141
|
const advance = curve.speed * step;
|
|
142
|
-
const target = (targetT % curve.period + curve.period) % curve.period;
|
|
142
|
+
const target = ((targetT % curve.period) + curve.period) % curve.period;
|
|
143
143
|
const targetTime = target / curve.speed;
|
|
144
144
|
t = target;
|
|
145
145
|
actualTime = targetTime;
|
|
@@ -148,7 +148,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
148
148
|
const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
|
|
149
149
|
for (let i = count - 1; i >= 0; i--) {
|
|
150
150
|
const sampleT = target - i * advance;
|
|
151
|
-
const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
|
|
151
|
+
const wrappedT = ((sampleT % curve.period) + curve.period) % curve.period;
|
|
152
152
|
const time = targetTime - i * step;
|
|
153
153
|
const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
|
|
154
154
|
trail.push(point.x, point.y);
|
|
@@ -165,13 +165,16 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
165
165
|
...frozenB,
|
|
166
166
|
fn: (sampleT, time, params) => {
|
|
167
167
|
const a = frozenA.fn(sampleT, time, params);
|
|
168
|
-
const tB =
|
|
168
|
+
const tB =
|
|
169
|
+
frozenStrategy === "normalized"
|
|
170
|
+
? (sampleT / frozenA.period) * frozenB.period
|
|
171
|
+
: sampleT;
|
|
169
172
|
const b = frozenB.fn(tB, time, params);
|
|
170
173
|
return {
|
|
171
174
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
172
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
175
|
+
y: a.y + (b.y - a.y) * frozenAlpha,
|
|
173
176
|
};
|
|
174
|
-
}
|
|
177
|
+
},
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
180
|
_morphStrategy = strategy;
|
|
@@ -184,7 +187,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
184
187
|
completeMorph() {
|
|
185
188
|
if (morphCurveB !== null) {
|
|
186
189
|
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
187
|
-
t = t / curve.period * morphCurveB.period;
|
|
190
|
+
t = (t / curve.period) * morphCurveB.period;
|
|
188
191
|
}
|
|
189
192
|
curve = morphCurveB;
|
|
190
193
|
}
|
|
@@ -196,19 +199,22 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
196
199
|
const points = new Array(steps);
|
|
197
200
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
198
201
|
for (let i = 0; i < steps; i++) {
|
|
199
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
202
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
200
203
|
const a = sampleSkeleton(curve, sampleT);
|
|
201
|
-
const tB =
|
|
204
|
+
const tB =
|
|
205
|
+
_morphStrategy === "normalized"
|
|
206
|
+
? (sampleT / curve.period) * morphCurveB.period
|
|
207
|
+
: sampleT;
|
|
202
208
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
203
209
|
points[i] = {
|
|
204
210
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
205
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
211
|
+
y: a.y + (b.y - a.y) * _morphAlpha,
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
214
|
return points;
|
|
209
215
|
}
|
|
210
216
|
for (let i = 0; i < steps; i++) {
|
|
211
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
217
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
212
218
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
213
219
|
}
|
|
214
220
|
return points;
|
|
@@ -250,7 +256,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
250
256
|
_speedTransition.reject(new Error("Speed transition cancelled"));
|
|
251
257
|
_speedTransition = null;
|
|
252
258
|
}
|
|
253
|
-
}
|
|
259
|
+
},
|
|
254
260
|
};
|
|
255
261
|
}
|
|
256
262
|
|
|
@@ -258,6 +264,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
258
264
|
var DEFAULT_MORPH_DURATION_MS = 300;
|
|
259
265
|
var DEFAULT_SKELETON_OPACITY = 0.15;
|
|
260
266
|
var FIT_PADDING = 0.1;
|
|
267
|
+
var FIT_PADDING_MIN = 4;
|
|
261
268
|
var TRAIL_FADE_CURVE = 1.5;
|
|
262
269
|
var TRAIL_MAX_OPACITY = 0.88;
|
|
263
270
|
var TRAIL_MIN_WIDTH = 0.5;
|
|
@@ -312,13 +319,16 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
|
|
|
312
319
|
r1x: nx - n1.x * w1,
|
|
313
320
|
r1y: ny - n1.y * w1,
|
|
314
321
|
opacity,
|
|
315
|
-
progress
|
|
322
|
+
progress,
|
|
316
323
|
};
|
|
317
324
|
}
|
|
318
325
|
function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
319
326
|
if (pts.length === 0) return null;
|
|
320
327
|
const first = pts[0];
|
|
321
|
-
let minX = first.x,
|
|
328
|
+
let minX = first.x,
|
|
329
|
+
maxX = first.x,
|
|
330
|
+
minY = first.y,
|
|
331
|
+
maxY = first.y;
|
|
322
332
|
for (const p of pts) {
|
|
323
333
|
if (p.x < minX) {
|
|
324
334
|
minX = p.x;
|
|
@@ -337,16 +347,23 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
337
347
|
const h = maxY - minY;
|
|
338
348
|
if (w === 0 && h === 0) {
|
|
339
349
|
throw new Error(
|
|
340
|
-
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
350
|
+
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t.",
|
|
341
351
|
);
|
|
342
352
|
}
|
|
343
|
-
const
|
|
344
|
-
const
|
|
345
|
-
const
|
|
353
|
+
const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
|
|
354
|
+
const scaleYProportional = logicalHeight / (h * (1 + FIT_PADDING * 2));
|
|
355
|
+
const scaleXMinPadding = (logicalWidth - FIT_PADDING_MIN * 2) / w;
|
|
356
|
+
const scaleYMinPadding = (logicalHeight - FIT_PADDING_MIN * 2) / h;
|
|
357
|
+
const scale = Math.min(
|
|
358
|
+
scaleXProportional,
|
|
359
|
+
scaleYProportional,
|
|
360
|
+
scaleXMinPadding,
|
|
361
|
+
scaleYMinPadding,
|
|
362
|
+
);
|
|
346
363
|
return {
|
|
347
364
|
scale,
|
|
348
365
|
offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
|
|
349
|
-
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
366
|
+
offsetY: (logicalHeight - h * scale) / 2 - minY * scale,
|
|
350
367
|
};
|
|
351
368
|
}
|
|
352
369
|
function enginePassthroughs(engine) {
|
|
@@ -356,7 +373,7 @@ function enginePassthroughs(engine) {
|
|
|
356
373
|
setSpeed: engine.setSpeed,
|
|
357
374
|
getSpeed: engine.getSpeed,
|
|
358
375
|
resetSpeed: engine.resetSpeed,
|
|
359
|
-
setSpeedOver: engine.setSpeedOver
|
|
376
|
+
setSpeedOver: engine.setSpeedOver,
|
|
360
377
|
};
|
|
361
378
|
}
|
|
362
379
|
|
|
@@ -368,7 +385,7 @@ var GRADIENT = {
|
|
|
368
385
|
ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"],
|
|
369
386
|
ice: ["#1e3a8a", "#67e8f9"],
|
|
370
387
|
fire: ["#7f1d1d", "#fbbf24"],
|
|
371
|
-
forest: ["#14532d", "#86efac"]
|
|
388
|
+
forest: ["#14532d", "#86efac"],
|
|
372
389
|
};
|
|
373
390
|
var PRESETS = {
|
|
374
391
|
bard: GRADIENT.bard,
|
|
@@ -376,16 +393,16 @@ var PRESETS = {
|
|
|
376
393
|
ocean: GRADIENT.ocean,
|
|
377
394
|
ice: GRADIENT.ice,
|
|
378
395
|
fire: GRADIENT.fire,
|
|
379
|
-
forest: GRADIENT.forest
|
|
396
|
+
forest: GRADIENT.forest,
|
|
380
397
|
};
|
|
381
398
|
function hexToRgb(hex) {
|
|
382
399
|
const n = parseInt(hex.slice(1), 16);
|
|
383
|
-
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
400
|
+
return { r: n >> 16, g: (n >> 8) & 255, b: n & 255 };
|
|
384
401
|
}
|
|
385
402
|
var lerpRgb = (a, b, t) => ({
|
|
386
403
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
387
404
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
388
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
405
|
+
b: Math.round(a.b + (b.b - a.b) * t),
|
|
389
406
|
});
|
|
390
407
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
391
408
|
if (palette.length === 0) return { r: 255, g: 255, b: 255 };
|
|
@@ -405,7 +422,7 @@ function resolvePalette(palette, trailStyle) {
|
|
|
405
422
|
}
|
|
406
423
|
function hexToRgbComponents(hex) {
|
|
407
424
|
const n = parseInt(hex.slice(1), 16);
|
|
408
|
-
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
425
|
+
return `${n >> 16},${(n >> 8) & 255},${n & 255}`;
|
|
409
426
|
}
|
|
410
427
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
411
428
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -433,7 +450,7 @@ function createRenderer(options) {
|
|
|
433
450
|
const opts = {
|
|
434
451
|
skeletonColor: options.skeletonColor ?? DEFAULT_SKELETON_COLOR,
|
|
435
452
|
trailColor,
|
|
436
|
-
headColor: options.headColor ?? defaultHeadColor()
|
|
453
|
+
headColor: options.headColor ?? defaultHeadColor(),
|
|
437
454
|
};
|
|
438
455
|
const trailRgb = hexToRgbComponents(opts.trailColor);
|
|
439
456
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
@@ -534,7 +551,7 @@ function createRenderer(options) {
|
|
|
534
551
|
i,
|
|
535
552
|
trailCount,
|
|
536
553
|
toX,
|
|
537
|
-
toY
|
|
554
|
+
toY,
|
|
538
555
|
);
|
|
539
556
|
if (trailStyle === "default") {
|
|
540
557
|
ctx.fillStyle = `rgba(${trailRgb},${opacity})`;
|
|
@@ -558,16 +575,14 @@ function createRenderer(options) {
|
|
|
558
575
|
}
|
|
559
576
|
const x = head.x * scale + offsetX;
|
|
560
577
|
const y = head.y * scale + offsetY;
|
|
561
|
-
const r =
|
|
578
|
+
const r =
|
|
579
|
+
options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(logicalWidth, logicalHeight) / 160));
|
|
562
580
|
ctx.fillStyle = opts.headColor;
|
|
563
581
|
ctx.beginPath();
|
|
564
582
|
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
565
583
|
ctx.fill();
|
|
566
584
|
}
|
|
567
|
-
function
|
|
568
|
-
const now = performance.now();
|
|
569
|
-
const deltaTime = Math.min((now - lastTime) / 1e3, 1 / 30);
|
|
570
|
-
lastTime = now;
|
|
585
|
+
function renderFrame(deltaTime) {
|
|
571
586
|
if (trailStyle === "gradient-animated") {
|
|
572
587
|
gradientAnimTime += deltaTime * 1e3;
|
|
573
588
|
}
|
|
@@ -603,22 +618,33 @@ function createRenderer(options) {
|
|
|
603
618
|
drawSkeleton();
|
|
604
619
|
drawTrail();
|
|
605
620
|
drawHead();
|
|
606
|
-
|
|
621
|
+
}
|
|
622
|
+
function loop() {
|
|
623
|
+
const now = performance.now();
|
|
624
|
+
const deltaTime = Math.min((now - lastTime) / 1e3, 1 / 30);
|
|
625
|
+
lastTime = now;
|
|
626
|
+
renderFrame(deltaTime);
|
|
627
|
+
animationId = requestAnimationFrame(loop);
|
|
607
628
|
}
|
|
608
629
|
skeleton = engine.getSarmalSkeleton();
|
|
609
630
|
calculateBoundaries();
|
|
610
631
|
if (!engine.isLiveSkeleton) {
|
|
611
632
|
buildSkeletonCanvas();
|
|
612
633
|
}
|
|
613
|
-
|
|
614
|
-
|
|
634
|
+
if (options.initialT !== void 0) {
|
|
635
|
+
engine.seek(options.initialT);
|
|
636
|
+
}
|
|
637
|
+
renderFrame(0);
|
|
638
|
+
const shouldAutoStart = options.autoStart !== false;
|
|
639
|
+
const instance = {
|
|
640
|
+
play() {
|
|
615
641
|
if (animationId !== null) {
|
|
616
642
|
return;
|
|
617
643
|
}
|
|
618
644
|
lastTime = performance.now();
|
|
619
|
-
|
|
645
|
+
loop();
|
|
620
646
|
},
|
|
621
|
-
|
|
647
|
+
pause() {
|
|
622
648
|
if (animationId === null) {
|
|
623
649
|
return;
|
|
624
650
|
}
|
|
@@ -651,26 +677,33 @@ function createRenderer(options) {
|
|
|
651
677
|
return new Promise((resolve) => {
|
|
652
678
|
morphResolve = resolve;
|
|
653
679
|
});
|
|
654
|
-
}
|
|
680
|
+
},
|
|
655
681
|
};
|
|
682
|
+
if (shouldAutoStart) {
|
|
683
|
+
instance.play();
|
|
684
|
+
}
|
|
685
|
+
return instance;
|
|
656
686
|
}
|
|
657
687
|
|
|
658
688
|
// src/curves/artemis2.ts
|
|
659
689
|
var TWO_PI2 = Math.PI * 2;
|
|
660
690
|
function artemis2Fn(t, _time, _params) {
|
|
661
|
-
const a = 0.35,
|
|
662
|
-
|
|
691
|
+
const a = 0.35,
|
|
692
|
+
b = 0.15,
|
|
693
|
+
ox = 0.175;
|
|
694
|
+
const s = Math.sin(t),
|
|
695
|
+
c = Math.cos(t);
|
|
663
696
|
const denom = 1 + s * s;
|
|
664
697
|
return {
|
|
665
|
-
x: c * (1 + a * c) / denom - ox,
|
|
666
|
-
y: s * c * (1 + b * c) / denom
|
|
698
|
+
x: (c * (1 + a * c)) / denom - ox,
|
|
699
|
+
y: (s * c * (1 + b * c)) / denom,
|
|
667
700
|
};
|
|
668
701
|
}
|
|
669
702
|
var artemis2 = {
|
|
670
703
|
name: "Artemis II",
|
|
671
704
|
fn: artemis2Fn,
|
|
672
705
|
period: TWO_PI2,
|
|
673
|
-
speed: 0.7
|
|
706
|
+
speed: 0.7,
|
|
674
707
|
};
|
|
675
708
|
|
|
676
709
|
// src/curves/astroid.ts
|
|
@@ -680,14 +713,14 @@ function astroidFn(t, _time, _params) {
|
|
|
680
713
|
const s = Math.sin(t);
|
|
681
714
|
return {
|
|
682
715
|
x: c * c * c,
|
|
683
|
-
y: s * s * s
|
|
716
|
+
y: s * s * s,
|
|
684
717
|
};
|
|
685
718
|
}
|
|
686
719
|
var astroid = {
|
|
687
720
|
name: "Astroid",
|
|
688
721
|
fn: astroidFn,
|
|
689
722
|
period: TWO_PI3,
|
|
690
|
-
speed: 1.1
|
|
723
|
+
speed: 1.1,
|
|
691
724
|
};
|
|
692
725
|
|
|
693
726
|
// src/curves/deltoid.ts
|
|
@@ -695,14 +728,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
695
728
|
function deltoidFn(t, _time, _params) {
|
|
696
729
|
return {
|
|
697
730
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
698
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
731
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t),
|
|
699
732
|
};
|
|
700
733
|
}
|
|
701
734
|
var deltoid = {
|
|
702
735
|
name: "Deltoid",
|
|
703
736
|
fn: deltoidFn,
|
|
704
737
|
period: TWO_PI4,
|
|
705
|
-
speed: 0.9
|
|
738
|
+
speed: 0.9,
|
|
706
739
|
};
|
|
707
740
|
|
|
708
741
|
// src/curves/epicycloid3.ts
|
|
@@ -710,14 +743,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
710
743
|
function epicycloid3Fn(t, _time, _params) {
|
|
711
744
|
return {
|
|
712
745
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
713
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
746
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t),
|
|
714
747
|
};
|
|
715
748
|
}
|
|
716
749
|
var epicycloid3 = {
|
|
717
750
|
name: "Epicycloid (n=3)",
|
|
718
751
|
fn: epicycloid3Fn,
|
|
719
752
|
period: TWO_PI5,
|
|
720
|
-
speed: 0.75
|
|
753
|
+
speed: 0.75,
|
|
721
754
|
};
|
|
722
755
|
|
|
723
756
|
// src/curves/epitrochoid7.ts
|
|
@@ -726,14 +759,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
726
759
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
727
760
|
return {
|
|
728
761
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
729
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
762
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
730
763
|
};
|
|
731
764
|
}
|
|
732
765
|
function epitrochoid7SkeletonFn(t) {
|
|
733
766
|
const d = 1.275;
|
|
734
767
|
return {
|
|
735
768
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
736
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
769
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
737
770
|
};
|
|
738
771
|
}
|
|
739
772
|
var epitrochoid7 = {
|
|
@@ -741,7 +774,7 @@ var epitrochoid7 = {
|
|
|
741
774
|
fn: epitrochoid7Fn,
|
|
742
775
|
period: TWO_PI6,
|
|
743
776
|
speed: 1.4,
|
|
744
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
777
|
+
skeletonFn: epitrochoid7SkeletonFn,
|
|
745
778
|
};
|
|
746
779
|
|
|
747
780
|
// src/curves/lissajous32.ts
|
|
@@ -750,7 +783,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
750
783
|
const phi = time * 0.45;
|
|
751
784
|
return {
|
|
752
785
|
x: Math.sin(3 * t + phi),
|
|
753
|
-
y: Math.sin(2 * t)
|
|
786
|
+
y: Math.sin(2 * t),
|
|
754
787
|
};
|
|
755
788
|
}
|
|
756
789
|
var lissajous32 = {
|
|
@@ -758,7 +791,7 @@ var lissajous32 = {
|
|
|
758
791
|
fn: lissajous32Fn,
|
|
759
792
|
period: TWO_PI7,
|
|
760
793
|
speed: 2,
|
|
761
|
-
skeleton: "live"
|
|
794
|
+
skeleton: "live",
|
|
762
795
|
};
|
|
763
796
|
|
|
764
797
|
// src/curves/lissajous43.ts
|
|
@@ -767,7 +800,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
767
800
|
const phi = time * 0.38;
|
|
768
801
|
return {
|
|
769
802
|
x: Math.sin(4 * t + phi),
|
|
770
|
-
y: Math.sin(3 * t)
|
|
803
|
+
y: Math.sin(3 * t),
|
|
771
804
|
};
|
|
772
805
|
}
|
|
773
806
|
var lissajous43 = {
|
|
@@ -775,17 +808,18 @@ var lissajous43 = {
|
|
|
775
808
|
fn: lissajous43Fn,
|
|
776
809
|
period: TWO_PI8,
|
|
777
810
|
speed: 1.8,
|
|
778
|
-
skeleton: "live"
|
|
811
|
+
skeleton: "live",
|
|
779
812
|
};
|
|
780
813
|
|
|
781
814
|
// src/curves/lame.ts
|
|
782
815
|
var TWO_PI9 = Math.PI * 2;
|
|
783
816
|
function lameFn(t, time, _params) {
|
|
784
817
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
785
|
-
const c = Math.cos(t),
|
|
818
|
+
const c = Math.cos(t),
|
|
819
|
+
s = Math.sin(t);
|
|
786
820
|
return {
|
|
787
821
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
788
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
822
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p),
|
|
789
823
|
};
|
|
790
824
|
}
|
|
791
825
|
var lame = {
|
|
@@ -793,7 +827,7 @@ var lame = {
|
|
|
793
827
|
fn: lameFn,
|
|
794
828
|
period: TWO_PI9,
|
|
795
829
|
speed: 1,
|
|
796
|
-
skeleton: "live"
|
|
830
|
+
skeleton: "live",
|
|
797
831
|
};
|
|
798
832
|
|
|
799
833
|
// src/curves/rose3.ts
|
|
@@ -802,14 +836,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
802
836
|
const r = Math.cos(3 * t);
|
|
803
837
|
return {
|
|
804
838
|
x: r * Math.cos(t),
|
|
805
|
-
y: r * Math.sin(t)
|
|
839
|
+
y: r * Math.sin(t),
|
|
806
840
|
};
|
|
807
841
|
}
|
|
808
842
|
var rose3 = {
|
|
809
843
|
name: "Rose (n=3)",
|
|
810
844
|
fn: rose3Fn,
|
|
811
845
|
period: TWO_PI10,
|
|
812
|
-
speed: 1.15
|
|
846
|
+
speed: 1.15,
|
|
813
847
|
};
|
|
814
848
|
|
|
815
849
|
// src/curves/rose5.ts
|
|
@@ -818,14 +852,14 @@ function rose5Fn(t, _time, _params) {
|
|
|
818
852
|
const r = Math.cos(5 * t);
|
|
819
853
|
return {
|
|
820
854
|
x: r * Math.cos(t),
|
|
821
|
-
y: r * Math.sin(t)
|
|
855
|
+
y: r * Math.sin(t),
|
|
822
856
|
};
|
|
823
857
|
}
|
|
824
858
|
var rose5 = {
|
|
825
859
|
name: "Rose (n=5)",
|
|
826
860
|
fn: rose5Fn,
|
|
827
861
|
period: TWO_PI11,
|
|
828
|
-
speed: 1
|
|
862
|
+
speed: 1,
|
|
829
863
|
};
|
|
830
864
|
|
|
831
865
|
// src/curves/index.ts
|
|
@@ -839,7 +873,7 @@ var curves = {
|
|
|
839
873
|
lissajous32,
|
|
840
874
|
lissajous43,
|
|
841
875
|
epicycloid3,
|
|
842
|
-
lame
|
|
876
|
+
lame,
|
|
843
877
|
};
|
|
844
878
|
|
|
845
879
|
// src/index.ts
|
|
@@ -856,8 +890,7 @@ function parsePalette(value) {
|
|
|
856
890
|
if (Array.isArray(parsed)) {
|
|
857
891
|
return parsed;
|
|
858
892
|
}
|
|
859
|
-
} catch {
|
|
860
|
-
}
|
|
893
|
+
} catch {}
|
|
861
894
|
return value;
|
|
862
895
|
}
|
|
863
896
|
function init() {
|
|
@@ -871,18 +904,17 @@ function init() {
|
|
|
871
904
|
if (!curveDef) {
|
|
872
905
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
873
906
|
}
|
|
874
|
-
|
|
875
|
-
...canvas.dataset.trailColor && { trailColor: canvas.dataset.trailColor },
|
|
876
|
-
...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
|
|
877
|
-
...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
|
|
878
|
-
...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
|
|
879
|
-
...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) },
|
|
880
|
-
...canvas.dataset.trailStyle && {
|
|
881
|
-
trailStyle: canvas.dataset.trailStyle
|
|
882
|
-
},
|
|
883
|
-
...canvas.dataset.palette && { palette: parsePalette(canvas.dataset.palette) }
|
|
907
|
+
createSarmal(canvas, curveDef, {
|
|
908
|
+
...(canvas.dataset.trailColor && { trailColor: canvas.dataset.trailColor }),
|
|
909
|
+
...(canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor }),
|
|
910
|
+
...(canvas.dataset.headColor && { headColor: canvas.dataset.headColor }),
|
|
911
|
+
...(canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) }),
|
|
912
|
+
...(canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) }),
|
|
913
|
+
...(canvas.dataset.trailStyle && {
|
|
914
|
+
trailStyle: canvas.dataset.trailStyle,
|
|
915
|
+
}),
|
|
916
|
+
...(canvas.dataset.palette && { palette: parsePalette(canvas.dataset.palette) }),
|
|
884
917
|
});
|
|
885
|
-
sarmal.start();
|
|
886
918
|
});
|
|
887
919
|
}
|
|
888
920
|
if (document.readyState === "loading") {
|
|
@@ -893,4 +925,4 @@ if (document.readyState === "loading") {
|
|
|
893
925
|
requestAnimationFrame(init);
|
|
894
926
|
}
|
|
895
927
|
//# sourceMappingURL=auto-init.js.map
|
|
896
|
-
//# sourceMappingURL=auto-init.js.map
|
|
928
|
+
//# sourceMappingURL=auto-init.js.map
|