Skip to content

Commit

Permalink
The most recent updates
Browse files Browse the repository at this point in the history
* I added a challenges.md to show visitors the downsides in my code
* I couldn't implement exactly the scenes outside the finished_scenes
* I have been working on the scenes, but, unfortuantely it seems that I
  need my own implementation of manim, or just a little deeper
  understanding.
  • Loading branch information
YehiaMedhat000 committed Sep 19, 2023
1 parent eaafb27 commit 8e1e751
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 123 deletions.
File renamed without changes.
File renamed without changes.
97 changes: 39 additions & 58 deletions unfinished/CubVolume.py → LineToSquareToCube.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,39 @@
from manim import *

class CubeVolume(ThreeDScene):
class LineToSquareToCube(ThreeDScene):
def construct(self):

# Set the camera initial position
self.set_camera_orientation(phi=0)

# Initialize the mobjects
# TODO, keep track of the numbers so they always show up clearly on the screen.
axes = ThreeDAxes(x_length=12,y_length=10,z_length=8)

# MathTex() mobjects
st_dim_l = Line(start=DL*2,end=UL*2,color=RED)
st_dim_r = st_dim_l.copy()
st_dim_br = Brace(st_dim_l,direction=LEFT)

st_dim_tex = MathTex('4').next_to(st_dim_br,LEFT).scale(2)

times = MathTex('\\times').scale(2)

# The square
sq = always_redraw(lambda:
Polygon(st_dim_r.get_end(),st_dim_r.get_start(),st_dim_l.get_start(),st_dim_l.get_end(),
color=RED,fill_color=BLUE,fill_opacity=0.75,stroke_width=4))

arr = Arrow(start=st_dim_l.get_top(),end=UR*2,color=RED)
arr_br = Brace(arr,direction=UP)
arrs = [arr.copy().shift(DOWN*(i+1)) for i in range(4)]

# Some arrows
arr = Arrow(start=st_dim_l.get_top(),end=UR*2,color=RED,buff=0)
arrs = [arr.copy().shift(DOWN*(i)) for i in range(5)]
arr_br = Brace(arr[0],direction=UP)
arr_br_tex = MathTex('4').next_to(arr_br,UP).scale(2)

result = MathTex('16').scale(2.5)

cube = always_redraw(lambda:Cube(side_length=4,color=BLUE,fill_opacity=1,stroke_width=4,stroke_color=RED)
.shift(np.array([0,0,2]))
.stretch_to_fit_depth(sq.get_center()[2],about_point=axes.c2p(0,0,0)))

rd_0_arr_dim = Arrow3D(start=np.array([2,-2,0]),end=np.array([2,-2,4]),color=RED)
rd_1_arr_dim = rd_0_arr_dim.copy().move_to(np.array([2,2,2]))
rd_2_arr_dim = rd_0_arr_dim.copy().move_to(np.array([-2,2,2]))
rd_3_arr_dim = rd_0_arr_dim.copy().move_to(np.array([-2,-2,2]))

arrs_3d = [rd_0_arr_dim,rd_1_arr_dim,rd_2_arr_dim,rd_3_arr_dim]

rd_dim_br = (Brace(Line3D(start=[2,-2,0],end=[2,2,0]),direction=RIGHT))
rd_dim_tex = (MathTex('4').scale(2.5).next_to(rd_dim_br))

rd_dim = VGroup(rd_dim_br,rd_dim_tex).rotate(angle=PI/2,axis=X_AXIS,about_point=np.array([2,-2,0]))

result_3d = MathTex('64').scale(2)
grp_3d = VGroup(result_3d,times,result).to_corner(DOWN)
grp_3d.arrange()
result = MathTex('16').scale(3)

# Play animations
self.add(sq)
self.play(Create(st_dim_l))
self.play(Write(st_dim_br),Write(st_dim_tex))
self.wait()
self.play(GrowArrow(arr),run_time=0.5)
self.play(Write(arr_br_tex),Write(arr_br))

self.play(Write(arr_br_tex),Write(arr_br))
for i in arrs:
self.play(GrowArrow(i),run_time=0.5)

self.wait(3)
self.play(FadeOut(arr),run_time=0.25)


for i in arrs:
self.play(FadeOut(i),run_time=0.25)

Expand All @@ -76,33 +46,44 @@ def construct(self):
self.wait()
self.play(ReplacementTransform(VGroup(st_dim_tex,arr_br_tex,times),result))
self.play(FadeOut(st_dim_br,st_dim_tex,arr_br_tex,arr_br))
self.play(result.animate.to_corner(DOWN))
self.add_fixed_in_frame_mobjects(result.to_corner(DOWN))

