This article records how I created a Modular Arithmetic Multiplication Animation using manim.
the video is requiring below a few items.
- totally 120 balls are there, totally 5 mins duration.
- good quaility, 4K with 60 FPS
from manim import *
import numpy as np
from os import system
import math
config.media_dir = "E:\PythonMedia\media"
config.frame_width = 16#9#16
config.frame_height = 9#16#
config.frame_size = (3840,2160)#(720,1280)#(2160,3840)##(3840,2160)##(3840,2160)#(1280,720)#(1080, 1920) #(1920, 1080) 426 x , 640 x 360,
config.frame_rate = 60
config.background_color = BLACK
class No32_purePendulum(Scene):
frameIndex = 0
frameIndexBook = []
ballPlay = []
fristFewCount = 15
def construct(self):
count = 120
runTime = 300
radius_ = np.linspace(0.5,4.2, count)
circles = [Circle(radius=_, fill_opacity=0, stroke_width=1, stroke_color=BLACK).rotate(PI/2)
for _ in radius_]
positions = [np.linspace(0, count-_, runTime*config.frame_rate) for _ in range(count)]
print(positions)
print("------------")
print(len(positions[0]))
def update_collection():
vg = VGroup()
for index in range(count-1):
if self.frameIndex<=10 or self.frameIndex >= len(positions[0])-1:
s_ = circles[index].point_from_proportion(0)
e_ = circles[index + 1].point_from_proportion(0)
else:
s_ = round(positions[index][self.frameIndex], 3) - math.floor(positions[index][self.frameIndex])
s_ = circles[index].point_from_proportion(s_)
e_ = round(positions[index + 1][self.frameIndex], 3) - math.floor(
positions[index + 1][self.frameIndex])
e_ = circles[index + 1].point_from_proportion(e_)
line = Line(start=s_, end=e_, stroke_color=WHITE, stroke_width=1)
vg.add(line)
#print(self.frameIndex)
self.frameIndex = self.frameIndex + 1
return vg
objects = always_redraw(update_collection)
self.add(objects)
self.play(Create(Text("").move_to(LEFT * 100), run_time=(runTime*config.frame_rate + 3) / config.frame_rate,
rate_func=linear)) #(runTime*config.frame_rate + 3) / config.frame_rate
if __name__ == '__main__':
system("manim -ql {} No32_purePendulum --disable_caching".format(__file__))
