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