This article records how I created a Modular Arithmetic Multiplication Animation using manim.
the video is requiring below a few items.
- totally 150 division are there, and would come to video one by one quickly. don’t spend much time i in it
- times varys from 0.1 to 10. totally 50 second duration amination.
from manim import *
import numpy as np
from os import system
import os
from colour import Color
import math
import random
config.media_dir = "E:\PythonMedia\media"
config.frame_width = 9 # 9#16
config.frame_height = 16 # 16#
config.frame_size = (720,1280)#(720, 1280) ##(3840,2160)#(1280,720)#(3840,2160)#(1280,720)#(1080, 1920) #(1920, 1080) 426 x , 640 x 360,
config.frame_rate = 50
config.background_color = BLACK
class multipifcation(Scene):
index = 0
def construct(self):
author = Text("Wangbw", color=WHITE).move_to(DOWN * 5)
self.add(author)
circle = Circle(radius=4.3, fill_opacity=0, stroke_width=1, stroke_color=WHITE)
self.add(circle)
dotCount=150
dotPositions = np.linspace(0, 1, dotCount+1)[:dotCount]
arrTimes = np.linspace(0.1,10.2, config.frame_rate*51 - config.frame_rate)
def update_collection():
times = 1
count = 1
if self.index>config.frame_rate:
times = round(arrTimes[self.index-config.frame_rate],2)
count = dotCount
else:
times = round(arrTimes[0],2)
count = math.floor(dotCount/config.frame_rate) * self.index
lineVG = VGroup()
for index in range(count):
endPoint = times * dotPositions[index]
endPoint = endPoint - math.floor(endPoint)
line = Line(start=circle.point_from_proportion(dotPositions[index]),
end=circle.point_from_proportion(endPoint), stroke_color=WHITE, stroke_width=1)
lineVG.add(line)
info1 = Text("Times={}".format(times)).next_to(circle,UP, buff=0.2).scale(0.8)
info2 = Text("Divisions={}".format(count)).next_to(info1,UP, buff=0.2).scale(0.8)
lineVG.add(info1)
lineVG.add(info2)
self.index = self.index + 1
return lineVG
objects = always_redraw(update_collection)
self.add(objects)
self.index = 0
self.play(Create(Text("").move_to(LEFT*10), run_time=50, rate_func=linear))
if __name__ == '__main__':
system("manim -ql {} multipifcation --disable_caching".format(__file__))
