This article records how I created a Polyrhythms Visualization ainmation using manim.
the video is requiring below a few items.
- it is pattern 3:4:5:6:7:8:9:10
- sound effect is seperated from here. I presented source code ONLY
- I wrote the below code when I am starting to learn manim, code is not gracefully at all. it is ONLY for your reference.
from manim import *
from os import system
import random
import os
config.frame_width = 16
config.frame_height = 9
config.frame_size = (1920,1080)#(1080,1920)#(3840,2160)#(2560,1440)#(1920,1080)#
config.frame_rate = 30
config.background_color = BLACK
class B_Polyrhythm_3_4_5_6_7_8_9_10_11_go(Scene):
firstProgres = 0
secondProgres = 0
currentAgainst = 0
factor = 0.01
def construct(self):
def getIndex(list, num):
index = 0
for x in list:
if x == num:
return index
index = index + 1
return -1
sounds = ['bongo.mp3','open_conga.wav','bongo.mp3','open_conga.wav',
'bongo.mp3','open_conga.wav','bongo.mp3','open_conga.wav']
soundPath = 'sounds\drum'
dirname = os.path.dirname(__file__)
sounds = [os.path.join(dirname, soundPath, s) for s in sounds]
colors = [YELLOW, ORANGE, YELLOW, ORANGE,YELLOW, ORANGE,YELLOW,
ORANGE, YELLOW, ORANGE,YELLOW, ORANGE]
author = Text("Wangbw", fill_opacity=0.3).scale(0.6).to_edge(DOWN, buff=0.6)
patterns = [3,4,5, 6,7,8, 9,10]
playBooks = [[3],[3,4],[4],[4,5],[5],[5,6],[6],[6,7],[7],
[7,8],[8],[8,9],[9],[9,10], [3,4,5, 6,7,8, 9,10]]
eachTime = 2
polys = []
vgPatterns = VGroup()
scale_factor = 1.5
woring_scale_factor = 1.7
for t in patterns:
r = RegularPolygon(n=t, stroke_color=WHITE, stroke_width=10,
radius=1.5, stroke_opacity=2) #.scale(scale_factor)
if t%2 == 1:
rotate = 0
else:
rotate = PI/2
r.rotate(rotate)
polys.append(r)
vgPatterns.add(r)
vgPatterns.arrange_in_grid(rows=2, buff=0.4)
#self.add(author)
self.add(vgPatterns)
if __name__ == '__main__':
#system("manim -qh {} B_Polyrhythm_3_4_5_6_7_8_9_10_11 --disable_caching".format(__file__))
system("manim -qh {} B_Polyrhythm_3_4_5_6_7_8_9_10_11_go --disable_caching".format(__file__))