@sarmal/core 0.6.0 → 0.7.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 +117 -139
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.d.cts +2 -1
- package/dist/auto-init.d.ts +2 -1
- package/dist/auto-init.js +116 -138
- package/dist/auto-init.js.map +1 -1
- package/dist/index.cjs +122 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +200 -225
- package/dist/index.d.ts +200 -225
- package/dist/index.js +121 -152
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/auto-init.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/engine.ts
|
|
4
4
|
var TWO_PI = Math.PI * 2;
|
|
@@ -51,7 +51,7 @@ function resolveCurve(curveDef) {
|
|
|
51
51
|
period: curveDef.period ?? TWO_PI,
|
|
52
52
|
speed: curveDef.speed ?? 1,
|
|
53
53
|
skeleton: curveDef.skeleton,
|
|
54
|
-
skeletonFn: curveDef.skeletonFn
|
|
54
|
+
skeletonFn: curveDef.skeletonFn
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
function createEngine(curveDef, trailLength = 120) {
|
|
@@ -77,7 +77,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
77
77
|
actualTime += deltaTime;
|
|
78
78
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
79
79
|
const a = curve.fn(t, actualTime, {});
|
|
80
|
-
const tB = _morphStrategy === "normalized" ?
|
|
80
|
+
const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
|
|
81
81
|
const b = morphCurveB.fn(tB, actualTime, {});
|
|
82
82
|
trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
|
|
83
83
|
} else {
|
|
@@ -101,14 +101,14 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
101
101
|
trail.clear();
|
|
102
102
|
},
|
|
103
103
|
seek(newT, { clearTrail = false } = {}) {
|
|
104
|
-
t = (
|
|
104
|
+
t = (newT % curve.period + curve.period) % curve.period;
|
|
105
105
|
if (clearTrail) {
|
|
106
106
|
trail.clear();
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
seekWithTrail(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
|
|
110
110
|
const advance = curve.speed * step;
|
|
111
|
-
const target = (
|
|
111
|
+
const target = (targetT % curve.period + curve.period) % curve.period;
|
|
112
112
|
const targetTime = target / curve.speed;
|
|
113
113
|
t = target;
|
|
114
114
|
actualTime = targetTime;
|
|
@@ -134,16 +134,13 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
134
134
|
...frozenB,
|
|
135
135
|
fn: (sampleT, time, params) => {
|
|
136
136
|
const a = frozenA.fn(sampleT, time, params);
|
|
137
|
-
const tB =
|
|
138
|
-
frozenStrategy === "normalized"
|
|
139
|
-
? (sampleT / frozenA.period) * frozenB.period
|
|
140
|
-
: sampleT;
|
|
137
|
+
const tB = frozenStrategy === "normalized" ? sampleT / frozenA.period * frozenB.period : sampleT;
|
|
141
138
|
const b = frozenB.fn(tB, time, params);
|
|
142
139
|
return {
|
|
143
140
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
144
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
141
|
+
y: a.y + (b.y - a.y) * frozenAlpha
|
|
145
142
|
};
|
|
146
|
-
}
|
|
143
|
+
}
|
|
147
144
|
};
|
|
148
145
|
}
|
|
149
146
|
_morphStrategy = strategy;
|
|
@@ -155,6 +152,9 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
155
152
|
},
|
|
156
153
|
completeMorph() {
|
|
157
154
|
if (morphCurveB !== null) {
|
|
155
|
+
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
156
|
+
t = t / curve.period * morphCurveB.period;
|
|
157
|
+
}
|
|
158
158
|
curve = morphCurveB;
|
|
159
159
|
}
|
|
160
160
|
morphCurveB = null;
|
|
@@ -165,26 +165,23 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
165
165
|
const points = new Array(steps);
|
|
166
166
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
167
167
|
for (let i = 0; i < steps; i++) {
|
|
168
|
-
const sampleT =
|
|
168
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
169
169
|
const a = sampleSkeleton(curve, sampleT);
|
|
170
|
-
const tB =
|
|
171
|
-
_morphStrategy === "normalized"
|
|
172
|
-
? (sampleT / curve.period) * morphCurveB.period
|
|
173
|
-
: sampleT;
|
|
170
|
+
const tB = _morphStrategy === "normalized" ? sampleT / curve.period * morphCurveB.period : sampleT;
|
|
174
171
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
175
172
|
points[i] = {
|
|
176
173
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
177
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
174
|
+
y: a.y + (b.y - a.y) * _morphAlpha
|
|
178
175
|
};
|
|
179
176
|
}
|
|
180
177
|
return points;
|
|
181
178
|
}
|
|
182
179
|
for (let i = 0; i < steps; i++) {
|
|
183
|
-
const sampleT =
|
|
180
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
184
181
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
185
182
|
}
|
|
186
183
|
return points;
|
|
187
|
-
}
|
|
184
|
+
}
|
|
188
185
|
};
|
|
189
186
|
}
|
|
190
187
|
|
|
@@ -204,7 +201,7 @@ var GLOW_INNER_EDGE = 0.4;
|
|
|
204
201
|
var GLOW_FALLOFF_OPACITY = 0.53;
|
|
205
202
|
function hexToRgbComponents(hex) {
|
|
206
203
|
const n = parseInt(hex.slice(1), 16);
|
|
207
|
-
return `${n >> 16},${
|
|
204
|
+
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
208
205
|
}
|
|
209
206
|
function createRenderer(options) {
|
|
210
207
|
const canvas = options.canvas;
|
|
@@ -218,7 +215,7 @@ function createRenderer(options) {
|
|
|
218
215
|
trailColor: options.trailColor ?? "#ffffff",
|
|
219
216
|
headColor: options.headColor ?? "#ffffff",
|
|
220
217
|
headRadius: options.headRadius ?? DEFAULT_HEAD_RADIUS,
|
|
221
|
-
glowSize: options.glowSize ?? DEFAULT_GLOW_SIZE
|
|
218
|
+
glowSize: options.glowSize ?? DEFAULT_GLOW_SIZE
|
|
222
219
|
};
|
|
223
220
|
const trailRgb = hexToRgbComponents(opts.trailColor);
|
|
224
221
|
const headRgbFalloff = `rgba(${hexToRgbComponents(opts.headColor)},${GLOW_FALLOFF_OPACITY})`;
|
|
@@ -234,32 +231,18 @@ function createRenderer(options) {
|
|
|
234
231
|
let lastTime = 0;
|
|
235
232
|
let morphResolve = null;
|
|
236
233
|
let morphDurationMs = DEFAULT_MORPH_DURATION_MS;
|
|
237
|
-
let morphTarget = null;
|
|
238
234
|
let morphAlpha = 0;
|
|
239
|
-
let
|
|
240
|
-
let
|
|
241
|
-
function
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
maxX =
|
|
248
|
-
minY =
|
|
249
|
-
maxY =
|
|
250
|
-
for (const p of skeleton) {
|
|
251
|
-
if (p.x < minX) {
|
|
252
|
-
minX = p.x;
|
|
253
|
-
}
|
|
254
|
-
if (p.x > maxX) {
|
|
255
|
-
maxX = p.x;
|
|
256
|
-
}
|
|
257
|
-
if (p.y < minY) {
|
|
258
|
-
minY = p.y;
|
|
259
|
-
}
|
|
260
|
-
if (p.y > maxY) {
|
|
261
|
-
maxY = p.y;
|
|
262
|
-
}
|
|
235
|
+
let morphBoundsA = null;
|
|
236
|
+
let morphBoundsB = null;
|
|
237
|
+
function computeBoundaries(pts) {
|
|
238
|
+
if (pts.length === 0) return null;
|
|
239
|
+
const first = pts[0];
|
|
240
|
+
let minX = first.x, maxX = first.x, minY = first.y, maxY = first.y;
|
|
241
|
+
for (const p of pts) {
|
|
242
|
+
if (p.x < minX) minX = p.x;
|
|
243
|
+
if (p.x > maxX) maxX = p.x;
|
|
244
|
+
if (p.y < minY) minY = p.y;
|
|
245
|
+
if (p.y > maxY) maxY = p.y;
|
|
263
246
|
}
|
|
264
247
|
const width = maxX - minX;
|
|
265
248
|
const height = maxY - minY;
|
|
@@ -267,11 +250,22 @@ function createRenderer(options) {
|
|
|
267
250
|
const canvasHeight = canvas.height;
|
|
268
251
|
const scaleX = canvasWidth / (width * (1 + FIT_PADDING * 2));
|
|
269
252
|
const scaleY = canvasHeight / (height * (1 + FIT_PADDING * 2));
|
|
270
|
-
|
|
271
|
-
const boundsWidth = width *
|
|
272
|
-
const boundsHeight = height *
|
|
273
|
-
|
|
274
|
-
|
|
253
|
+
const s = Math.min(scaleX, scaleY);
|
|
254
|
+
const boundsWidth = width * s;
|
|
255
|
+
const boundsHeight = height * s;
|
|
256
|
+
return {
|
|
257
|
+
scale: s,
|
|
258
|
+
offsetX: (canvasWidth - boundsWidth) / 2 - minX * s,
|
|
259
|
+
offsetY: (canvasHeight - boundsHeight) / 2 - minY * s
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function calculateBoundaries() {
|
|
263
|
+
const b = computeBoundaries(skeleton);
|
|
264
|
+
if (b) {
|
|
265
|
+
scale = b.scale;
|
|
266
|
+
offsetX = b.offsetX;
|
|
267
|
+
offsetY = b.offsetY;
|
|
268
|
+
}
|
|
275
269
|
}
|
|
276
270
|
function buildSkeletonCanvas() {
|
|
277
271
|
if (skeleton.length < 2) return;
|
|
@@ -288,20 +282,23 @@ function createRenderer(options) {
|
|
|
288
282
|
}
|
|
289
283
|
skeletonCtx.stroke();
|
|
290
284
|
}
|
|
285
|
+
function drawSkeletonPath(pts, opacity) {
|
|
286
|
+
if (pts.length < 2) return;
|
|
287
|
+
ctx.strokeStyle = `rgba(${hexToRgbComponents(opts.skeletonColor)},${opacity})`;
|
|
288
|
+
ctx.lineWidth = 1.5;
|
|
289
|
+
ctx.beginPath();
|
|
290
|
+
ctx.moveTo(pts[0].x * scale + offsetX, pts[0].y * scale + offsetY);
|
|
291
|
+
for (let i = 1; i < pts.length; i++) {
|
|
292
|
+
ctx.lineTo(pts[i].x * scale + offsetX, pts[i].y * scale + offsetY);
|
|
293
|
+
}
|
|
294
|
+
ctx.stroke();
|
|
295
|
+
}
|
|
291
296
|
function drawSkeleton() {
|
|
292
297
|
if (opts.skeletonColor === "transparent") {
|
|
293
298
|
return;
|
|
294
299
|
}
|
|
295
300
|
if (engine.morphAlpha !== null) {
|
|
296
|
-
|
|
297
|
-
ctx.globalAlpha = (1 - morphAlpha) * DEFAULT_SKELETON_OPACITY;
|
|
298
|
-
ctx.drawImage(skeletonCanvasA, 0, 0);
|
|
299
|
-
}
|
|
300
|
-
if (skeletonCanvasB) {
|
|
301
|
-
ctx.globalAlpha = morphAlpha * DEFAULT_SKELETON_OPACITY;
|
|
302
|
-
ctx.drawImage(skeletonCanvasB, 0, 0);
|
|
303
|
-
}
|
|
304
|
-
ctx.globalAlpha = 1;
|
|
301
|
+
drawSkeletonPath(engine.getSarmalSkeleton(), DEFAULT_SKELETON_OPACITY);
|
|
305
302
|
return;
|
|
306
303
|
}
|
|
307
304
|
if (engine.isLiveSkeleton) {
|
|
@@ -373,23 +370,31 @@ function createRenderer(options) {
|
|
|
373
370
|
if (engine.morphAlpha !== null) {
|
|
374
371
|
morphAlpha = Math.min(1, morphAlpha + deltaTime / (morphDurationMs / 1e3));
|
|
375
372
|
engine.setMorphAlpha(morphAlpha);
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
if (morphBoundsA && morphBoundsB) {
|
|
374
|
+
const a = morphBoundsA;
|
|
375
|
+
const b = morphBoundsB;
|
|
376
|
+
scale = a.scale + (b.scale - a.scale) * morphAlpha;
|
|
377
|
+
offsetX = a.offsetX + (b.offsetX - a.offsetX) * morphAlpha;
|
|
378
|
+
offsetY = a.offsetY + (b.offsetY - a.offsetY) * morphAlpha;
|
|
379
|
+
}
|
|
378
380
|
if (morphAlpha >= 1) {
|
|
379
381
|
engine.completeMorph();
|
|
380
382
|
morphResolve?.();
|
|
381
383
|
morphResolve = null;
|
|
382
|
-
morphTarget = null;
|
|
383
384
|
morphAlpha = 0;
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
morphBoundsA = null;
|
|
386
|
+
morphBoundsB = null;
|
|
387
|
+
skeleton = engine.getSarmalSkeleton();
|
|
388
|
+
if (!engine.isLiveSkeleton) {
|
|
389
|
+
buildSkeletonCanvas();
|
|
390
|
+
}
|
|
386
391
|
}
|
|
387
392
|
}
|
|
388
393
|
trail = engine.tick(deltaTime);
|
|
389
394
|
trailCount = engine.trailCount;
|
|
390
395
|
head = trailCount > 0 ? trail[trailCount - 1] : null;
|
|
391
396
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
392
|
-
if (engine.isLiveSkeleton
|
|
397
|
+
if (engine.isLiveSkeleton && engine.morphAlpha === null) {
|
|
393
398
|
skeleton = engine.getSarmalSkeleton();
|
|
394
399
|
calculateBoundaries();
|
|
395
400
|
}
|
|
@@ -436,83 +441,57 @@ function createRenderer(options) {
|
|
|
436
441
|
engine.seekWithTrail(t);
|
|
437
442
|
},
|
|
438
443
|
morphTo(target, options2) {
|
|
444
|
+
const interruptBounds = morphResolve !== null ? { scale, offsetX, offsetY } : null;
|
|
439
445
|
if (morphResolve !== null) {
|
|
440
446
|
engine.completeMorph();
|
|
441
447
|
morphResolve();
|
|
442
448
|
morphResolve = null;
|
|
443
449
|
morphAlpha = 0;
|
|
444
|
-
|
|
445
|
-
|
|
450
|
+
morphBoundsA = null;
|
|
451
|
+
morphBoundsB = null;
|
|
446
452
|
}
|
|
447
453
|
morphDurationMs = options2?.duration ?? DEFAULT_MORPH_DURATION_MS;
|
|
448
|
-
morphTarget = target;
|
|
449
454
|
morphAlpha = 0;
|
|
450
|
-
|
|
451
|
-
if (currentSkeleton.length >= 2) {
|
|
452
|
-
skeletonCanvasA = new OffscreenCanvas(canvas.width, canvas.height);
|
|
453
|
-
const ctxA = skeletonCanvasA.getContext("2d");
|
|
454
|
-
ctxA.strokeStyle = `rgba(${hexToRgbComponents(opts.skeletonColor)},${DEFAULT_SKELETON_OPACITY})`;
|
|
455
|
-
ctxA.lineWidth = 1.5;
|
|
456
|
-
ctxA.beginPath();
|
|
457
|
-
const first = currentSkeleton[0];
|
|
458
|
-
ctxA.moveTo(first.x * scale + offsetX, first.y * scale + offsetY);
|
|
459
|
-
for (let i = 1; i < currentSkeleton.length; i++) {
|
|
460
|
-
const p = currentSkeleton[i];
|
|
461
|
-
ctxA.lineTo(p.x * scale + offsetX, p.y * scale + offsetY);
|
|
462
|
-
}
|
|
463
|
-
ctxA.stroke();
|
|
464
|
-
}
|
|
455
|
+
morphBoundsA = interruptBounds ?? computeBoundaries(engine.getSarmalSkeleton()) ?? { scale, offsetX, offsetY };
|
|
465
456
|
engine.startMorph(target, options2?.morphStrategy);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const firstB = morphTarget.fn(0, 0, {});
|
|
475
|
-
skeletonCtx.moveTo(firstB.x * scale + offsetX, firstB.y * scale + offsetY);
|
|
476
|
-
for (let i = 1; i <= samples; i++) {
|
|
477
|
-
const t = (i / samples) * period;
|
|
478
|
-
const p = morphTarget.fn(t, 0, {});
|
|
479
|
-
skeletonCtx.lineTo(p.x * scale + offsetX, p.y * scale + offsetY);
|
|
480
|
-
}
|
|
481
|
-
skeletonCtx.stroke();
|
|
482
|
-
}
|
|
457
|
+
const period = target.period ?? Math.PI * 2;
|
|
458
|
+
const samples = Math.max(50, Math.round(period * 20));
|
|
459
|
+
const skeletonFn = target.skeletonFn ?? ((t) => target.fn(t, 0, {}));
|
|
460
|
+
const skeletonB = Array.from(
|
|
461
|
+
{ length: samples + 1 },
|
|
462
|
+
(_, i) => skeletonFn(i / samples * period)
|
|
463
|
+
);
|
|
464
|
+
morphBoundsB = computeBoundaries(skeletonB) ?? { scale, offsetX, offsetY };
|
|
483
465
|
return new Promise((resolve) => {
|
|
484
466
|
morphResolve = resolve;
|
|
485
467
|
});
|
|
486
|
-
}
|
|
468
|
+
}
|
|
487
469
|
};
|
|
488
470
|
}
|
|
489
471
|
|
|
490
472
|
// src/curves.ts
|
|
491
473
|
var TWO_PI2 = Math.PI * 2;
|
|
492
474
|
function artemis2(t, _time, _params) {
|
|
493
|
-
const a = 0.35,
|
|
494
|
-
|
|
495
|
-
ox = 0.175;
|
|
496
|
-
const s = Math.sin(t),
|
|
497
|
-
c = Math.cos(t);
|
|
475
|
+
const a = 0.35, b = 0.15, ox = 0.175;
|
|
476
|
+
const s = Math.sin(t), c = Math.cos(t);
|
|
498
477
|
const denom = 1 + s * s;
|
|
499
478
|
return {
|
|
500
|
-
x:
|
|
501
|
-
y:
|
|
479
|
+
x: c * (1 + a * c) / denom - ox,
|
|
480
|
+
y: s * c * (1 + b * c) / denom
|
|
502
481
|
};
|
|
503
482
|
}
|
|
504
483
|
function epitrochoid7(t, _time, _params) {
|
|
505
484
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
506
485
|
return {
|
|
507
486
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
508
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
487
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
509
488
|
};
|
|
510
489
|
}
|
|
511
490
|
function epitrochoid7Skeleton(t) {
|
|
512
491
|
const d = 1.275;
|
|
513
492
|
return {
|
|
514
493
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
515
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
494
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
516
495
|
};
|
|
517
496
|
}
|
|
518
497
|
function astroid(t, _time, _params) {
|
|
@@ -520,56 +499,55 @@ function astroid(t, _time, _params) {
|
|
|
520
499
|
const s = Math.sin(t);
|
|
521
500
|
return {
|
|
522
501
|
x: c * c * c,
|
|
523
|
-
y: s * s * s
|
|
502
|
+
y: s * s * s
|
|
524
503
|
};
|
|
525
504
|
}
|
|
526
505
|
function deltoid(t, _time, _params) {
|
|
527
506
|
return {
|
|
528
507
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
529
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
508
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
530
509
|
};
|
|
531
510
|
}
|
|
532
511
|
function rose5(t, _time, _params) {
|
|
533
512
|
const r = Math.cos(5 * t);
|
|
534
513
|
return {
|
|
535
514
|
x: r * Math.cos(t),
|
|
536
|
-
y: r * Math.sin(t)
|
|
515
|
+
y: r * Math.sin(t)
|
|
537
516
|
};
|
|
538
517
|
}
|
|
539
518
|
function rose3(t, _time, _params) {
|
|
540
519
|
const r = Math.cos(3 * t);
|
|
541
520
|
return {
|
|
542
521
|
x: r * Math.cos(t),
|
|
543
|
-
y: r * Math.sin(t)
|
|
522
|
+
y: r * Math.sin(t)
|
|
544
523
|
};
|
|
545
524
|
}
|
|
546
525
|
function lissajous32(t, time, _params) {
|
|
547
526
|
const phi = time * 0.45;
|
|
548
527
|
return {
|
|
549
528
|
x: Math.sin(3 * t + phi),
|
|
550
|
-
y: Math.sin(2 * t)
|
|
529
|
+
y: Math.sin(2 * t)
|
|
551
530
|
};
|
|
552
531
|
}
|
|
553
532
|
function lissajous43(t, time, _params) {
|
|
554
533
|
const phi = time * 0.38;
|
|
555
534
|
return {
|
|
556
535
|
x: Math.sin(4 * t + phi),
|
|
557
|
-
y: Math.sin(3 * t)
|
|
536
|
+
y: Math.sin(3 * t)
|
|
558
537
|
};
|
|
559
538
|
}
|
|
560
539
|
function epicycloid3(t, _time, _params) {
|
|
561
540
|
return {
|
|
562
541
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
563
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
542
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
564
543
|
};
|
|
565
544
|
}
|
|
566
545
|
function lame(t, time, _params) {
|
|
567
546
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
568
|
-
const c = Math.cos(t),
|
|
569
|
-
s = Math.sin(t);
|
|
547
|
+
const c = Math.cos(t), s = Math.sin(t);
|
|
570
548
|
return {
|
|
571
549
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
572
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
550
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
573
551
|
};
|
|
574
552
|
}
|
|
575
553
|
var curves = {
|
|
@@ -577,66 +555,66 @@ var curves = {
|
|
|
577
555
|
name: "Artemis II",
|
|
578
556
|
fn: artemis2,
|
|
579
557
|
period: TWO_PI2,
|
|
580
|
-
speed: 0.7
|
|
558
|
+
speed: 0.7
|
|
581
559
|
},
|
|
582
560
|
epitrochoid7: {
|
|
583
561
|
name: "Epitrochoid",
|
|
584
562
|
fn: epitrochoid7,
|
|
585
563
|
period: TWO_PI2,
|
|
586
564
|
speed: 1.4,
|
|
587
|
-
skeletonFn: epitrochoid7Skeleton
|
|
565
|
+
skeletonFn: epitrochoid7Skeleton
|
|
588
566
|
},
|
|
589
567
|
astroid: {
|
|
590
568
|
name: "Astroid",
|
|
591
569
|
fn: astroid,
|
|
592
570
|
period: TWO_PI2,
|
|
593
|
-
speed: 1.1
|
|
571
|
+
speed: 1.1
|
|
594
572
|
},
|
|
595
573
|
deltoid: {
|
|
596
574
|
name: "Deltoid",
|
|
597
575
|
fn: deltoid,
|
|
598
576
|
period: TWO_PI2,
|
|
599
|
-
speed: 0.9
|
|
577
|
+
speed: 0.9
|
|
600
578
|
},
|
|
601
579
|
rose5: {
|
|
602
580
|
name: "Rose (n=5)",
|
|
603
581
|
fn: rose5,
|
|
604
582
|
period: TWO_PI2,
|
|
605
|
-
speed: 1
|
|
583
|
+
speed: 1
|
|
606
584
|
},
|
|
607
585
|
rose3: {
|
|
608
586
|
name: "Rose (n=3)",
|
|
609
587
|
fn: rose3,
|
|
610
588
|
period: TWO_PI2,
|
|
611
|
-
speed: 1.15
|
|
589
|
+
speed: 1.15
|
|
612
590
|
},
|
|
613
591
|
lissajous32: {
|
|
614
592
|
name: "Lissajous 3:2",
|
|
615
593
|
fn: lissajous32,
|
|
616
594
|
period: TWO_PI2,
|
|
617
595
|
speed: 2,
|
|
618
|
-
skeleton: "live"
|
|
596
|
+
skeleton: "live"
|
|
619
597
|
},
|
|
620
598
|
lissajous43: {
|
|
621
599
|
name: "Lissajous 4:3",
|
|
622
600
|
fn: lissajous43,
|
|
623
601
|
period: TWO_PI2,
|
|
624
602
|
speed: 1.8,
|
|
625
|
-
skeleton: "live"
|
|
603
|
+
skeleton: "live"
|
|
626
604
|
},
|
|
627
605
|
epicycloid3: {
|
|
628
606
|
name: "Epicycloid (n=3)",
|
|
629
607
|
fn: epicycloid3,
|
|
630
608
|
period: TWO_PI2,
|
|
631
|
-
speed: 0.75
|
|
609
|
+
speed: 0.75
|
|
632
610
|
},
|
|
633
611
|
lame: {
|
|
634
612
|
name: "Lam\xE9 Curve",
|
|
635
613
|
fn: lame,
|
|
636
614
|
period: TWO_PI2,
|
|
637
615
|
speed: 1,
|
|
638
|
-
skeleton: "live"
|
|
639
|
-
}
|
|
616
|
+
skeleton: "live"
|
|
617
|
+
}
|
|
640
618
|
};
|
|
641
619
|
|
|
642
620
|
// src/index.ts
|
|
@@ -659,12 +637,12 @@ function init() {
|
|
|
659
637
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
660
638
|
}
|
|
661
639
|
const sarmal = createSarmal(canvas, curveDef, {
|
|
662
|
-
...
|
|
663
|
-
...
|
|
664
|
-
...
|
|
665
|
-
...
|
|
666
|
-
...
|
|
667
|
-
...
|
|
640
|
+
...canvas.dataset.trailColor && { trailColor: canvas.dataset.trailColor },
|
|
641
|
+
...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
|
|
642
|
+
...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
|
|
643
|
+
...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
|
|
644
|
+
...canvas.dataset.glowSize && { glowSize: parseInt(canvas.dataset.glowSize, 10) },
|
|
645
|
+
...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) }
|
|
668
646
|
});
|
|
669
647
|
sarmal.start();
|
|
670
648
|
});
|
|
@@ -675,4 +653,4 @@ if (document.readyState === "loading") {
|
|
|
675
653
|
init();
|
|
676
654
|
}
|
|
677
655
|
//# sourceMappingURL=auto-init.cjs.map
|
|
678
|
-
//# sourceMappingURL=auto-init.cjs.map
|
|
656
|
+
//# sourceMappingURL=auto-init.cjs.map
|