self.move_camera(phi=60*DEGREES,theta=-45*DEGREES,
focal_distance=20)
# Initialize mobjects
cube = always_redraw(lambda:Cube(side_length=4,color=BLUE,fill_opacity=1,stroke_width=4,stroke_color=RED)
.shift(np.array([0,0,2]))
.stretch_to_fit_depth(sq.get_center()[2],about_point=ORIGIN))

self.remove(result)
arr_3d = Arrow3D(start=ORIGIN,end=np.array([0,0,4]),color=RED)

rd_dim_br = (Brace(Line3D(start=[2,-2,0],end=[2,2,0]),direction=RIGHT))
rd_dim_tex = (MathTex('4').scale(3).next_to(rd_dim_br))
rd_dim = VGroup(rd_dim_br,rd_dim_tex).rotate(angle=PI/2,axis=X_AXIS,about_point=np.array([2,-2,0]))

exp = MathTex('16 \\times 4 = 64').scale(2)

# Set the camera settings
self.set_camera_orientation(phi=0)
self.move_camera(phi=60*DEGREES,theta=-45*DEGREES,focal_distance=20)
self.camera.set_zoom(0.75)
#self.play(Write(result))
self.wait()

for arr in arrs_3d:
self.play(Create(arr),run_time=0.2)

self.play(Create(arr_3d),run_time=0.2)
self.play(Write(rd_dim))

for arr in arrs_3d:
self.play(FadeOut(arr))


self.play(FadeOut(arr_3d))
self.wait()
self.add(cube)

self.add_fixed_in_frame_mobjects(grp_3d)

self.add(cube)
self.play(st_dim_r.animate.move_to(np.array([-2,0,4])),
st_dim_l.animate.move_to(np.array([2,0,4])))

self.add_fixed_in_frame_mobjects(exp)
self.play(TransformMatchingTex(result,exp))

#self.begin_ambient_camera_rotation(rate=PI/9)
self.wait(10)

self.play(Write(grp_3d))
self.begin_ambient_camera_rotation(rate=PI/9)
self.wait(5)
# TODO, not completed; needs more clarifications with LaTeX and formulae.
# Almost done
# TODO: would like to pull the 16 from the square to let it be fixed_in_frame, then add
# the other `times` and `MathTex('64')` mobjects. It will seem better this way
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
125 changes: 125 additions & 0 deletions SpheresCuboid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from manim import *

class SpheresCuboid(ThreeDScene):
def construct(self):

# Initialize the TexTemplate
temp = TexTemplate()
temp.add_to_preamble('\\usepackage{arabtex,utf8} \n\\setcode{utf8}')
Tex.set_default(tex_template=temp)
MathTex.set_default(tex_template=temp)

# Set the camera orientaion
self.set_camera_orientation(phi=0,theta=0,gamma=90*DEGREES)

# Initialize mobjects
s_0 = Sphere(fill_opacity=0.5,checkerboard_colors=None,stroke_width=0)
l_0 = Line(start=LEFT,end=RIGHT,color=RED)
b_0 = Brace(Line(start=ORIGIN,end=l_0.get_end()),direction=UP)
t_0 = Tex('\\begin{arabtex}\nنق\n\\end{arabtex}',font_size=30).next_to(b_0,direction=UP,buff=0.2)
t_0_1 = VGroup(t_0,b_0).copy()

s_1 = s_0.copy().move_to(RIGHT*2)
l_1 = l_0.copy().move_to(s_1.get_center())
t_1 = VGroup(t_0,b_0).copy()
t_1_1 = VGroup(t_0,b_0).copy()

s_2 = s_0.copy().move_to(LEFT*2)
l_2 = l_0.copy().move_to(s_2.get_center())
t_2 = VGroup(t_0,b_0).copy()
t_2_1 = VGroup(t_0,b_0).copy()

b_all = Brace(Line(start=LEFT*3,end=RIGHT*3),direction=UP)
t_all = Tex('\\begin{arabtex}\n6نق\n\\end{arabtex}',font_size=60).next_to(b_all,direction=UP)

small_braces_group = VGroup(b_0,t_0,t_0_1,t_1,t_1_1,t_2,t_2_1)
big_brace_group = VGroup(b_all,t_all)

# Play animations
self.play(Create(s_0))
self.wait(2)

