Getting Started
Installation
If you haven't already, install the Dart SDK
(tutorial).
You will also need to have and Git installed.
Then, you can install the ManimWeb CLI with:
pub global activate manim_web
That's it, the Manim Web CLI is installed.
If the command's output tells you need to add a folder to your PATH
environment variable, you'll need to do it.
For example, with linux/macos it's:
export PATH="$PATH":"$HOME/.pub-cache/bin"
Creating the project
You can use either the manimweb
command or the manim_web
command: they're
the same.
Create a project with the default template with:
manimweb init --directory {directory}
Replace {directory}
with the name of the directory to create.
Make sure the directory is empty or doesn't exist.
Then go to the directory ( cd {directory}
).
First scene with Manim Web
You can open the src/example.dart
in your favorite text editor.
Visual Studio Code with the Dart extension works really well.
Copy and paste the code below.
import 'package:manim_web/manim.dart';
class ExampleScene extends Scene {
@override
FutureOr<void> preload() {
Tex.preload('Hello World!');
}
@override
FutureOr<void> construct() async {
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
}
}
You can then start the dev server with:
manimweb dev --file src/example.dart --html src/example.html
The server should be running on localhost:8080
How it works
import 'package:manim_web/manim.dart';
...
On line 1, you import the whole Manim Web library. It allows you to use Scene
,
Tex
, FadeIn
.
import 'package:manim_web/manim.dart';
class ExampleScene extends Scene {
@override
FutureOr<void> preload() {
Tex.preload('Hello World!');
}
@override
FutureOr<void> construct() async {
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
}
}
On line 3, you create a scene: ExampleScene
.
Then, you define two methods: preload
and construct
on lines 5 and 10.
Both methods return a FutureOr<void>
which is either a Future
(asynchronous
result) or of type void
. The construct
method is also async
, it allows you
to use the await
keyword later.
The construct
method
First, look at the construct
method's body:
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
You first create some text "Hello World!".
The Tex
class is a Mobject
. Here, it represents text generated with .
You can also use math formulas with MathTex
.
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
Then, the tex
is scaled by 4 uniformly.
You can also scale differently along the x and y-axis with the scale
method.
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
Finally, the animation part:
You start by creating a new Animation
. It's a FadeIn
animation.
FadeOut
, ShowCreation
...Then, you play the animation with the play
method.
The play
method is part of the Scene
, so you could also write:
await this.play(FadeIn(tex));
With the this
keyword referring to the scene.
Also, you use await
to wait for the scene to play the animation.
Now, you should know how the construct
method works.
The preload
method
When running your animation, your browser can't use to generate the needed Math formulas and texts. You need to preload the results.
The preload
method is used for that, it doesn't run in your browser but
manimweb
runs it internally. It tells which text and formulas need to be
preloaded.
In this method, there is only one line:
Tex.preload('Hello World!');
You tell ManimWeb you will use Tex with the "Hello World!" text. Then, ManimWeb will run to generate the "Hello World!" text.
Mobjects
In ManimWeb, every element displayed is a Mobject
.
Tex
is a Mobject
, but it's not the only one. There are many more mobjects:
MathTex, Circle, Square, Axes, Arrow, Dot, Group, NumberPlane, SVGMobject...
But, Mobject
can't be rendered, they're only used as a container. VMobject
is an extension of Mobject
which can be rendered. It's what most mobjects use.
Animations
When using the play
method, you used the FadeIn
animation.
Every animation extends from Animation
.
You can play many animations at once with the playMany
method. Instead of
giving a single animation, you use a list of animations. Then, all the
animations will be played simultaneously.
If you want to delay the animations, you can use an AnimationGroup
with the
lagRatio
argument.
Like this:
var square1 = Square();
var square2 = Square();
square1.shift(RIGHT);
square2.shift(RIGHT);
await play(
AnimationGroup(
[
FadeIn(square1),
FadeIn(square2),
],
lagRatio: 0.02,
),
);