-
-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add Code node documentation (#1023)
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"version": 0, | ||
"shared": { | ||
"background": null, | ||
"range": [ | ||
0, | ||
null | ||
], | ||
"size": { | ||
"x": 1920, | ||
"y": 1080 | ||
}, | ||
"audioOffset": 0 | ||
}, | ||
"preview": { | ||
"fps": 30, | ||
"resolutionScale": 1 | ||
}, | ||
"rendering": { | ||
"fps": 60, | ||
"resolutionScale": 2, | ||
"colorSpace": "srgb", | ||
"exporter": { | ||
"name": "@motion-canvas/core/image-sequence", | ||
"options": { | ||
"fileType": "image/png", | ||
"quality": 100, | ||
"groupByScene": false | ||
} | ||
}, | ||
"fileType": "image/png", | ||
"quality": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {makeProject} from '@motion-canvas/core'; | ||
import scene from './scenes/code?scene'; | ||
|
||
import {parser} from '@lezer/javascript'; | ||
import {Code, LezerHighlighter} from '@motion-canvas/2d'; | ||
|
||
Code.defaultHighlighter = new LezerHighlighter(parser); | ||
|
||
export default makeProject({ | ||
scenes: [scene], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": 1, | ||
"timeEvents": [], | ||
"seed": 3853578122 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {CODE, Code, lines, makeScene2D, word} from '@motion-canvas/2d'; | ||
import { | ||
DEFAULT, | ||
SimpleSignal, | ||
createRef, | ||
createSignal, | ||
easeOutCubic, | ||
waitFor, | ||
} from '@motion-canvas/core'; | ||
|
||
export default makeScene2D(function* (view) { | ||
const codeRef = createRef<Code>(); | ||
|
||
const radius = createSignal(1); | ||
const r2 = createSignal(() => radius() * radius()); | ||
const area = createSignal(() => Math.PI * r2()); | ||
|
||
const functionName = Code.createSignal('calculateArea'); | ||
|
||
const displayFloat = (signal: SimpleSignal<number, void>) => { | ||
return () => signal().toFixed(2).toString(); | ||
}; | ||
|
||
view.add( | ||
<Code | ||
fontSize={42} | ||
ref={codeRef} | ||
code={CODE`\ | ||
const radius = ${displayFloat(radius)}; | ||
area = ${functionName}(radius); // ${displayFloat(area)} | ||
const ${functionName} = () => { | ||
const r2 = radius * radius; // ${displayFloat(radius)} * ${displayFloat( | ||
radius, | ||
)} = ${displayFloat(r2)} | ||
return Math.PI * r2; | ||
}; | ||
`} | ||
/>, | ||
); | ||
|
||
yield* waitFor(2); | ||
yield* codeRef().selection(codeRef().findAllRanges(/radius/gi), 0.8); | ||
yield* waitFor(1); | ||
yield* codeRef().selection(DEFAULT, 0.8); | ||
yield* functionName('getAreaFromRadius', 1); | ||
yield* waitFor(2); | ||
yield* radius(10, 3, easeOutCubic); | ||
yield* waitFor(2); | ||
yield* codeRef().code.replace( | ||
lines(4, 5), | ||
CODE` return Math.PI * radius * radius;\n`, | ||
1, | ||
); | ||
yield* waitFor(1); | ||
yield* codeRef().code.remove(word(4, 1, 7), 1); | ||
yield* waitFor(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters