Skip to content

Commit 0000ec8

Browse files
committed
Added kolibril python examples to the docs, re-formatted to be readable
1 parent 3b6519a commit 0000ec8

File tree

3 files changed

+278
-2
lines changed

3 files changed

+278
-2
lines changed

docs/source/examples/3d.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,52 @@
7979
self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
8080
self.wait()
8181

82+
.. manim:: ThreeDPlane
83+
84+
class ThreeDPlane(ThreeDScene):
85+
86+
def construct(self):
87+
88+
resolution_fa=22
89+
self.set_camera_orientation(phi=75 * DEGREES, theta=-30 * DEGREES)
90+
91+
def param_plane(u,v):
92+
x=u
93+
y=v
94+
z=0
95+
return np.array([x,y,z])
96+
plane = ParametricSurface( param_plane,
97+
resolution = (resolution_fa,resolution_fa),
98+
v_min = -2,
99+
v_max = +2,
100+
u_min = -2,
101+
u_max = +2 )
102+
plane.scale_about_point(2,ORIGIN)
103+
104+
def param_gauss(u,v):
105+
x=u
106+
y=v
107+
d = np.sqrt(x * x + y * y)
108+
sigma, mu = 0.4, 0.0
109+
z= np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))
110+
return np.array([x,y,z])
111+
112+
gauss_plane = ParametricSurface( param_gauss,
113+
resolution = (resolution_fa, resolution_fa),
114+
v_min = -2,
115+
v_max = +2,
116+
u_min = -2,
117+
u_max = +2 )
118+
119+
gauss_plane.scale_about_point(2,ORIGIN)
120+
gauss_plane.set_style(fill_opacity=1)
121+
gauss_plane.set_style(stroke_color=GREEN)
122+
gauss_plane.set_fill_by_checkerboard(GREEN,BLUE,opacity=0.1)
123+
124+
axes = ThreeDAxes()
125+
126+
self.add(axes)
127+
self.play(Write(plane))
128+
self.play(Transform(plane,gauss_plane))
129+
self.wait()
130+

docs/source/examples/animations.rst

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,43 @@ Updaters
105105
line_moving = Line(ORIGIN, LEFT).set_color(ORANGE)
106106
line_moving.add_updater(my_rotation_updater)
107107
self.add(line_reference, line_moving)
108-
self.play(val_tracker.set_value, tick_end, run_time=PI)
108+
self.play(val_tracker.set_value, tick_end, run_time=PI)
109+
110+
.. manim:: PlaneFadeOut
111+
112+
class PlaneFadeOut(Scene):
113+
114+
def construct(self):
115+
116+
sq2= Square()
117+
118+
sq1= Square()
119+
sq1.next_to(sq2,LEFT)
120+
121+
sq3= Square()
122+
sq3.next_to(sq2,RIGHT)
123+
124+
circ = Circle()
125+
circ.next_to(sq2,DOWN)
126+
127+
self.add(sq1,sq2,sq3,circ)
128+
self.wait()
129+
130+
self.play(FadeOut(sq1),FadeOut(sq2),FadeOut(sq3))
131+
self.wait()
132+
133+
.. manim:: AnimationFadeInAndOut
134+
135+
class AnimationFadeInAndOut(Scene):
136+
def construct(self):
137+
square = Square(color=BLUE).shift(2*UP)
138+
139+
annotation = Text('Fade In', height=.8)
140+
self.add(annotation)
141+
self.play(FadeIn(square))
142+
143+
annotation.become(Text('Fade Out', height=.8))
144+
self.add(annotation)
145+
self.play(FadeOut(square))
146+
147+

docs/source/examples/shapes_images_positions.rst

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Shapes, Images and Positions
1616
self.add(d, c, s, t)
1717
self.wait(1)
1818

19+
1920
.. manim:: Example1ImageFromArray
2021
:save_last_frame:
2122

@@ -26,6 +27,7 @@ Shapes, Images and Positions
2627
image.set_height(7)
2728
self.add(image)
2829

30+
2931
.. manim:: Example2ImageFromFile
3032
:save_last_frame:
3133

@@ -43,4 +45,190 @@ Shapes, Images and Positions
4345
self.add(img_mobject)
4446

4547

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

Comments
 (0)