@sarmal/core 0.17.0 → 0.17.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 +4 -4
- package/dist/auto-init.cjs +88 -109
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.js +87 -108
- package/dist/auto-init.js.map +1 -1
- package/dist/curves/artemis2.cjs +7 -10
- package/dist/curves/artemis2.d.cts +1 -1
- package/dist/curves/artemis2.d.ts +1 -1
- package/dist/curves/artemis2.js +6 -9
- 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 +40 -53
- package/dist/curves/index.d.cts +29 -29
- package/dist/curves/index.d.ts +29 -29
- package/dist/curves/index.js +40 -69
- package/dist/curves/lame.cjs +5 -6
- package/dist/curves/lame.d.cts +1 -1
- package/dist/curves/lame.d.ts +1 -1
- package/dist/curves/lame.js +4 -5
- 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/curves/rose52.cjs +5 -5
- package/dist/curves/rose52.d.cts +1 -1
- package/dist/curves/rose52.d.ts +1 -1
- package/dist/curves/rose52.js +4 -4
- package/dist/curves/star.cjs +5 -8
- package/dist/curves/star.d.cts +1 -1
- package/dist/curves/star.d.ts +1 -1
- package/dist/curves/star.js +4 -7
- package/dist/curves/star4.cjs +5 -8
- package/dist/curves/star4.d.cts +1 -1
- package/dist/curves/star4.d.ts +1 -1
- package/dist/curves/star4.js +4 -7
- package/dist/curves/star7.cjs +5 -8
- package/dist/curves/star7.d.cts +1 -1
- package/dist/curves/star7.d.ts +1 -1
- package/dist/curves/star7.js +4 -7
- package/dist/index.cjs +82 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -76
- package/dist/index.d.ts +39 -76
- package/dist/index.js +82 -123
- package/dist/index.js.map +1 -1
- package/dist/types-BL9HhEmk.d.cts +246 -259
- package/dist/types-BL9HhEmk.d.ts +246 -259
- package/package.json +1 -1
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" ?
|
|
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 = (
|
|
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 = (
|
|
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 = (
|
|
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,16 +165,13 @@ 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 =
|
|
169
|
-
frozenStrategy === "normalized"
|
|
170
|
-
? (sampleT / frozenA.period) * frozenB.period
|
|
171
|
-
: sampleT;
|
|
168
|
+
const tB = frozenStrategy === "normalized" ? sampleT / frozenA.period * frozenB.period : sampleT;
|
|
172
169
|
const b = frozenB.fn(tB, time, params);
|
|
173
170
|
return {
|
|
174
171
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
175
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
172
|
+
y: a.y + (b.y - a.y) * frozenAlpha
|
|
176
173
|
};
|
|
177
|
-
}
|
|
174
|
+
}
|
|
178
175
|
};
|
|
179
176
|
}
|
|
180
177
|
_morphStrategy = strategy;
|
|
@@ -187,7 +184,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
187
184
|
completeMorph() {
|
|
188
185
|
if (morphCurveB !== null) {
|
|
189
186
|
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
190
|
-
t =
|
|
187
|
+
t = t / curve.period * morphCurveB.period;
|
|
191
188
|
}
|
|
192
189
|
curve = morphCurveB;
|
|
193
190
|
}
|
|
@@ -199,22 +196,19 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
199
196
|
const points = new Array(steps);
|
|
200
197
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
201
198
|
for (let i = 0; i < steps; i++) {
|
|
202
|
-
const sampleT =
|
|
199
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
203
200
|
const a = sampleSkeleton(curve, sampleT);
|
|
204
|
-
const tB =
|
|
205
|
-
_morphStrategy === "normalized"
|
|
206
|
-
? (sampleT / curve.period) * morphCurveB.period
|
|
207
|
-
: sampleT;
|
|
201
|
+
const tB = _morphStrategy === "normalized" ? sampleT / curve.period * morphCurveB.period : sampleT;
|
|
208
202
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
209
203
|
points[i] = {
|
|
210
204
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
211
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
205
|
+
y: a.y + (b.y - a.y) * _morphAlpha
|
|
212
206
|
};
|
|
213
207
|
}
|
|
214
208
|
return points;
|
|
215
209
|
}
|
|
216
210
|
for (let i = 0; i < steps; i++) {
|
|
217
|
-
const sampleT =
|
|
211
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
218
212
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
219
213
|
}
|
|
220
214
|
return points;
|
|
@@ -256,7 +250,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
256
250
|
_speedTransition.reject(new Error("Speed transition cancelled"));
|
|
257
251
|
_speedTransition = null;
|
|
258
252
|
}
|
|
259
|
-
}
|
|
253
|
+
}
|
|
260
254
|
};
|
|
261
255
|
}
|
|
262
256
|
|
|
@@ -319,16 +313,13 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
|
|
|
319
313
|
r1x: nx - n1.x * w1,
|
|
320
314
|
r1y: ny - n1.y * w1,
|
|
321
315
|
opacity,
|
|
322
|
-
progress
|
|
316
|
+
progress
|
|
323
317
|
};
|
|
324
318
|
}
|
|
325
319
|
function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
326
320
|
if (pts.length === 0) return null;
|
|
327
321
|
const first = pts[0];
|
|
328
|
-
let minX = first.x,
|
|
329
|
-
maxX = first.x,
|
|
330
|
-
minY = first.y,
|
|
331
|
-
maxY = first.y;
|
|
322
|
+
let minX = first.x, maxX = first.x, minY = first.y, maxY = first.y;
|
|
332
323
|
for (const p of pts) {
|
|
333
324
|
if (p.x < minX) {
|
|
334
325
|
minX = p.x;
|
|
@@ -347,7 +338,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
347
338
|
const h = maxY - minY;
|
|
348
339
|
if (w === 0 && h === 0) {
|
|
349
340
|
throw new Error(
|
|
350
|
-
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
341
|
+
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
351
342
|
);
|
|
352
343
|
}
|
|
353
344
|
const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
|
|
@@ -358,12 +349,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
358
349
|
scaleXProportional,
|
|
359
350
|
scaleYProportional,
|
|
360
351
|
scaleXMinPadding,
|
|
361
|
-
scaleYMinPadding
|
|
352
|
+
scaleYMinPadding
|
|
362
353
|
);
|
|
363
354
|
return {
|
|
364
355
|
scale,
|
|
365
356
|
offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
|
|
366
|
-
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
357
|
+
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
367
358
|
};
|
|
368
359
|
}
|
|
369
360
|
function enginePassthroughs(engine) {
|
|
@@ -373,17 +364,17 @@ function enginePassthroughs(engine) {
|
|
|
373
364
|
setSpeed: engine.setSpeed,
|
|
374
365
|
getSpeed: engine.getSpeed,
|
|
375
366
|
resetSpeed: engine.resetSpeed,
|
|
376
|
-
setSpeedOver: engine.setSpeedOver
|
|
367
|
+
setSpeedOver: engine.setSpeedOver
|
|
377
368
|
};
|
|
378
369
|
}
|
|
379
370
|
function hexToRgb(hex) {
|
|
380
371
|
const n = parseInt(hex.slice(1), 16);
|
|
381
|
-
return { r: n >> 16, g:
|
|
372
|
+
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
382
373
|
}
|
|
383
374
|
var lerpRgb = (a, b, t) => ({
|
|
384
375
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
385
376
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
386
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
377
|
+
b: Math.round(a.b + (b.b - a.b) * t)
|
|
387
378
|
});
|
|
388
379
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
389
380
|
if (palette.length === 0) {
|
|
@@ -406,7 +397,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
406
397
|
"trailColor",
|
|
407
398
|
"headColor",
|
|
408
399
|
"skeletonColor",
|
|
409
|
-
"trailStyle"
|
|
400
|
+
"trailStyle"
|
|
410
401
|
]);
|
|
411
402
|
function validateRenderOptions(partial) {
|
|
412
403
|
for (const key of Object.keys(partial)) {
|
|
@@ -431,7 +422,7 @@ function assertTrailColor(value) {
|
|
|
431
422
|
if (typeof value === "string") {
|
|
432
423
|
if (!HEX_COLOR_RE.test(value)) {
|
|
433
424
|
throw new TypeError(
|
|
434
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"
|
|
425
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`
|
|
435
426
|
);
|
|
436
427
|
}
|
|
437
428
|
return;
|
|
@@ -439,21 +430,21 @@ function assertTrailColor(value) {
|
|
|
439
430
|
if (Array.isArray(value)) {
|
|
440
431
|
if (value.length < 2) {
|
|
441
432
|
throw new RangeError(
|
|
442
|
-
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}
|
|
433
|
+
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`
|
|
443
434
|
);
|
|
444
435
|
}
|
|
445
436
|
for (let i = 0; i < value.length; i++) {
|
|
446
437
|
const entry = value[i];
|
|
447
438
|
if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
|
|
448
439
|
throw new TypeError(
|
|
449
|
-
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}
|
|
440
|
+
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`
|
|
450
441
|
);
|
|
451
442
|
}
|
|
452
443
|
}
|
|
453
444
|
return;
|
|
454
445
|
}
|
|
455
446
|
throw new TypeError(
|
|
456
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}
|
|
447
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`
|
|
457
448
|
);
|
|
458
449
|
}
|
|
459
450
|
function assertHeadColor(value) {
|
|
@@ -462,7 +453,7 @@ function assertHeadColor(value) {
|
|
|
462
453
|
}
|
|
463
454
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
464
455
|
throw new TypeError(
|
|
465
|
-
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}
|
|
456
|
+
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`
|
|
466
457
|
);
|
|
467
458
|
}
|
|
468
459
|
}
|
|
@@ -472,14 +463,14 @@ function assertSkeletonColor(value) {
|
|
|
472
463
|
}
|
|
473
464
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
474
465
|
throw new TypeError(
|
|
475
|
-
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}
|
|
466
|
+
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`
|
|
476
467
|
);
|
|
477
468
|
}
|
|
478
469
|
}
|
|
479
470
|
function assertTrailStyle(value) {
|
|
480
471
|
if (!TRAIL_STYLES.includes(value)) {
|
|
481
472
|
throw new RangeError(
|
|
482
|
-
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}
|
|
473
|
+
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`
|
|
483
474
|
);
|
|
484
475
|
}
|
|
485
476
|
}
|
|
@@ -501,13 +492,13 @@ function resolveHeadColor(trailColor, trailStyle) {
|
|
|
501
492
|
function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
502
493
|
if (trailStyle === "default" && Array.isArray(trailColor)) {
|
|
503
494
|
console.warn(
|
|
504
|
-
'[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.'
|
|
495
|
+
'[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.'
|
|
505
496
|
);
|
|
506
497
|
return;
|
|
507
498
|
}
|
|
508
499
|
if (trailStyle !== "default" && typeof trailColor === "string") {
|
|
509
500
|
console.warn(
|
|
510
|
-
`[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient
|
|
501
|
+
`[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient.`
|
|
511
502
|
);
|
|
512
503
|
}
|
|
513
504
|
}
|
|
@@ -517,7 +508,7 @@ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160)
|
|
|
517
508
|
var WHITE_HEX = "#ffffff";
|
|
518
509
|
function hexToRgbComponents(hex) {
|
|
519
510
|
const n = parseInt(hex.slice(1), 16);
|
|
520
|
-
return `${n >> 16},${
|
|
511
|
+
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
521
512
|
}
|
|
522
513
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
523
514
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -642,7 +633,7 @@ function createRenderer(options) {
|
|
|
642
633
|
i,
|
|
643
634
|
trailCount,
|
|
644
635
|
toX,
|
|
645
|
-
toY
|
|
636
|
+
toY
|
|
646
637
|
);
|
|
647
638
|
if (trailStyle === "default") {
|
|
648
639
|
ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
|
|
@@ -803,7 +794,7 @@ function createRenderer(options) {
|
|
|
803
794
|
if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
|
|
804
795
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
805
796
|
}
|
|
806
|
-
}
|
|
797
|
+
}
|
|
807
798
|
};
|
|
808
799
|
if (shouldAutoStart) {
|
|
809
800
|
instance.play();
|
|
@@ -814,22 +805,19 @@ function createRenderer(options) {
|
|
|
814
805
|
// src/curves/artemis2.ts
|
|
815
806
|
var TWO_PI2 = Math.PI * 2;
|
|
816
807
|
function artemis2Fn(t, _time, _params) {
|
|
817
|
-
const a = 0.35,
|
|
818
|
-
|
|
819
|
-
ox = 0.175;
|
|
820
|
-
const s = Math.sin(t),
|
|
821
|
-
c = Math.cos(t);
|
|
808
|
+
const a = 0.35, b = 0.15, ox = 0.175;
|
|
809
|
+
const s = Math.sin(t), c = Math.cos(t);
|
|
822
810
|
const denom = 1 + s * s;
|
|
823
811
|
return {
|
|
824
|
-
x:
|
|
825
|
-
y:
|
|
812
|
+
x: c * (1 + a * c) / denom - ox,
|
|
813
|
+
y: s * c * (1 + b * c) / denom
|
|
826
814
|
};
|
|
827
815
|
}
|
|
828
816
|
var artemis2 = {
|
|
829
817
|
name: "Artemis II",
|
|
830
818
|
fn: artemis2Fn,
|
|
831
819
|
period: TWO_PI2,
|
|
832
|
-
speed: 0.7
|
|
820
|
+
speed: 0.7
|
|
833
821
|
};
|
|
834
822
|
|
|
835
823
|
// src/curves/astroid.ts
|
|
@@ -839,14 +827,14 @@ function astroidFn(t, _time, _params) {
|
|
|
839
827
|
const s = Math.sin(t);
|
|
840
828
|
return {
|
|
841
829
|
x: c * c * c,
|
|
842
|
-
y: s * s * s
|
|
830
|
+
y: s * s * s
|
|
843
831
|
};
|
|
844
832
|
}
|
|
845
833
|
var astroid = {
|
|
846
834
|
name: "Astroid",
|
|
847
835
|
fn: astroidFn,
|
|
848
836
|
period: TWO_PI3,
|
|
849
|
-
speed: 1.1
|
|
837
|
+
speed: 1.1
|
|
850
838
|
};
|
|
851
839
|
|
|
852
840
|
// src/curves/deltoid.ts
|
|
@@ -854,14 +842,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
854
842
|
function deltoidFn(t, _time, _params) {
|
|
855
843
|
return {
|
|
856
844
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
857
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
845
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
858
846
|
};
|
|
859
847
|
}
|
|
860
848
|
var deltoid = {
|
|
861
849
|
name: "Deltoid",
|
|
862
850
|
fn: deltoidFn,
|
|
863
851
|
period: TWO_PI4,
|
|
864
|
-
speed: 0.9
|
|
852
|
+
speed: 0.9
|
|
865
853
|
};
|
|
866
854
|
|
|
867
855
|
// src/curves/epicycloid3.ts
|
|
@@ -869,14 +857,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
869
857
|
function epicycloid3Fn(t, _time, _params) {
|
|
870
858
|
return {
|
|
871
859
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
872
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
860
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
873
861
|
};
|
|
874
862
|
}
|
|
875
863
|
var epicycloid3 = {
|
|
876
864
|
name: "Epicycloid (n=3)",
|
|
877
865
|
fn: epicycloid3Fn,
|
|
878
866
|
period: TWO_PI5,
|
|
879
|
-
speed: 0.75
|
|
867
|
+
speed: 0.75
|
|
880
868
|
};
|
|
881
869
|
|
|
882
870
|
// src/curves/epitrochoid7.ts
|
|
@@ -885,14 +873,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
885
873
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
886
874
|
return {
|
|
887
875
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
888
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
876
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
889
877
|
};
|
|
890
878
|
}
|
|
891
879
|
function epitrochoid7SkeletonFn(t) {
|
|
892
880
|
const d = 1.275;
|
|
893
881
|
return {
|
|
894
882
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
895
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
883
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
896
884
|
};
|
|
897
885
|
}
|
|
898
886
|
var epitrochoid7 = {
|
|
@@ -900,7 +888,7 @@ var epitrochoid7 = {
|
|
|
900
888
|
fn: epitrochoid7Fn,
|
|
901
889
|
period: TWO_PI6,
|
|
902
890
|
speed: 1.4,
|
|
903
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
891
|
+
skeletonFn: epitrochoid7SkeletonFn
|
|
904
892
|
};
|
|
905
893
|
|
|
906
894
|
// src/curves/lissajous32.ts
|
|
@@ -909,7 +897,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
909
897
|
const phi = time * 0.45;
|
|
910
898
|
return {
|
|
911
899
|
x: Math.sin(3 * t + phi),
|
|
912
|
-
y: Math.sin(2 * t)
|
|
900
|
+
y: Math.sin(2 * t)
|
|
913
901
|
};
|
|
914
902
|
}
|
|
915
903
|
var lissajous32 = {
|
|
@@ -917,7 +905,7 @@ var lissajous32 = {
|
|
|
917
905
|
fn: lissajous32Fn,
|
|
918
906
|
period: TWO_PI7,
|
|
919
907
|
speed: 2,
|
|
920
|
-
skeleton: "live"
|
|
908
|
+
skeleton: "live"
|
|
921
909
|
};
|
|
922
910
|
|
|
923
911
|
// src/curves/lissajous43.ts
|
|
@@ -926,7 +914,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
926
914
|
const phi = time * 0.38;
|
|
927
915
|
return {
|
|
928
916
|
x: Math.sin(4 * t + phi),
|
|
929
|
-
y: Math.sin(3 * t)
|
|
917
|
+
y: Math.sin(3 * t)
|
|
930
918
|
};
|
|
931
919
|
}
|
|
932
920
|
var lissajous43 = {
|
|
@@ -934,18 +922,17 @@ var lissajous43 = {
|
|
|
934
922
|
fn: lissajous43Fn,
|
|
935
923
|
period: TWO_PI8,
|
|
936
924
|
speed: 1.8,
|
|
937
|
-
skeleton: "live"
|
|
925
|
+
skeleton: "live"
|
|
938
926
|
};
|
|
939
927
|
|
|
940
928
|
// src/curves/lame.ts
|
|
941
929
|
var TWO_PI9 = Math.PI * 2;
|
|
942
930
|
function lameFn(t, time, _params) {
|
|
943
931
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
944
|
-
const c = Math.cos(t),
|
|
945
|
-
s = Math.sin(t);
|
|
932
|
+
const c = Math.cos(t), s = Math.sin(t);
|
|
946
933
|
return {
|
|
947
934
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
948
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
935
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
949
936
|
};
|
|
950
937
|
}
|
|
951
938
|
var lame = {
|
|
@@ -953,7 +940,7 @@ var lame = {
|
|
|
953
940
|
fn: lameFn,
|
|
954
941
|
period: TWO_PI9,
|
|
955
942
|
speed: 1,
|
|
956
|
-
skeleton: "live"
|
|
943
|
+
skeleton: "live"
|
|
957
944
|
};
|
|
958
945
|
|
|
959
946
|
// src/curves/rose3.ts
|
|
@@ -962,14 +949,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
962
949
|
const r = Math.cos(3 * t);
|
|
963
950
|
return {
|
|
964
951
|
x: r * Math.cos(t),
|
|
965
|
-
y: r * Math.sin(t)
|
|
952
|
+
y: r * Math.sin(t)
|
|
966
953
|
};
|
|
967
954
|
}
|
|
968
955
|
var rose3 = {
|
|
969
956
|
name: "Rose (n=3)",
|
|
970
957
|
fn: rose3Fn,
|
|
971
958
|
period: TWO_PI10,
|
|
972
|
-
speed: 1.15
|
|
959
|
+
speed: 1.15
|
|
973
960
|
};
|
|
974
961
|
|
|
975
962
|
// src/curves/rose5.ts
|
|
@@ -978,87 +965,78 @@ function rose5Fn(t, _time, _params) {
|
|
|
978
965
|
const r = Math.cos(5 * t);
|
|
979
966
|
return {
|
|
980
967
|
x: r * Math.cos(t),
|
|
981
|
-
y: r * Math.sin(t)
|
|
968
|
+
y: r * Math.sin(t)
|
|
982
969
|
};
|
|
983
970
|
}
|
|
984
971
|
var rose5 = {
|
|
985
972
|
name: "Rose (n=5)",
|
|
986
973
|
fn: rose5Fn,
|
|
987
974
|
period: TWO_PI11,
|
|
988
|
-
speed: 1
|
|
975
|
+
speed: 1
|
|
989
976
|
};
|
|
990
977
|
|
|
991
978
|
// src/curves/rose52.ts
|
|
992
979
|
var FOUR_PI = Math.PI * 4;
|
|
993
980
|
function rose52Fn(t, _time, _params) {
|
|
994
|
-
const r = Math.cos(
|
|
981
|
+
const r = Math.cos(5 / 2 * t);
|
|
995
982
|
return {
|
|
996
983
|
x: r * Math.cos(t),
|
|
997
|
-
y: r * Math.sin(t)
|
|
984
|
+
y: r * Math.sin(t)
|
|
998
985
|
};
|
|
999
986
|
}
|
|
1000
987
|
var rose52 = {
|
|
1001
988
|
name: "Rose (n=5/2)",
|
|
1002
989
|
fn: rose52Fn,
|
|
1003
990
|
period: FOUR_PI,
|
|
1004
|
-
speed: 0.8
|
|
991
|
+
speed: 0.8
|
|
1005
992
|
};
|
|
1006
993
|
|
|
1007
994
|
// src/curves/star.ts
|
|
1008
995
|
var TWO_PI12 = Math.PI * 2;
|
|
1009
996
|
function starFn(t, _time, _params) {
|
|
1010
|
-
const r =
|
|
1011
|
-
Math.abs(Math.cos((5 / 2) * t)) +
|
|
1012
|
-
0.35 * Math.abs(Math.cos((15 / 2) * t)) +
|
|
1013
|
-
0.15 * Math.abs(Math.cos((25 / 2) * t));
|
|
997
|
+
const r = Math.abs(Math.cos(5 / 2 * t)) + 0.35 * Math.abs(Math.cos(15 / 2 * t)) + 0.15 * Math.abs(Math.cos(25 / 2 * t));
|
|
1014
998
|
return {
|
|
1015
999
|
x: r * Math.cos(t),
|
|
1016
|
-
y: r * Math.sin(t)
|
|
1000
|
+
y: r * Math.sin(t)
|
|
1017
1001
|
};
|
|
1018
1002
|
}
|
|
1019
1003
|
var star = {
|
|
1020
1004
|
name: "Star",
|
|
1021
1005
|
fn: starFn,
|
|
1022
1006
|
period: TWO_PI12,
|
|
1023
|
-
speed: 1
|
|
1007
|
+
speed: 1
|
|
1024
1008
|
};
|
|
1025
1009
|
|
|
1026
1010
|
// src/curves/star4.ts
|
|
1027
1011
|
var TWO_PI13 = Math.PI * 2;
|
|
1028
1012
|
function star4Fn(t, _time, _params) {
|
|
1029
|
-
const r =
|
|
1030
|
-
Math.abs(Math.cos(2 * t)) +
|
|
1031
|
-
0.35 * Math.abs(Math.cos(6 * t)) +
|
|
1032
|
-
0.15 * Math.abs(Math.cos(10 * t));
|
|
1013
|
+
const r = Math.abs(Math.cos(2 * t)) + 0.35 * Math.abs(Math.cos(6 * t)) + 0.15 * Math.abs(Math.cos(10 * t));
|
|
1033
1014
|
return {
|
|
1034
1015
|
x: r * Math.cos(t),
|
|
1035
|
-
y: r * Math.sin(t)
|
|
1016
|
+
y: r * Math.sin(t)
|
|
1036
1017
|
};
|
|
1037
1018
|
}
|
|
1038
1019
|
var star4 = {
|
|
1039
1020
|
name: "Star (4-arm)",
|
|
1040
1021
|
fn: star4Fn,
|
|
1041
1022
|
period: TWO_PI13,
|
|
1042
|
-
speed: 1
|
|
1023
|
+
speed: 1
|
|
1043
1024
|
};
|
|
1044
1025
|
|
|
1045
1026
|
// src/curves/star7.ts
|
|
1046
1027
|
var TWO_PI14 = Math.PI * 2;
|
|
1047
1028
|
function star7Fn(t, _time, _params) {
|
|
1048
|
-
const r =
|
|
1049
|
-
Math.abs(Math.cos((7 / 2) * t)) +
|
|
1050
|
-
0.35 * Math.abs(Math.cos((21 / 2) * t)) +
|
|
1051
|
-
0.15 * Math.abs(Math.cos((35 / 2) * t));
|
|
1029
|
+
const r = Math.abs(Math.cos(7 / 2 * t)) + 0.35 * Math.abs(Math.cos(21 / 2 * t)) + 0.15 * Math.abs(Math.cos(35 / 2 * t));
|
|
1052
1030
|
return {
|
|
1053
1031
|
x: r * Math.cos(t),
|
|
1054
|
-
y: r * Math.sin(t)
|
|
1032
|
+
y: r * Math.sin(t)
|
|
1055
1033
|
};
|
|
1056
1034
|
}
|
|
1057
1035
|
var star7 = {
|
|
1058
1036
|
name: "Star (7-arm)",
|
|
1059
1037
|
fn: star7Fn,
|
|
1060
1038
|
period: TWO_PI14,
|
|
1061
|
-
speed: 1
|
|
1039
|
+
speed: 1
|
|
1062
1040
|
};
|
|
1063
1041
|
|
|
1064
1042
|
// src/curves/index.ts
|
|
@@ -1076,7 +1054,7 @@ var curves = {
|
|
|
1076
1054
|
lissajous32,
|
|
1077
1055
|
lissajous43,
|
|
1078
1056
|
epicycloid3,
|
|
1079
|
-
lame
|
|
1057
|
+
lame
|
|
1080
1058
|
};
|
|
1081
1059
|
|
|
1082
1060
|
// src/index.ts
|
|
@@ -1093,7 +1071,8 @@ function parseTrailColor(value) {
|
|
|
1093
1071
|
if (Array.isArray(parsed)) {
|
|
1094
1072
|
return parsed;
|
|
1095
1073
|
}
|
|
1096
|
-
} catch {
|
|
1074
|
+
} catch {
|
|
1075
|
+
}
|
|
1097
1076
|
return value;
|
|
1098
1077
|
}
|
|
1099
1078
|
function init() {
|
|
@@ -1108,16 +1087,16 @@ function init() {
|
|
|
1108
1087
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
1109
1088
|
}
|
|
1110
1089
|
const instance = createSarmal(canvas, curveDef, {
|
|
1111
|
-
...
|
|
1112
|
-
trailColor: parseTrailColor(canvas.dataset.trailColor)
|
|
1113
|
-
}
|
|
1114
|
-
...
|
|
1115
|
-
...
|
|
1116
|
-
...
|
|
1117
|
-
...
|
|
1118
|
-
...
|
|
1119
|
-
trailStyle: canvas.dataset.trailStyle
|
|
1120
|
-
}
|
|
1090
|
+
...canvas.dataset.trailColor && {
|
|
1091
|
+
trailColor: parseTrailColor(canvas.dataset.trailColor)
|
|
1092
|
+
},
|
|
1093
|
+
...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
|
|
1094
|
+
...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
|
|
1095
|
+
...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
|
|
1096
|
+
...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) },
|
|
1097
|
+
...canvas.dataset.trailStyle && {
|
|
1098
|
+
trailStyle: canvas.dataset.trailStyle
|
|
1099
|
+
}
|
|
1121
1100
|
});
|
|
1122
1101
|
if (canvas.dataset.speed) {
|
|
1123
1102
|
instance.setSpeed(parseFloat(canvas.dataset.speed));
|
|
@@ -1134,4 +1113,4 @@ if (document.readyState === "loading") {
|
|
|
1134
1113
|
|
|
1135
1114
|
export { init };
|
|
1136
1115
|
//# sourceMappingURL=auto-init.js.map
|
|
1137
|
-
//# sourceMappingURL=auto-init.js.map
|
|
1116
|
+
//# sourceMappingURL=auto-init.js.map
|