• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Aug 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from manimlib.imports import *
2.
3. class MathMagic:
4.     def __init__(self, array):
5.         self.array_input = array
6.         self.array_output = self.array_input.copy()
7.         self.pixels = len(self.array_input)
8.
9.     def get_array(self):
10.         return self.array_output
11.
12.     @staticmethod
13.     def linear_step_func(x, x0, x1):
14.         y= np.piecewise(x, [
15.         x < x0,
16.         (x >= x0) & (x <= x1),
17.         x > x1],
18.             [0.,
19.             lambda x: x/(x1-x0)+x0/(x0-x1),
20.              1.]
21.         )
22.         return y
23.
24.     def p3(self, step): #creates a function that returns 0.5, .. 0.5 ,0.6...1
25.         val= self.linear_step_func(step,0,1)
26.         return val
27.
28.     def p2(self, step): #creates a function that returns 0.5, .. 0.5 ,0.6...1
29.         val= self.linear_step_func(step,0.5,1)
30.         return val
31.
32.     def p1(self, step): #creates a function that returns 0,0.1,0.2...0.5
33.         val= self.linear_step_func(step,0,0.5)
34.         return val
35.
36.     def make_mask(self,pixel,step): # step goes from 0 to 1
41.
45.
46. class ControlSubmobjects(Scene):
47.     def construct(self):
48.         PIXEL = 5
49.         sq_array= VGroup()
50.         for x in range(PIXEL):
51.             for y in range(PIXEL):
52.                 dot = Dot(point=(x, y, 0),side_length=0.1)
54.         sq_array.move_to(ORIGIN)
56.         my_tracker = ValueTracker(0)
57.         end_val = 1
58.         final_heights = np.ones((PIXEL,PIXEL))
59.         a_math = MathMagic(final_heights)
60.         def updater_func(mob):
62.                 new_array=a_math.get_array()
63.                 hght_vals= new_array.flatten()
64.                 [el.set_height(i+0.01) for i,el in zip(hght_vals,sq_array.submobjects) ]
65.                 return mob
66.
67.         self.play(my_tracker.increment_value, end_val,
68.                   UpdateFromFunc(sq_array, updater_func),
69.                   rate_func=linear, run_time=2)
70.         self.wait(2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?