@@ -16,6 +16,7 @@ Shapes, Images and Positions
16
16
self.add(d, c, s, t)
17
17
self.wait(1)
18
18
19
+
19
20
.. manim :: Example1ImageFromArray
20
21
:save_last_frame:
21
22
@@ -26,6 +27,7 @@ Shapes, Images and Positions
26
27
image.set_height(7)
27
28
self.add(image)
28
29
30
+
29
31
.. manim :: Example2ImageFromFile
30
32
:save_last_frame:
31
33
@@ -43,4 +45,190 @@ Shapes, Images and Positions
43
45
self.add(img_mobject)
44
46
45
47
46
- Note: Here can come the UnitDot Example.
48
+ .. manim :: ArcShapeExample
49
+ :save_last_frame:
50
+
51
+ class ArcShapeExample(Scene):
52
+ def construct(self):
53
+ colors = [DARK_BLUE , DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
54
+ radius = [1+rad*0.1 for rad in range(len(colors))]
55
+
56
+ circles_group=VGroup()
57
+
58
+ # zip(radius,color) makes the iterator [(radius[i],color[i]) for i in range(radius)]
59
+ circles_group.add( *[Circle(radius=rad,stroke_width=10, color = col)
60
+ for rad,col in zip(radius,colors)])
61
+
62
+ self.add(circles_group)
63
+ self.wait(2)
64
+
65
+
66
+ .. manim :: ImageFromGradient
67
+ :save_last_frame:
68
+
69
+ class ImageFromGradient(Scene):
70
+ def construct(self):
71
+ n = 256
72
+ imageArray = np.uint8([[i*256/n for i in range(0,n)] for j in range(0,n)])
73
+ image = ImageMobject(imageArray).scale(2)
74
+ image.next_to(ORIGIN,LEFT, SMALL_BUFF)
75
+ self.add(image)
76
+ self.wait(1)
77
+
78
+
79
+ .. manim :: ShapesExample
80
+
81
+ class ShapesExample(Scene):
82
+
83
+ def construct(self):
84
+
85
+ circle = Circle(radius= 1, color=BLUE)
86
+
87
+ dot = Dot()
88
+ dot2= dot.copy().shift(RIGHT)
89
+ self.add(dot)
90
+
91
+ line=Line(np.array([3,0,0]),np.array([5,0,0]))
92
+ self.add(line)
93
+
94
+
95
+ self.play(GrowFromCenter(circle))
96
+ self.play(Transform(dot,dot2))
97
+ self.play(MoveAlongPath(dot,circle), run_time= 2, rate_func=linear)
98
+ self.play(Rotating(dot, about_point=np.array((2, 0, 0.))), run_time=1.5)
99
+ self.wait()
100
+
101
+
102
+ .. manim :: InterpolationExample
103
+ :save_last_frame:
104
+
105
+ class InterpolationExample(Scene):
106
+ def construct(self):
107
+ dotL = Dot(color=DARK_GREY)
108
+ dotL.shift(2*RIGHT)
109
+ dotR = Dot(color=WHITE)
110
+ dotR.shift(2*LEFT )
111
+
112
+ dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
113
+
114
+ self.add(dotL, dotR, dotMiddle)
115
+
116
+
117
+ .. manim :: MoveAroundExample
118
+
119
+ class MoveAroundExample(Scene):
120
+ def construct(self):
121
+ square = Square(color=BLUE,fill_opacity=1)
122
+
123
+ self.play(square.shift,LEFT)
124
+ self.play(square.set_fill,ORANGE)
125
+ self.play(square.scale,0.3)
126
+ self.play(square.rotate,0.4)
127
+
128
+
129
+ .. manim :: TextAlignementExample
130
+ :save_last_frame:
131
+
132
+ class TextAlignementExample(Scene):
133
+ def construct(self):
134
+ title=PangoText("K-means clustering and Logistic Regression", color=WHITE)
135
+ title.scale_in_place(0.75)
136
+ self.add(title.to_edge(UP))
137
+
138
+ t1=PangoText("1. Measuring").set_color(WHITE)
139
+ t1.next_to(ORIGIN,direction=RIGHT,aligned_edge=UP)
140
+
141
+ t2=PangoText("2. Clustering").set_color(WHITE)
142
+ t2.next_to(t1,direction=DOWN,aligned_edge=LEFT)
143
+
144
+ t3=PangoText("3. Regression").set_color(WHITE)
145
+ t3.next_to(t2,direction=DOWN,aligned_edge=LEFT)
146
+
147
+ t4=PangoText("4. Prediction").set_color(WHITE)
148
+ t4.next_to(t3,direction=DOWN,aligned_edge=LEFT)
149
+
150
+ x=VGroup(t1,t2,t3,t4).scale_in_place(0.7)
151
+ x.set_opacity(0.5)
152
+ x.submobjects[1].set_opacity(1)
153
+ self.add(x)
154
+
155
+
156
+ .. manim :: SplineExample
157
+
158
+ class SplineExample(Scene):
159
+ def construct(self):
160
+
161
+ np.random.seed(42)
162
+ area = 4
163
+
164
+ x1 = np.random.randint(-area,area)
165
+ y1 = np.random.randint(-area,area)
166
+ p1 = np.array([x1,y1,0])
167
+ destination_dot1 = Dot(point=p1).set_color(BLUE)
168
+
169
+ x2 = np.random.randint(-area,area)
170
+ y2 = np.random.randint(-area,area)
171
+ p2 = np.array([x2,y2,0])
172
+ destination_dot2 = Dot(p2).set_color(RED)
173
+
174
+
175
+ deltaP = p1-p2
176
+ deltaPNormalized = deltaP/get_norm(deltaP)
177
+
178
+ theta = np.radians(90)
179
+ r = np.array(( (np.cos(theta), -np.sin(theta), 0 ),
180
+ (np.sin(theta), np.cos(theta), 0 ),
181
+ ( 0 , 0 , 0 ) ))
182
+ senk = r.dot(deltaPNormalized)
183
+ offset = 0.1
184
+ offset_along = 0.5
185
+ offset_connect = 0.25
186
+
187
+ dest_line1_point1 = p1 + senk*offset - deltaPNormalized*offset_along
188
+ dest_line1_point2 = p2 + senk*offset + deltaPNormalized*offset_along
189
+ dest_line2_point1 = p1 - senk*offset - deltaPNormalized*offset_along
190
+ dest_line2_point2 = p2 - senk*offset + deltaPNormalized*offset_along
191
+ s1 = p1 - offset_connect*deltaPNormalized
192
+ s2 = p2 + offset_connect*deltaPNormalized
193
+ dest_line1 = Line(dest_line1_point1, dest_line1_point2)
194
+ dest_line2 = Line(dest_line2_point1, dest_line2_point2)
195
+
196
+ Lp1s1 = Line(p1, s1)
197
+
198
+ Lp1s1.add_cubic_bezier_curve(s1,
199
+ s1-deltaPNormalized*0.1,
200
+ dest_line2_point1+deltaPNormalized*0.1,
201
+ dest_line2_point1-deltaPNormalized*0.01 )
202
+ Lp1s1.add_cubic_bezier_curve(s1,
203
+ s1-deltaPNormalized*0.1,
204
+ dest_line1_point1+deltaPNormalized*0.1,
205
+ dest_line1_point1 )
206
+
207
+ Lp2s2 = Line(p2, s2)
208
+
209
+ Lp2s2.add_cubic_bezier_curve(s2,
210
+ s2+deltaPNormalized*0.1,
211
+ dest_line2_point2-deltaPNormalized*0.1,
212
+ dest_line2_point2 )
213
+ Lp2s2.add_cubic_bezier_curve(s2,
214
+ s2+deltaPNormalized*0.1,
215
+ dest_line1_point2-deltaPNormalized*0.1,
216
+ dest_line1_point2 )
217
+
218
+
219
+ start=VGroup(Line(destination_dot1.get_center(), destination_dot2.get_center()),
220
+ destination_dot1.copy(),
221
+ destination_dot2.copy())
222
+ start.scale(0.5)
223
+
224
+ end= VGroup(Lp1s1, Lp2s2,dest_line1,dest_line2,destination_dot1,destination_dot2)
225
+ end.scale(2)
226
+
227
+ self.add(start)
228
+ self.wait()
229
+ self.play(ClockwiseTransform(start,end), run_time=3)
230
+ self.wait()
231
+
232
+ Note: Here can come the UnitDot Example.
233
+
234
+
0 commit comments