Skip to content

Commit 92bab90

Browse files
committed
DrawText & DrawTex with useAnimation
1 parent 32a3b10 commit 92bab90

5 files changed

Lines changed: 310 additions & 27 deletions

File tree

docs/docs/lib/animation.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,19 @@ const Impact = () => (
9292
`<DrawText />` renders text as animated SVG strokes using a supplied font file.
9393

9494
```tsx
95+
import { useAnimation, useVariable } from "../src/lib/animation"
9596
import { DrawText } from "../src/lib/animation/effect/draw-text"
97+
import { seconds } from "../src/lib/frame"
98+
99+
const Title = () => {
100+
const progress = useVariable(0)
96101

97-
<DrawText text="Hello" fontUrl="assets/Roboto.ttf" fontSize={96} />
102+
useAnimation(async (context) => {
103+
await context.move(progress).to(1, seconds(2))
104+
})
105+
106+
return <DrawText text="Hello" fontUrl="assets/Roboto.ttf" fontSize={96} progress={progress} />
107+
}
98108
```
99109

100110
## Effects: DrawTex
@@ -103,7 +113,19 @@ import { DrawText } from "../src/lib/animation/effect/draw-text"
103113
MathJax must be available in the build (this project uses a static import in `draw-text.tsx`).
104114

105115
```tsx
116+
import { useAnimation, useVariable } from "../src/lib/animation"
106117
import { DrawTex } from "../src/lib/animation/effect/draw-text"
118+
import { seconds } from "../src/lib/frame"
119+
120+
const Formula = () => {
121+
const progress = useVariable(0)
122+
123+
useAnimation(async (context) => {
124+
await context.move(progress).to(1, seconds(2))
125+
})
107126

108-
<DrawTex tex={"\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}"} fontSize={96} />
127+
return (
128+
<DrawTex tex={"\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}"} fontSize={96} progress={progress} />
129+
)
130+
}
109131
```

docs/i18n/ja/docusaurus-plugin-content-docs/current/lib/animation.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,19 @@ const Impact = () => (
9292
`<DrawText />` はフォントファイルを使ってテキストを SVG ストロークで描画します。
9393

9494
```tsx
95+
import { useAnimation, useVariable } from "../src/lib/animation"
9596
import { DrawText } from "../src/lib/animation/effect/draw-text"
97+
import { seconds } from "../src/lib/frame"
98+
99+
const Title = () => {
100+
const progress = useVariable(0)
96101

97-
<DrawText text="Hello" fontUrl="assets/Roboto.ttf" fontSize={96} />
102+
useAnimation(async (context) => {
103+
await context.move(progress).to(1, seconds(2))
104+
})
105+
106+
return <DrawText text="Hello" fontUrl="assets/Roboto.ttf" fontSize={96} progress={progress} />
107+
}
98108
```
99109

100110
## Effects: DrawTex
@@ -103,7 +113,19 @@ import { DrawText } from "../src/lib/animation/effect/draw-text"
103113
MathJax がビルドに含まれている必要があります(このプロジェクトでは `draw-text.tsx` で静的 import しています)。
104114

105115
```tsx
116+
import { useAnimation, useVariable } from "../src/lib/animation"
106117
import { DrawTex } from "../src/lib/animation/effect/draw-text"
118+
import { seconds } from "../src/lib/frame"
119+
120+
const Formula = () => {
121+
const progress = useVariable(0)
122+
123+
useAnimation(async (context) => {
124+
await context.move(progress).to(1, seconds(2))
125+
})
107126

108-
<DrawTex tex={"\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}"} fontSize={96} />
127+
return (
128+
<DrawTex tex={"\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}"} fontSize={96} progress={progress} />
129+
)
130+
}
109131
```

project/project.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { useAnimation, useVariable } from "../src/lib/animation"
12
import { DrawText } from "../src/lib/animation/effect/draw-text"
3+
import { BEZIER_SMOOTH } from "../src/lib/animation/functions"
24
import { Clip } from "../src/lib/clip"
35
import { seconds } from "../src/lib/frame"
46
import { FillFrame } from "../src/lib/layout/fill-frame"
@@ -13,13 +15,21 @@ export const PROJECT_SETTINGS: ProjectSettings = {
1315
}
1416

1517
const HelloScene = () => {
18+
const progress = useVariable(0)
19+
20+
useAnimation(async (context) => {
21+
await context.move(progress).to(1, seconds(2), BEZIER_SMOOTH)
22+
await context.sleep(seconds(1))
23+
await context.move(progress).to(0, seconds(2), BEZIER_SMOOTH)
24+
}, [])
25+
1626
return (
1727
<FillFrame style={{ alignItems: "center", justifyContent: "center" }}>
1828
<DrawText
1929
text="Hello, world!"
2030
fontUrl="assets/NotoSerifCJKJP-Medium.ttf"
2131
strokeWidth={2}
22-
durationFrames={seconds(2)}
32+
progress={progress}
2333
/>
2434
</FillFrame>
2535
)
@@ -29,7 +39,7 @@ export const PROJECT = () => {
2939
return (
3040
<Project>
3141
<TimeLine>
32-
<Clip label="Hello" duration={seconds(5)}>
42+
<Clip label="Hello">
3343
<HelloScene />
3444
</Clip>
3545
</TimeLine>

0 commit comments

Comments
 (0)