@@ -22,21 +22,18 @@ Shapes, Images and Positions
22
22
class PointMovingOnShapes(Scene):
23
23
24
24
def construct(self):
25
-
26
- circle = Circle(radius= 1, color=BLUE)
27
-
25
+ circle = Circle(radius=1, color=BLUE)
28
26
dot = Dot()
29
- dot2= dot.copy().shift(RIGHT)
27
+ dot2 = dot.copy().shift(RIGHT)
30
28
self.add(dot)
31
-
32
- line= Line(np.array( [3,0,0]),np.array( [5,0,0]) )
29
+
30
+ line = Line([3, 0, 0], [5, 0, 0] )
33
31
self.add(line)
34
-
35
-
32
+
36
33
self.play(GrowFromCenter(circle))
37
- self.play(Transform(dot,dot2))
38
- self.play(MoveAlongPath(dot,circle), run_time= 2, rate_func=linear)
39
- self.play(Rotating(dot, about_point=np.array(( 2, 0, 0.)) ), run_time=1.5)
34
+ self.play(Transform(dot, dot2))
35
+ self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
36
+ self.play(Rotating(dot, about_point=[ 2, 0, 0] ), run_time=1.5)
40
37
self.wait()
41
38
42
39
@@ -73,15 +70,14 @@ Shapes, Images and Positions
73
70
74
71
class ArcShapeIris(Scene):
75
72
def construct(self):
76
- colors = [DARK_BLUE , DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
77
- radius = [1+rad*0.1 for rad in range(len(colors))]
78
-
79
- circles_group=VGroup()
80
-
81
- # zip(radius,color) makes the iterator [(radius[i],color[i]) for i in range(radius)]
82
- circles_group.add( *[Circle(radius=rad,stroke_width=10, color = col)
83
- for rad,col in zip(radius,colors)])
84
-
73
+ colors = [DARK_BLUE, DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
74
+ radius = [1 + rad * 0.1 for rad in range(len(colors))]
75
+
76
+ circles_group = VGroup()
77
+
78
+ # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]
79
+ circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)
80
+ for rad, col in zip(radius, colors)])
85
81
self.add(circles_group)
86
82
87
83
@@ -91,9 +87,9 @@ Shapes, Images and Positions
91
87
class DotInterpolation(Scene):
92
88
def construct(self):
93
89
dotL = Dot(color=DARK_GREY)
94
- dotL.shift(2* RIGHT)
90
+ dotL.shift(2 * RIGHT)
95
91
dotR = Dot(color=WHITE)
96
- dotR.shift(2*LEFT )
92
+ dotR.shift(2 * LEFT )
97
93
98
94
dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
99
95
@@ -104,108 +100,118 @@ Shapes, Images and Positions
104
100
105
101
class MovingAround(Scene):
106
102
def construct(self):
107
- square = Square(color=BLUE,fill_opacity=1)
103
+ square = Square(color=BLUE, fill_opacity=1)
108
104
109
- self.play(square.shift,LEFT)
110
- self.play(square.set_fill,ORANGE)
111
- self.play(square.scale,0.3)
112
- self.play(square.rotate,0.4)
105
+ self.play(square.shift, LEFT)
106
+ self.play(square.set_fill, ORANGE)
107
+ self.play(square.scale, 0.3)
108
+ self.play(square.rotate, 0.4)
113
109
114
110
115
111
.. manim :: TextAlignement
116
112
:save_last_frame:
117
113
118
114
class TextAlignement(Scene):
119
- def construct(self):
120
- title= PangoText("K-means clustering and Logistic Regression", color=WHITE)
121
- title.scale_in_place(0.75)
122
- self.add(title.to_edge(UP))
123
-
124
- t1= PangoText("1. Measuring").set_color(WHITE)
125
- t1.next_to(ORIGIN,direction=RIGHT,aligned_edge=UP)
126
-
127
- t2= PangoText("2. Clustering").set_color(WHITE)
128
- t2.next_to(t1,direction=DOWN,aligned_edge=LEFT)
129
-
130
- t3= PangoText("3. Regression").set_color(WHITE)
131
- t3.next_to(t2,direction=DOWN,aligned_edge=LEFT)
132
-
133
- t4= PangoText("4. Prediction").set_color(WHITE)
134
- t4.next_to(t3,direction=DOWN,aligned_edge=LEFT)
135
-
136
- x= VGroup(t1,t2,t3,t4).scale_in_place(0.7)
137
- x.set_opacity(0.5)
138
- x.submobjects[1].set_opacity(1)
139
- self.add(x)
115
+ def construct(self):
116
+ title = PangoText("K-means clustering and Logistic Regression", color=WHITE)
117
+ title.scale_in_place(0.75)
118
+ self.add(title.to_edge(UP))
119
+
120
+ t1 = PangoText("1. Measuring").set_color(WHITE)
121
+ t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)
122
+
123
+ t2 = PangoText("2. Clustering").set_color(WHITE)
124
+ t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)
125
+
126
+ t3 = PangoText("3. Regression").set_color(WHITE)
127
+ t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)
128
+
129
+ t4 = PangoText("4. Prediction").set_color(WHITE)
130
+ t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)
131
+
132
+ x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)
133
+ x.set_opacity(0.5)
134
+ x.submobjects[1].set_opacity(1)
135
+ self.add(x)
140
136
141
137
142
138
.. manim :: BezierSpline
143
139
:save_last_frame:
144
140
145
141
class BezierSpline(Scene):
146
142
def construct(self):
147
-
148
143
np.random.seed(42)
149
144
area = 4
150
-
151
- x1 = np.random.randint(-area,area)
152
- y1 = np.random.randint(-area,area)
153
- p1 = np.array([x1,y1,0])
145
+
146
+ x1 = np.random.randint(-area, area)
147
+ y1 = np.random.randint(-area, area)
148
+ p1 = np.array([x1, y1, 0])
154
149
destination_dot1 = Dot(point=p1).set_color(BLUE)
155
-
156
- x2 = np.random.randint(-area,area)
157
- y2 = np.random.randint(-area,area)
158
- p2 = np.array([x2,y2,0])
150
+
151
+ x2 = np.random.randint(-area, area)
152
+ y2 = np.random.randint(-area, area)
153
+ p2 = np.array([x2, y2, 0])
159
154
destination_dot2 = Dot(p2).set_color(RED)
160
-
161
-
162
- deltaP = p1-p2
163
- deltaPNormalized = deltaP/get_norm(deltaP)
164
-
155
+
156
+ deltaP = p1 - p2
157
+ deltaPNormalized = deltaP / get_norm(deltaP)
158
+
165
159
theta = np.radians(90)
166
- r = np.array(( (np.cos(theta), -np.sin(theta), 0 ),
167
- (np.sin(theta), np.cos(theta), 0 ),
168
- ( 0 , 0 , 0 ) ))
160
+ r = np.array(
161
+ (
162
+ (np.cos(theta), -np.sin(theta), 0),
163
+ (np.sin(theta), np.cos(theta), 0),
164
+ (0, 0, 0),
165
+ )
166
+ )
169
167
senk = r.dot(deltaPNormalized)
170
168
offset = 0.1
171
169
offset_along = 0.5
172
170
offset_connect = 0.25
173
-
174
- dest_line1_point1 = p1 + senk* offset - deltaPNormalized* offset_along
175
- dest_line1_point2 = p2 + senk* offset + deltaPNormalized* offset_along
176
- dest_line2_point1 = p1 - senk* offset - deltaPNormalized* offset_along
177
- dest_line2_point2 = p2 - senk* offset + deltaPNormalized* offset_along
178
- s1 = p1 - offset_connect* deltaPNormalized
179
- s2 = p2 + offset_connect* deltaPNormalized
171
+
172
+ dest_line1_point1 = p1 + senk * offset - deltaPNormalized * offset_along
173
+ dest_line1_point2 = p2 + senk * offset + deltaPNormalized * offset_along
174
+ dest_line2_point1 = p1 - senk * offset - deltaPNormalized * offset_along
175
+ dest_line2_point2 = p2 - senk * offset + deltaPNormalized * offset_along
176
+ s1 = p1 - offset_connect * deltaPNormalized
177
+ s2 = p2 + offset_connect * deltaPNormalized
180
178
dest_line1 = Line(dest_line1_point1, dest_line1_point2)
181
179
dest_line2 = Line(dest_line2_point1, dest_line2_point2)
182
-
180
+
183
181
Lp1s1 = Line(p1, s1)
184
-
185
- Lp1s1.add_cubic_bezier_curve(s1,
186
- s1-deltaPNormalized*0.1,
187
- dest_line2_point1+deltaPNormalized*0.1,
188
- dest_line2_point1-deltaPNormalized*0.01 )
189
- Lp1s1.add_cubic_bezier_curve(s1,
190
- s1-deltaPNormalized*0.1,
191
- dest_line1_point1+deltaPNormalized*0.1,
192
- dest_line1_point1 )
193
-
182
+
183
+ Lp1s1.add_cubic_bezier_curve(
184
+ s1,
185
+ s1 - deltaPNormalized * 0.1,
186
+ dest_line2_point1 + deltaPNormalized * 0.1,
187
+ dest_line2_point1 - deltaPNormalized * 0.01,
188
+ )
189
+ Lp1s1.add_cubic_bezier_curve(
190
+ s1,
191
+ s1 - deltaPNormalized * 0.1,
192
+ dest_line1_point1 + deltaPNormalized * 0.1,
193
+ dest_line1_point1,
194
+ )
195
+
194
196
Lp2s2 = Line(p2, s2)
195
-
196
- Lp2s2.add_cubic_bezier_curve(s2,
197
- s2+deltaPNormalized*0.1,
198
- dest_line2_point2-deltaPNormalized*0.1,
199
- dest_line2_point2 )
200
- Lp2s2.add_cubic_bezier_curve(s2,
201
- s2+deltaPNormalized*0.1,
202
- dest_line1_point2-deltaPNormalized*0.1,
203
- dest_line1_point2 )
204
-
205
-
206
- mobjects= VGroup(Lp1s1, Lp2s2,dest_line1,dest_line2,destination_dot1,destination_dot2)
207
-
197
+
198
+ Lp2s2.add_cubic_bezier_curve(
199
+ s2,
200
+ s2 + deltaPNormalized * 0.1,
201
+ dest_line2_point2 - deltaPNormalized * 0.1,
202
+ dest_line2_point2,
203
+ )
204
+ Lp2s2.add_cubic_bezier_curve(
205
+ s2,
206
+ s2 + deltaPNormalized * 0.1,
207
+ dest_line1_point2 - deltaPNormalized * 0.1,
208
+ dest_line1_point2,
209
+ )
210
+
211
+ mobjects = VGroup(
212
+ Lp1s1, Lp2s2, dest_line1, dest_line2, destination_dot1, destination_dot2
213
+ )
214
+
208
215
mobjects.scale(2)
209
216
self.add(mobjects)
210
217
211
-
0 commit comments