self.play(Create(l_0),Write(t_0),Write(b_0))
self.wait()

t_0_1.save_state(); t_1_1.save_state()

self.play(t_0_1.animate.shift(np.array([-1,0,0])))
self.wait()

self.play(Create(s_1),Create(s_2),run_time=0.5)
self.play(Create(l_1),Create(l_2),run_time=0.5)
self.play(t_1.animate.shift(RIGHT),
t_1_1.animate.shift(RIGHT*2),
t_2.animate.shift(LEFT*2),
t_2_1.animate.shift(LEFT*3),run_time=0.5)
self.wait(3)

self.play(ReplacementTransform(small_braces_group,big_brace_group,remover=False))
self.wait(3)

t_all.save_state()

self.play(Unwrite(big_brace_group),remover=False)

t_all.restore()

self.add_fixed_in_frame_mobjects(t_all.to_corner(DOWN))
self.play(Write(t_all))

# TODO:
# Make another one from the other side after rotation
# Make these rectangle a base for stretching a prism which will represent the parallelopaipad

# Set camera orientation
self.move_camera(phi=90*DEGREES,theta=-180*DEGREES,gamma=0)

# Initialize new mobjects
t_0_1.restore(); t_1_1.restore()

def rot_br(mob):
return (mob.rotate(-90*DEGREES,axis=Z_AXIS,about_point=l_0.get_center())
.rotate(-90*DEGREES,axis=Y_AXIS,about_point=l_0.get_center()))

rot_br(t_0_1)
rot_br(t_1_1)


s_2.save_state()
# Playing animations
self.play(Uncreate(s_2))
self.play(l_0.animate.rotate(90*DEGREES,axis=Z_AXIS,about_point=l_0.get_center()))

b_two_r = Brace(l_0,direction=OUT)
text_two_r = Tex('\\begin{arabtex}\n2نق\n\\end{arabtex}',font_size=30).next_to(b_two_r,direction=OUT,buff=0.2)
two_r = VGroup(b_two_r,text_two_r)

self.play(Write(t_0_1),t_1_1.animate.shift(UP))
self.play(ReplacementTransform(VGroup(t_0_1,t_1_1),two_r))
self.wait()
#self.play(grp_2r_0.animate.shift(np.array([0,1,0])))

#self.play(ReplacementTransform(VGroup(grp_2r,grp_2r_0),two_r))
self.play(FadeOut(two_r))
self.play(text_two_r.animate.move_to(np.array([-3,0,-1])))
self.add_fixed_orientation_mobjects(two_r)

self.play(l_0.animate.rotate(90*DEGREES,axis=X_AXIS,about_point=l_0.get_center()))

b_two_r = Brace(l_0,direction=DOWN)
text_two_r = Tex('\\begin{arabtex}\n2نق\n\\end{arabtex}',font_size=30).next_to(b_two_r,direction=DOWN,buff=0.2)
two_r = VGroup(b_two_r,text_two_r)

self.play(Write(two_r))

self.wait()


#rec_side = Line(start=np.array([-3,1,1]),end=np.array([3,1,1]),stroke_width=4,color=RED)
#rec_other_side = rec_side.copy()
#rec_plan = always_redraw(lambda: Polygon(rec_side.get_start(),rec_side.get_end(),rec_other_side.get_end(),
# rec_other_side.get_start(),stroke_color=RED,fill_color=PURE_BLUE,fill_opacity=0.3))

#self.add(rec_plan)
#self.play(rec_side.animate.move_to(np.array([0,-1,1])))
#self.wait()
Binary file removed __pycache__/1p1t_1lesson.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/1p1t_lesson.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/Scenes.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/demo1.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/demo_equation.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/discord.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/practice.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/re_1p1t_lesson.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/try_manimlib.cpython-311.pyc
Binary file not shown.
2 changes: 0 additions & 2 deletions challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

## SpheresCuboid scene

### Uncomplete scene

> Explains a specific problem in a textbook about the ration between 3 spheres and the box that contains them.
1. I wanted to get the braces to completely be replaced with the bigger one, but, as it seems in the video that one of the braces wasn't replaced.
3 changes: 1 addition & 2 deletions manim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pixel_height = 720
pixel_width = 1280
background_color = BLACK
background_opacity = 1
scene_names = DefaultTemplate

scene_names = DefaultTemplate
61 changes: 0 additions & 61 deletions unfinished/SpheresCuboid.py

This file was deleted.

0 comments on commit 8e1e751

Please sign in to comment.