Une première animation avec manim

Récemment, j'ai découvert manim et j'ai adoré le côté procédural du langage.
Voilà ma première « vraie » animation.

Je vous partage le code ici. Il est encore primitif.
N'hésitez pas à me faire une remarque si vous en avez.

config.frame_width = 7
config.frame_height = 12
config.pixel_width = 500
config.pixel_height= 500
class fractionsDecoupe(Scene):
	delta = DOWN
	def decoupe(self, r, a, n):
		epsilon = 0.
		return VGroup( *[ Sector( r, start_angle=j*TAU/n+epsilon/2+PI/2, angle=TAU/n-epsilon, color=Color( hue=j/n, saturation=1, luminance=0.6 ) ) for j in range(int(a)) ] ).shift( self.delta );
	def decL(self, r, n):
		angle=TAU/n
		return VGroup( *[ Line( ORIGIN, RIGHT*r*np.cos(angle*j+PI/2)+UP*r*np.sin(angle*j+PI/2), color=BLACK ) for j in range(int(n)+1) ] ).shift( self.delta );
	
	def construct(self):
		a = ValueTracker(4)
		b = ValueTracker(5)
		k = 3
		c = 8
		fontSize = 56
		i = complex(0,1)
		circle = Circle(radius=2, color=WHITE, fill_color=WHITE, fill_opacity=0.5).shift( self.delta );
		sectors = self.decoupe( circle.radius, a.get_value(), b.get_value() );
		
		t = MathTex(r'\frac{'+str(int(a.get_value()))+'}{' + str(int(b.get_value())) + r'}', font_size=fontSize, color=ORANGE).next_to( circle, UL ).shift(UR*0.5)
		t2 = MathTex(r' = \frac{'+str(int(a.get_value()))+'\\times'+str(k)+'}{'+str(int(b.get_value()))+'\\times'+str(k)+ r'}', font_size=fontSize, color=ORANGE).next_to( t, RIGHT )
		self.play( DrawBorderThenFill(circle) )
		self.wait(0.5)
		self.play( Write(t) )
		self.play( Create( self.decL(circle.radius, b.get_value() ) ), run_time=2 )
		self.play( FadeIn( sectors ), FadeIn( self.decL(circle.radius, b.get_value() ) ), run_time=2 )
		
		a.set_value(a.get_value()*k);
		b.set_value(b.get_value()*k);
		t3 = MathTex(r' = \frac{'+str(int(a.get_value()))+'}{' + str(int(b.get_value())) + r'}', font_size=fontSize, color=ORANGE).next_to( t2, RIGHT )
		self.play( TransformFromCopy( t, t2 ), FadeIn( self.decL(circle.radius, b.get_value() ) ), run_time=2 )
		self.play( TransformFromCopy( t2, t3 ), run_time=2 )
		
		box = SurroundingRectangle( VGroup( t, t2, t3 ), buff=0.2 )
		self.play( Create( box ) )
		
		self.wait(4)

En modifiant un peu le script précédent, on est capable de faire mieux :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *