@algorisys/tinyfly 0.92.0 → 0.94.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/README.md +7 -6
- package/bin/tinyfly.mjs +34 -1
- package/docs/2d-animation-roadmap.md +191 -0
- package/docs/3d-rotations.md +164 -0
- package/docs/3d-support-plan.md +628 -0
- package/docs/DEPLOYMENT.md +414 -0
- package/docs/acting.md +529 -0
- package/docs/api-reference.md +2353 -0
- package/docs/camera.md +94 -0
- package/docs/cartoon-hands.md +96 -0
- package/docs/character-system-m1.md +218 -0
- package/docs/character-system-plan.md +384 -0
- package/docs/dance.md +315 -0
- package/docs/editor-guide.md +1249 -0
- package/docs/examples.md +765 -0
- package/docs/extending.md +168 -0
- package/docs/file-format.md +690 -0
- package/docs/getting-started.md +314 -0
- package/docs/grid-and-snapping.md +64 -0
- package/docs/gsap-compat.md +1241 -0
- package/docs/llm-guide.md +131 -0
- package/docs/maps.md +116 -0
- package/docs/onion-skinning.md +41 -0
- package/docs/pen-tool.md +65 -0
- package/docs/polygon-star.md +44 -0
- package/docs/scene-3d.md +299 -0
- package/docs/scroll-animation.md +314 -0
- package/docs/shape-morph.md +61 -0
- package/docs/sprite-sheet-export.md +54 -0
- package/docs/symbols-and-library.md +137 -0
- package/docs/teaching.md +348 -0
- package/docs/video-rendering.md +728 -0
- package/lib/addons/adapters.js +22 -18
- package/lib/addons/characters.js +3045 -2024
- package/lib/addons/target-properties-BtN9skb-.js +142 -0
- package/lib/browser/tinyfly.iife.js +9 -4
- package/lib/browser/tinyfly.js +6968 -5817
- package/lib/browser/tinyfly.umd.js +9 -4
- package/lib/engine/tinyfly-engine.js +286 -258
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +6 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/adapters/canvas/target-properties.d.ts +68 -0
- package/lib/types/characters/acting/beat-check.d.ts +102 -0
- package/lib/types/characters/acting/custom.d.ts +66 -0
- package/lib/types/characters/acting/gags.d.ts +10 -0
- package/lib/types/characters/acting/hand-path.d.ts +35 -0
- package/lib/types/characters/acting/index.d.ts +4 -0
- package/lib/types/characters/acting/persona.d.ts +93 -0
- package/lib/types/characters/acting/script.d.ts +75 -11
- package/lib/types/characters/capabilities.d.ts +61 -0
- package/lib/types/characters/code-panel.d.ts +201 -0
- package/lib/types/characters/figure-actions.d.ts +12 -0
- package/lib/types/characters/figure-props.d.ts +87 -0
- package/lib/types/characters/gaits.d.ts +8 -0
- package/lib/types/characters/index.d.ts +3 -0
- package/lib/types/characters/stick-figure.d.ts +9 -2
- package/lib/types/engine/authoring/did-you-mean.d.ts +14 -0
- package/lib/types/engine/authoring/index.d.ts +1 -0
- package/llms-full.txt +12631 -0
- package/llms.txt +57 -0
- package/package.json +6 -2
- package/skills/tinyfly/SKILL.md +67 -0
- package/lib/addons/camera-C7bZOWMB.js +0 -33
package/docs/examples.md
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
# Code Examples
|
|
2
|
+
|
|
3
|
+
Practical examples for common animation patterns using the tinyfly API.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Basic: Fade In](#basic-fade-in)
|
|
8
|
+
- [Multi-Property Animation](#multi-property-animation)
|
|
9
|
+
- [Infinite Looping](#infinite-looping)
|
|
10
|
+
- [Color Animation](#color-animation)
|
|
11
|
+
- [Custom Cubic Bezier Easing](#custom-cubic-bezier-easing)
|
|
12
|
+
- [Load from External JSON](#load-from-external-json)
|
|
13
|
+
- [Canvas Rendering](#canvas-rendering)
|
|
14
|
+
- [SVG Animation](#svg-animation)
|
|
15
|
+
- [Multi-Scene Sequence](#multi-scene-sequence)
|
|
16
|
+
- [Programmatic Animation Builder](#programmatic-animation-builder)
|
|
17
|
+
- [Motion Path](#motion-path)
|
|
18
|
+
- [Embed with IIFE Player](#embed-with-iife-player)
|
|
19
|
+
- [Video from Code](#video-from-code)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Basic: Fade In
|
|
24
|
+
|
|
25
|
+
The simplest animation — fade an element from invisible to visible.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Timeline, createTrack } from '@algorisys/tinyfly'
|
|
29
|
+
import { DOMAdapter } from '@algorisys/tinyfly/adapters'
|
|
30
|
+
|
|
31
|
+
const timeline = new Timeline({
|
|
32
|
+
id: 'fade-in',
|
|
33
|
+
config: { duration: 1000 }
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
timeline.addTrack(createTrack({
|
|
37
|
+
id: 'opacity',
|
|
38
|
+
target: 'box',
|
|
39
|
+
property: 'opacity',
|
|
40
|
+
keyframes: [
|
|
41
|
+
{ time: 0, value: 0 },
|
|
42
|
+
{ time: 1000, value: 1, easing: 'ease-out' }
|
|
43
|
+
]
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
// Set up DOM rendering
|
|
47
|
+
const adapter = new DOMAdapter()
|
|
48
|
+
adapter.registerTarget('box', document.getElementById('my-box'))
|
|
49
|
+
|
|
50
|
+
timeline.onUpdate = (state) => adapter.applyState(state)
|
|
51
|
+
timeline.play()
|
|
52
|
+
|
|
53
|
+
// Animation loop
|
|
54
|
+
function animate() {
|
|
55
|
+
timeline.tick(16.67)
|
|
56
|
+
if (timeline.playbackState === 'playing') {
|
|
57
|
+
requestAnimationFrame(animate)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
requestAnimationFrame(animate)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Multi-Property Animation
|
|
66
|
+
|
|
67
|
+
Animate position, opacity, and rotation simultaneously.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Timeline, createTrack } from '@algorisys/tinyfly'
|
|
71
|
+
|
|
72
|
+
const timeline = new Timeline({
|
|
73
|
+
id: 'multi-prop',
|
|
74
|
+
config: { duration: 2000 }
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Move horizontally
|
|
78
|
+
timeline.addTrack(createTrack({
|
|
79
|
+
id: 'move-x',
|
|
80
|
+
target: 'box',
|
|
81
|
+
property: 'x',
|
|
82
|
+
keyframes: [
|
|
83
|
+
{ time: 0, value: 0 },
|
|
84
|
+
{ time: 2000, value: 300, easing: 'ease-in-out' }
|
|
85
|
+
]
|
|
86
|
+
}))
|
|
87
|
+
|
|
88
|
+
// Fade in
|
|
89
|
+
timeline.addTrack(createTrack({
|
|
90
|
+
id: 'fade',
|
|
91
|
+
target: 'box',
|
|
92
|
+
property: 'opacity',
|
|
93
|
+
keyframes: [
|
|
94
|
+
{ time: 0, value: 0 },
|
|
95
|
+
{ time: 500, value: 1, easing: 'ease-out' }
|
|
96
|
+
]
|
|
97
|
+
}))
|
|
98
|
+
|
|
99
|
+
// Rotate
|
|
100
|
+
timeline.addTrack(createTrack({
|
|
101
|
+
id: 'rotate',
|
|
102
|
+
target: 'box',
|
|
103
|
+
property: 'rotation',
|
|
104
|
+
keyframes: [
|
|
105
|
+
{ time: 0, value: 0 },
|
|
106
|
+
{ time: 2000, value: 360, easing: 'ease-in-out' }
|
|
107
|
+
]
|
|
108
|
+
}))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Infinite Looping
|
|
114
|
+
|
|
115
|
+
Create an animation that loops forever with a ping-pong (alternate) effect.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const timeline = new Timeline({
|
|
119
|
+
id: 'pulse',
|
|
120
|
+
config: {
|
|
121
|
+
duration: 800,
|
|
122
|
+
loop: -1, // Infinite loop
|
|
123
|
+
alternate: true // Reverse direction each loop
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
timeline.addTrack(createTrack({
|
|
128
|
+
id: 'scale-x',
|
|
129
|
+
target: 'box',
|
|
130
|
+
property: 'scaleX',
|
|
131
|
+
keyframes: [
|
|
132
|
+
{ time: 0, value: 1 },
|
|
133
|
+
{ time: 800, value: 1.2, easing: 'ease-in-out' }
|
|
134
|
+
]
|
|
135
|
+
}))
|
|
136
|
+
|
|
137
|
+
timeline.addTrack(createTrack({
|
|
138
|
+
id: 'scale-y',
|
|
139
|
+
target: 'box',
|
|
140
|
+
property: 'scaleY',
|
|
141
|
+
keyframes: [
|
|
142
|
+
{ time: 0, value: 1 },
|
|
143
|
+
{ time: 800, value: 1.2, easing: 'ease-in-out' }
|
|
144
|
+
]
|
|
145
|
+
}))
|
|
146
|
+
|
|
147
|
+
// This will pulse smoothly: grow → shrink → grow → shrink → ...
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Color Animation
|
|
153
|
+
|
|
154
|
+
Smoothly transition between colors.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const timeline = new Timeline({
|
|
158
|
+
id: 'color-cycle',
|
|
159
|
+
config: { duration: 3000, loop: -1 }
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
timeline.addTrack(createTrack({
|
|
163
|
+
id: 'bg-color',
|
|
164
|
+
target: 'box',
|
|
165
|
+
property: 'fill',
|
|
166
|
+
keyframes: [
|
|
167
|
+
{ time: 0, value: '#4a9eff' }, // Blue
|
|
168
|
+
{ time: 1000, value: '#ff4a4a' }, // Red
|
|
169
|
+
{ time: 2000, value: '#4aff4a' }, // Green
|
|
170
|
+
{ time: 3000, value: '#4a9eff' } // Back to blue
|
|
171
|
+
]
|
|
172
|
+
}))
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The engine automatically detects color values and uses color interpolation (blending in RGB space).
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Custom Cubic Bezier Easing
|
|
180
|
+
|
|
181
|
+
Define precise easing curves using cubic bezier control points.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { createCubicBezier } from '@algorisys/tinyfly'
|
|
185
|
+
|
|
186
|
+
// Create a custom "bounce" feel
|
|
187
|
+
const bounceEase = createCubicBezier([0.68, -0.55, 0.265, 1.55])
|
|
188
|
+
|
|
189
|
+
// Use in keyframes with the object syntax
|
|
190
|
+
const timeline = new Timeline({
|
|
191
|
+
id: 'custom-ease',
|
|
192
|
+
config: { duration: 1000 }
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
timeline.addTrack(createTrack({
|
|
196
|
+
id: 'move',
|
|
197
|
+
target: 'box',
|
|
198
|
+
property: 'y',
|
|
199
|
+
keyframes: [
|
|
200
|
+
{ time: 0, value: 0 },
|
|
201
|
+
{
|
|
202
|
+
time: 1000,
|
|
203
|
+
value: 200,
|
|
204
|
+
easing: {
|
|
205
|
+
type: 'cubic-bezier',
|
|
206
|
+
points: [0.68, -0.55, 0.265, 1.55]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
}))
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Load from External JSON
|
|
216
|
+
|
|
217
|
+
Load a previously exported animation from a JSON file.
|
|
218
|
+
|
|
219
|
+
### Using TinyflyPlayer
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { TinyflyPlayer } from '@algorisys/tinyfly/player'
|
|
223
|
+
|
|
224
|
+
const player = new TinyflyPlayer('#animation-container', {
|
|
225
|
+
loop: -1,
|
|
226
|
+
autoplay: true
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
// Load from URL
|
|
230
|
+
await player.load('./my-animation.json')
|
|
231
|
+
|
|
232
|
+
// Controls
|
|
233
|
+
player.pause()
|
|
234
|
+
player.seek(500)
|
|
235
|
+
player.setSpeed(2)
|
|
236
|
+
player.play()
|
|
237
|
+
|
|
238
|
+
// Cleanup when done
|
|
239
|
+
player.destroy()
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Using Serialization Directly
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { fromJSON } from '@algorisys/tinyfly'
|
|
246
|
+
|
|
247
|
+
const response = await fetch('./my-animation.json')
|
|
248
|
+
const json = await response.text()
|
|
249
|
+
const timeline = fromJSON(json)
|
|
250
|
+
|
|
251
|
+
timeline.play()
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Animation JSON Format
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"id": "my-animation",
|
|
259
|
+
"config": {
|
|
260
|
+
"duration": 2000,
|
|
261
|
+
"loop": -1
|
|
262
|
+
},
|
|
263
|
+
"tracks": [
|
|
264
|
+
{
|
|
265
|
+
"id": "track-1",
|
|
266
|
+
"target": "box",
|
|
267
|
+
"property": "opacity",
|
|
268
|
+
"keyframes": [
|
|
269
|
+
{ "time": 0, "value": 0 },
|
|
270
|
+
{ "time": 1000, "value": 1, "easing": "ease-out" },
|
|
271
|
+
{ "time": 2000, "value": 0, "easing": "ease-in" }
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Canvas Rendering
|
|
281
|
+
|
|
282
|
+
Animate shapes on a `<canvas>` element.
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import { Timeline, createTrack } from '@algorisys/tinyfly'
|
|
286
|
+
import { CanvasAdapter } from '@algorisys/tinyfly/adapters'
|
|
287
|
+
|
|
288
|
+
const canvas = document.getElementById('canvas') as HTMLCanvasElement
|
|
289
|
+
const ctx = canvas.getContext('2d')!
|
|
290
|
+
const adapter = new CanvasAdapter()
|
|
291
|
+
|
|
292
|
+
// Register shapes
|
|
293
|
+
adapter.registerTarget('box', {
|
|
294
|
+
type: 'rect',
|
|
295
|
+
x: 50, y: 50,
|
|
296
|
+
width: 80, height: 80,
|
|
297
|
+
fillStyle: '#4a9eff',
|
|
298
|
+
borderRadius: 8
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
adapter.registerTarget('ball', {
|
|
302
|
+
type: 'circle',
|
|
303
|
+
x: 200, y: 100,
|
|
304
|
+
radius: 30,
|
|
305
|
+
fillStyle: '#ff4a4a'
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
adapter.registerTarget('label', {
|
|
309
|
+
type: 'text',
|
|
310
|
+
x: 150, y: 180,
|
|
311
|
+
text: 'Hello!',
|
|
312
|
+
fontSize: 24,
|
|
313
|
+
fontFamily: 'Arial',
|
|
314
|
+
fillStyle: '#ffffff',
|
|
315
|
+
textAlign: 'center'
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
// Create timeline
|
|
319
|
+
const timeline = new Timeline({
|
|
320
|
+
id: 'canvas-demo',
|
|
321
|
+
config: { duration: 2000, loop: -1, alternate: true }
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
timeline.addTrack(createTrack({
|
|
325
|
+
id: 'box-x',
|
|
326
|
+
target: 'box',
|
|
327
|
+
property: 'x',
|
|
328
|
+
keyframes: [
|
|
329
|
+
{ time: 0, value: 50 },
|
|
330
|
+
{ time: 2000, value: 250, easing: 'ease-in-out' }
|
|
331
|
+
]
|
|
332
|
+
}))
|
|
333
|
+
|
|
334
|
+
timeline.addTrack(createTrack({
|
|
335
|
+
id: 'ball-opacity',
|
|
336
|
+
target: 'ball',
|
|
337
|
+
property: 'opacity',
|
|
338
|
+
keyframes: [
|
|
339
|
+
{ time: 0, value: 1 },
|
|
340
|
+
{ time: 1000, value: 0.3, easing: 'ease-in-out' },
|
|
341
|
+
{ time: 2000, value: 1, easing: 'ease-in-out' }
|
|
342
|
+
]
|
|
343
|
+
}))
|
|
344
|
+
|
|
345
|
+
// Animation loop
|
|
346
|
+
timeline.onUpdate = (state) => adapter.applyState(state)
|
|
347
|
+
timeline.play()
|
|
348
|
+
|
|
349
|
+
function animate() {
|
|
350
|
+
timeline.tick(16.67)
|
|
351
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
352
|
+
adapter.render(ctx)
|
|
353
|
+
requestAnimationFrame(animate)
|
|
354
|
+
}
|
|
355
|
+
requestAnimationFrame(animate)
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Canvas Gradients
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
adapter.registerTarget('gradient-box', {
|
|
362
|
+
type: 'rect',
|
|
363
|
+
x: 50, y: 50,
|
|
364
|
+
width: 200, height: 100,
|
|
365
|
+
fillStyle: {
|
|
366
|
+
type: 'linear',
|
|
367
|
+
angle: 45,
|
|
368
|
+
stops: [
|
|
369
|
+
{ offset: 0, color: '#4a9eff' },
|
|
370
|
+
{ offset: 1, color: '#ff4a4a' }
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## SVG Animation
|
|
379
|
+
|
|
380
|
+
Animate SVG elements directly.
|
|
381
|
+
|
|
382
|
+
```html
|
|
383
|
+
<svg id="my-svg" width="300" height="200">
|
|
384
|
+
<circle id="ball" cx="50" cy="100" r="20" fill="#4a9eff" />
|
|
385
|
+
<rect id="box" x="200" y="75" width="50" height="50" fill="#ff4a4a" />
|
|
386
|
+
</svg>
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
import { Timeline, createTrack } from '@algorisys/tinyfly'
|
|
391
|
+
import { SVGAdapter } from '@algorisys/tinyfly/adapters'
|
|
392
|
+
|
|
393
|
+
const adapter = new SVGAdapter()
|
|
394
|
+
adapter.registerTarget('ball', document.getElementById('ball') as SVGElement)
|
|
395
|
+
adapter.registerTarget('box', document.getElementById('box') as SVGElement)
|
|
396
|
+
|
|
397
|
+
const timeline = new Timeline({
|
|
398
|
+
id: 'svg-demo',
|
|
399
|
+
config: { duration: 2000, loop: -1 }
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
// Animate circle position
|
|
403
|
+
timeline.addTrack(createTrack({
|
|
404
|
+
id: 'ball-cx',
|
|
405
|
+
target: 'ball',
|
|
406
|
+
property: 'cx',
|
|
407
|
+
keyframes: [
|
|
408
|
+
{ time: 0, value: 50 },
|
|
409
|
+
{ time: 2000, value: 250, easing: 'ease-in-out' }
|
|
410
|
+
]
|
|
411
|
+
}))
|
|
412
|
+
|
|
413
|
+
// Animate rect fill color
|
|
414
|
+
timeline.addTrack(createTrack({
|
|
415
|
+
id: 'box-fill',
|
|
416
|
+
target: 'box',
|
|
417
|
+
property: 'fill',
|
|
418
|
+
keyframes: [
|
|
419
|
+
{ time: 0, value: '#ff4a4a' },
|
|
420
|
+
{ time: 1000, value: '#4aff4a' },
|
|
421
|
+
{ time: 2000, value: '#ff4a4a' }
|
|
422
|
+
]
|
|
423
|
+
}))
|
|
424
|
+
|
|
425
|
+
timeline.onUpdate = (state) => adapter.applyState(state)
|
|
426
|
+
timeline.play()
|
|
427
|
+
|
|
428
|
+
function animate() {
|
|
429
|
+
timeline.tick(16.67)
|
|
430
|
+
if (timeline.playbackState === 'playing') {
|
|
431
|
+
requestAnimationFrame(animate)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
requestAnimationFrame(animate)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
## Multi-Scene Sequence
|
|
440
|
+
|
|
441
|
+
Play multiple scenes in order with transitions between them.
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
import { TinyflySequencer } from '@algorisys/tinyfly/player'
|
|
445
|
+
|
|
446
|
+
const sequencer = new TinyflySequencer('#container', {
|
|
447
|
+
loop: -1,
|
|
448
|
+
onSceneChange: (index) => {
|
|
449
|
+
console.log(`Playing scene ${index}`)
|
|
450
|
+
}
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
await sequencer.load({
|
|
454
|
+
id: 'my-sequence',
|
|
455
|
+
name: 'Demo Sequence',
|
|
456
|
+
canvas: { width: 400, height: 300 },
|
|
457
|
+
scenes: [
|
|
458
|
+
{
|
|
459
|
+
id: 'intro',
|
|
460
|
+
name: 'Intro',
|
|
461
|
+
elements: [
|
|
462
|
+
{
|
|
463
|
+
type: 'rect', name: 'box',
|
|
464
|
+
x: 50, y: 50, width: 100, height: 100,
|
|
465
|
+
rotation: 0, opacity: 1,
|
|
466
|
+
html: '<div data-tinyfly="box" style="position:absolute;left:50px;top:50px;width:100px;height:100px;background:#4a9eff;"></div>'
|
|
467
|
+
}
|
|
468
|
+
],
|
|
469
|
+
timeline: {
|
|
470
|
+
id: 'intro-tl',
|
|
471
|
+
config: { duration: 1000 },
|
|
472
|
+
tracks: [{
|
|
473
|
+
id: 't1', target: 'box', property: 'opacity',
|
|
474
|
+
keyframes: [
|
|
475
|
+
{ time: 0, value: 0 },
|
|
476
|
+
{ time: 1000, value: 1 }
|
|
477
|
+
]
|
|
478
|
+
}]
|
|
479
|
+
},
|
|
480
|
+
transition: { type: 'none', duration: 0 }
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
id: 'main',
|
|
484
|
+
name: 'Main',
|
|
485
|
+
elements: [
|
|
486
|
+
{
|
|
487
|
+
type: 'rect', name: 'circle',
|
|
488
|
+
x: 100, y: 75, width: 80, height: 80,
|
|
489
|
+
rotation: 0, opacity: 1,
|
|
490
|
+
html: '<div data-tinyfly="circle" style="position:absolute;left:100px;top:75px;width:80px;height:80px;background:#ff4a4a;border-radius:50%;"></div>'
|
|
491
|
+
}
|
|
492
|
+
],
|
|
493
|
+
timeline: {
|
|
494
|
+
id: 'main-tl',
|
|
495
|
+
config: { duration: 1500 },
|
|
496
|
+
tracks: [{
|
|
497
|
+
id: 't2', target: 'circle', property: 'x',
|
|
498
|
+
keyframes: [
|
|
499
|
+
{ time: 0, value: 100 },
|
|
500
|
+
{ time: 1500, value: 250 }
|
|
501
|
+
]
|
|
502
|
+
}]
|
|
503
|
+
},
|
|
504
|
+
transition: { type: 'fade', duration: 500 } // Fade in from previous scene
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
sequencer.play()
|
|
510
|
+
|
|
511
|
+
// Controls
|
|
512
|
+
sequencer.pause()
|
|
513
|
+
sequencer.goToScene(0) // Jump to first scene
|
|
514
|
+
sequencer.play()
|
|
515
|
+
|
|
516
|
+
// Cleanup
|
|
517
|
+
sequencer.destroy()
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
## Programmatic Animation Builder
|
|
523
|
+
|
|
524
|
+
Build animations entirely from code, without the visual editor.
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
import { Timeline, createTrack, toJSON } from '@algorisys/tinyfly'
|
|
528
|
+
|
|
529
|
+
function createBounceAnimation(targetName: string, duration = 1000): Timeline {
|
|
530
|
+
const timeline = new Timeline({
|
|
531
|
+
id: `bounce-${targetName}`,
|
|
532
|
+
config: { duration, loop: -1 }
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
// Vertical bounce
|
|
536
|
+
timeline.addTrack(createTrack({
|
|
537
|
+
id: `${targetName}-y`,
|
|
538
|
+
target: targetName,
|
|
539
|
+
property: 'y',
|
|
540
|
+
keyframes: [
|
|
541
|
+
{ time: 0, value: 0 },
|
|
542
|
+
{ time: duration * 0.4, value: -80, easing: 'ease-out' },
|
|
543
|
+
{ time: duration * 0.6, value: -80, easing: 'ease-in' },
|
|
544
|
+
{ time: duration, value: 0, easing: 'ease-in' }
|
|
545
|
+
]
|
|
546
|
+
}))
|
|
547
|
+
|
|
548
|
+
// Squash on landing
|
|
549
|
+
timeline.addTrack(createTrack({
|
|
550
|
+
id: `${targetName}-sx`,
|
|
551
|
+
target: targetName,
|
|
552
|
+
property: 'scaleX',
|
|
553
|
+
keyframes: [
|
|
554
|
+
{ time: 0, value: 1 },
|
|
555
|
+
{ time: duration * 0.1, value: 1.2 },
|
|
556
|
+
{ time: duration * 0.3, value: 0.9 },
|
|
557
|
+
{ time: duration * 0.5, value: 1 },
|
|
558
|
+
{ time: duration * 0.9, value: 0.9 },
|
|
559
|
+
{ time: duration, value: 1.2 }
|
|
560
|
+
]
|
|
561
|
+
}))
|
|
562
|
+
|
|
563
|
+
timeline.addTrack(createTrack({
|
|
564
|
+
id: `${targetName}-sy`,
|
|
565
|
+
target: targetName,
|
|
566
|
+
property: 'scaleY',
|
|
567
|
+
keyframes: [
|
|
568
|
+
{ time: 0, value: 1 },
|
|
569
|
+
{ time: duration * 0.1, value: 0.8 },
|
|
570
|
+
{ time: duration * 0.3, value: 1.1 },
|
|
571
|
+
{ time: duration * 0.5, value: 1 },
|
|
572
|
+
{ time: duration * 0.9, value: 1.1 },
|
|
573
|
+
{ time: duration, value: 0.8 }
|
|
574
|
+
]
|
|
575
|
+
}))
|
|
576
|
+
|
|
577
|
+
return timeline
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Create and export
|
|
581
|
+
const bounce = createBounceAnimation('ball', 800)
|
|
582
|
+
const json = toJSON(bounce)
|
|
583
|
+
console.log(json) // Save this JSON, use it with TinyflyPlayer later
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
---
|
|
587
|
+
|
|
588
|
+
## Motion Path
|
|
589
|
+
|
|
590
|
+
Animate an element along a curved SVG path.
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
import { Timeline } from '@algorisys/tinyfly'
|
|
594
|
+
import type { MotionPathTrack } from '@algorisys/tinyfly'
|
|
595
|
+
|
|
596
|
+
const timeline = new Timeline({
|
|
597
|
+
id: 'path-animation',
|
|
598
|
+
config: { duration: 3000, loop: -1 }
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
// Define a curved path (SVG path data)
|
|
602
|
+
const motionTrack: MotionPathTrack = {
|
|
603
|
+
id: 'follow-path',
|
|
604
|
+
target: 'ball',
|
|
605
|
+
property: 'motionPath',
|
|
606
|
+
motionPathConfig: {
|
|
607
|
+
pathData: 'M 50 150 C 100 50, 200 50, 250 150 S 400 250, 450 150',
|
|
608
|
+
autoRotate: true, // Element rotates to face direction of travel
|
|
609
|
+
rotateOffset: -90 // Adjust facing angle
|
|
610
|
+
},
|
|
611
|
+
keyframes: [
|
|
612
|
+
{ time: 0, value: 0, easing: 'ease-in-out' },
|
|
613
|
+
{ time: 3000, value: 1 } // 0 = start of path, 1 = end of path
|
|
614
|
+
]
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
timeline.addTrack(motionTrack)
|
|
618
|
+
|
|
619
|
+
// The timeline expands motionPath into:
|
|
620
|
+
// - motionPathX (x position on path)
|
|
621
|
+
// - motionPathY (y position on path)
|
|
622
|
+
// - motionPathRotate (tangent angle, when autoRotate is true)
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
## Embed with IIFE Player
|
|
628
|
+
|
|
629
|
+
For simple website embedding without a build system.
|
|
630
|
+
|
|
631
|
+
```html
|
|
632
|
+
<!DOCTYPE html>
|
|
633
|
+
<html>
|
|
634
|
+
<head>
|
|
635
|
+
<style>
|
|
636
|
+
#animation {
|
|
637
|
+
position: relative;
|
|
638
|
+
width: 300px;
|
|
639
|
+
height: 200px;
|
|
640
|
+
background: #1a1a1a;
|
|
641
|
+
overflow: hidden;
|
|
642
|
+
border-radius: 8px;
|
|
643
|
+
}
|
|
644
|
+
</style>
|
|
645
|
+
</head>
|
|
646
|
+
<body>
|
|
647
|
+
|
|
648
|
+
<div id="animation">
|
|
649
|
+
<div data-tinyfly="box"
|
|
650
|
+
style="position: absolute; left: 50px; top: 50px;
|
|
651
|
+
width: 60px; height: 60px; background: #4a9eff;
|
|
652
|
+
border-radius: 4px;">
|
|
653
|
+
</div>
|
|
654
|
+
<div data-tinyfly="circle"
|
|
655
|
+
style="position: absolute; left: 180px; top: 60px;
|
|
656
|
+
width: 40px; height: 40px; background: #ff4a4a;
|
|
657
|
+
border-radius: 50%;">
|
|
658
|
+
</div>
|
|
659
|
+
</div>
|
|
660
|
+
|
|
661
|
+
<!-- Include the built player -->
|
|
662
|
+
<script src="tinyfly-player.iife.js"></script>
|
|
663
|
+
<script>
|
|
664
|
+
// Inline animation data
|
|
665
|
+
const animation = {
|
|
666
|
+
id: "demo",
|
|
667
|
+
config: { duration: 2000, loop: -1, alternate: true },
|
|
668
|
+
tracks: [
|
|
669
|
+
{
|
|
670
|
+
id: "t1", target: "box", property: "x",
|
|
671
|
+
keyframes: [
|
|
672
|
+
{ time: 0, value: 50 },
|
|
673
|
+
{ time: 2000, value: 200, easing: "ease-in-out" }
|
|
674
|
+
]
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
id: "t2", target: "circle", property: "opacity",
|
|
678
|
+
keyframes: [
|
|
679
|
+
{ time: 0, value: 1 },
|
|
680
|
+
{ time: 1000, value: 0.2 },
|
|
681
|
+
{ time: 2000, value: 1 }
|
|
682
|
+
]
|
|
683
|
+
}
|
|
684
|
+
]
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
tinyfly.play('#animation', animation, {
|
|
688
|
+
loop: -1,
|
|
689
|
+
autoplay: true
|
|
690
|
+
});
|
|
691
|
+
</script>
|
|
692
|
+
|
|
693
|
+
</body>
|
|
694
|
+
</html>
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
Build the player with `npm run build:player` to generate `lib/player/tinyfly-player.iife.js`, or load it from the CDN: `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.94.0/cdn/tinyfly-player.iife.js`.
|
|
698
|
+
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
## Video from Code
|
|
702
|
+
|
|
703
|
+
Render a scene to MP4 in Node, without a browser, with
|
|
704
|
+
`npx tinyfly video scene.mjs`. The full guide is
|
|
705
|
+
[Rendering Video from Code](video-rendering.md). Runnable scenes are in
|
|
706
|
+
[`examples/headless-video/`](../examples/headless-video/):
|
|
707
|
+
|
|
708
|
+
| Scene | Shows |
|
|
709
|
+
|---|---|
|
|
710
|
+
| [`stick-figure.mjs`](../examples/headless-video/stick-figure.mjs) | Narration timing, the `characters` stick figure posed, walked and voiced by tracks, a per-scene backdrop, captions |
|
|
711
|
+
| [`bar-chart.mjs`](../examples/headless-video/bar-chart.mjs) | Timeline targets only: the whole animation is JSON |
|
|
712
|
+
| [`cairo-style.mjs`](../examples/headless-video/cairo-style.mjs) | Pure immediate mode: a duration and `draw(ctx, { time })` |
|
|
713
|
+
|
|
714
|
+
The smallest scene is a duration and a draw function:
|
|
715
|
+
|
|
716
|
+
```js
|
|
717
|
+
// hello.mjs → npx tinyfly video hello.mjs
|
|
718
|
+
import { getEasingFunction } from '@algorisys/tinyfly'
|
|
719
|
+
|
|
720
|
+
const ease = getEasingFunction('ease-out')
|
|
721
|
+
|
|
722
|
+
export default {
|
|
723
|
+
width: 640,
|
|
724
|
+
height: 360,
|
|
725
|
+
duration: 2000,
|
|
726
|
+
background: '#0f1115',
|
|
727
|
+
draw(ctx, { time }) {
|
|
728
|
+
const t = ease(Math.min(1, time / 1500))
|
|
729
|
+
ctx.fillStyle = '#4a9eff'
|
|
730
|
+
ctx.beginPath()
|
|
731
|
+
ctx.arc(80 + t * 480, 180, 40, 0, Math.PI * 2)
|
|
732
|
+
ctx.fill()
|
|
733
|
+
},
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
A code-drawn character animated by the timeline is a `custom` canvas target.
|
|
738
|
+
Tracks write into the values it declares in `props`:
|
|
739
|
+
|
|
740
|
+
```js
|
|
741
|
+
targets: {
|
|
742
|
+
figure: {
|
|
743
|
+
type: 'custom',
|
|
744
|
+
x: 500, y: 300, width: 120, height: 300,
|
|
745
|
+
props: { arm: 0 },
|
|
746
|
+
draw(ctx, target) {
|
|
747
|
+
// local coordinates; target.props.arm goes 0 → 1 as its track plays
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
timeline: {
|
|
752
|
+
id: 'wave',
|
|
753
|
+
config: { duration: 2000 },
|
|
754
|
+
tracks: [{ id: 'arm', target: 'figure', property: 'arm', keyframes: [{ time: 0, value: 0 }, { time: 600, value: 1 }] }],
|
|
755
|
+
},
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
In the browser, the Examples gallery's **Video** category has two live cards:
|
|
759
|
+
|
|
760
|
+
- **Narrated Scene**: the same idea. `planNarration()` times the lines,
|
|
761
|
+
`poseTracks()` turns named poses into keyframes, and a canvas is redrawn from
|
|
762
|
+
the time on every frame.
|
|
763
|
+
- **Stick Figure**: the `characters` figure on its own. It blends from pose to
|
|
764
|
+
pose, and can walk and talk.
|
|
765
|
+
|