This semester I have to present a video for my Computer Algebra class, and the topic I chose is related to random walks generated by irrational numbers.
Our professor suggested using Manim to animate the videos. I’m unfamiliar with either Manim or Makie.jl, but since I’m “Python averse”, I figured I might as well try to do the animations in Makie.
Is this a good idea? Would Makie be a good alternative for Manim?
The things I’ll need for my project:
Well type-set mathematical formulas
Syntax highlighted code listings
Some way to animate random walks like the following Pi visualization (with or without the axes).
P.S. I know there’s also Javis.jl, but that package hasn’t received any updates in the last year, so I don’t know what the state of the project is.
You can animate a ton of different things with Makie, you can certainly get very cool results. From my cursory looks at Manim, it has more support for setting up large, movie-like animations where you want more artistic control over when what element appears, how it morphs into something else, etc. Makie is more direct there, you mostly specify what data should change in what way and that’s your animation.
We also don’t morph latex into other shapes etc., while that looks cool it’s not really needed for a lot of things though, it’s more 2B1B’s style.
Here’s a short snippet that includes three things you mentioned, note that the “syntax highlighting” is just random but that should be easy enough to get from some other package in the ecosystem, I’m just showing that it’s possible in principle.
code = """
function f(x)
x ^ 2 + 2x + 3
end"""
tokens = split(code, r"\b", keepempty = false)
rich_code = rich([rich(string(t), color = rand(RGBf)) for t in tokens]...)
f = Figure()
Label(f[1, 1], rich_code, justification = :left, font = "SF Mono", tellwidth = false)
Label(f[2, 1], L"\sum_a^b x^2 + 2x + 3", tellwidth = false)
random_path = Observable([Point2f(0, 0)])
colors = Observable(Int[0])
ax = Axis(f[3, 1])
lines!(ax, random_path, color = colors)
record(f, "test.mp4", 1:120, framerate = 30) do i
for _ in 1:30
push!(random_path[], random_path[][end] + 0.01 * randn(Point2f))
end
append!(colors[], colors[][end]:colors[][end]+30)
notify(colors)
notify(random_path)
end
We also had a recipe for correct code highlighting! Really need to add it to a package, because I keep losing it…I’ll try to dig it up in the next days
Manim is really fantastic at what it does. Javis can also do some cool stuff and I used it to explain entropy to my son , but in the end for explanatory videos with advanced animations I think Manim is just spot on. So I would agree with your professor. Especially if you plan to put it on YouTube with voice over.
In julia would the alternative to Manim is Javis.jl. I think the authors cite manim as there source of inspiration.
It seems it hasn’t seem a lot of development lately but it is specifically geared towards animations.
Thanks @jules! the example is very illustrative. I’ve done a lot of parsing related stuff, so I think I could hack something together for the syntax highlighting. The rest of the code seems straight forward.
I’ll also take another look at javis based on the suggestions.
I searched for examples of random walks in Manim and one of the first results wasn’t very encouraging: A Long Random Walk (and Possibly a Manim Bug ) . The other examples I found also had a small number of iterations, so I think I’ll have to make a more empirical comparison of the alternatives.
Hey! Co-creator of Javis.jl here! Although it is true that there hasn’t been too much recent development, it is still very much on my radar! I recently started graduate school in mathematics and am wanting to bring some major updates to Javis.jl for some presentations I want to be giving!
If you have any questions about Javis, please let me know!
Transforming LaTeX into other LaTeX is one of the hallmark features of Manim for me and one reason I would have such a hard time using another tool. That said, the particular way in which Manim has the user specify how do to the transformation is pretty abstruse — there is a lot room for improvement here!
Is there more going on there than transforming the paths into each other? Does it do clever stuff when there are equal subexpressions or so? There’s some form of polygon morphing in Luxor: Work with polygons · Luxor
Yeah, it has some logic where it’ll match up subexpressions correctly. Somehow it breaks down the TeX into small components and then transforms [EDIT: or tries to, anyway, it’s not perfect] matching ones between each other correctly. I don’t know how it gets the paths — from the DVI? [EDIT: oh I see it makes SVGs from the latex, so probably that.]