Dataset Viewer
file_path
stringlengths 50
109
| content
stringlengths 42
76k
|
|---|---|
AnimationsWithManim_Elteoremadebeethoven/README.md
|
<p align="center"><img src ="/_title.gif" /></p>
## Contents (updating)
### [Tutorial files](https://drive.google.com/open?id=10LYJVJsvkcl5a7q_S-ZlSxI7hEBepw3P)
### [Documentation](https://elteoremadebeethoven.github.io/manim_3feb_docs.github.io/html/index.html)
### Freelance job
If you need an animation made in Manim **I can do it for you**. I also give private tutorials on Manim, Python and LaTeX.
* Gmail: [email protected]
* Discord: theoremofbeethoven#2781
* Reddit: u/TheoremofBeethoven
### This tutorial is based on the manim version of [3 february of 2019](https://github.com/3b1b/manim/tree/3b088b12843b7a4459fe71eba96b70edafb7aa78)
0. Installation on [Windows](https://www.youtube.com/watch?v=ZltiKHFWmv8), [GNU/Linux](https://www.youtube.com/watch?v=z_WJaHYH66M) and [Mac](https://www.youtube.com/watch?v=uZj_GQc6pN4).
1. [Text format](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/1_text_formats/scenes.md)/[Part 1 - Youtube](https://www.youtube.com/watch?v=yI2YJff9SgI)/[Part 2 - YouTube](https://www.youtube.com/watch?v=Km09KYWb9ag)/[Part 3 - YouTube](https://www.youtube.com/watch?v=gIvQsqXy5os)
2. Tex formulas/[YouTube](https://www.youtube.com/watch?v=DGSj7weT-y8)
3. [Text like arrays](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/3_text_like_arrays/scenes.md)/[YouTube](https://www.youtube.com/watch?v=QEdVn8socC8)
4. [Transformations](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/4_transform/scenes.md)/[Part 1 - YouTube](https://www.youtube.com/watch?v=HKPm8FZYaqI)/[Part 2 - YouTube](https://www.youtube.com/watch?v=qfifBmYTEfA)
5. [Visual tools](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/5_visual_tools/scenes.md)/YouTube
6. [Introduction in 2D plot](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/6a_plots_2D/scenes.md)/YouTube
7. [Introduction in 3D plot](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/6b_plots_3D/scenes.md)/YouTube
8. Add images, svgs and audio/YouTube
9. [Update functions](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/update_successions/update_successions.py)/YouTube
10. First project/YouTube
Challenges:
* [Roulette Epicycloids](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/extra/manim_challenges/roulette_epicycloids.py)
* [M mod N Epicycloids](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/extra/manim_challenges/MmodN_epicycloids.py)
* [Dragon fractal](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/extra/manim_challenges/dragon_fractal.py)
* [Analytic Geometry Series](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/extra/manim_challenges/geo_analy.py)
Settings:
* [Leave progress bars by default.](https://www.youtube.com/watch?v=K8dVFqXR2JM)
* [Rendering settings.](https://www.youtube.com/watch?v=d_2V5mC2hx0)
* [Modify the directory "media".](https://www.youtube.com/watch?v=I9rHHiKqTWY)
* [Set FPS via terminal.](https://www.youtube.com/watch?v=cyIz0Oh3lWY)
* [Export as GIF.](https://www.youtube.com/watch?v=juFfUwJUTtI)
Extras:
* [Learn Manim by yourself - How to render most files in old_projects.](https://www.youtube.com/watch?v=vzyzqv8Sp8Y)
* [How to create your own Number Creature.](https://www.youtube.com/watch?v=KGdA8IB6JL0)
* [FAQs](https://github.com/Elteoremadebeethoven/AnimationsWithManim/blob/master/English/extra/faqs/faqs.md)
Support this work in:
* [Patreon](https://patreon.com/theoremofbeethoven)
* [PayPal](https://www.paypal.me/zavdn)
## What is Manim?
[Manim](https://github.com/3b1b/manim) is a free tool for Python created by [Grant Sanderson](http://www.3blue1brown.com/) ([twitter](https://twitter.com/3blue1brown?lang=es)), mathematician from Stanford and owner of the YouTube channel [3Blue1Brown](https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw). It is specialized in scientific subjects, mainly mathematical, so it is based on LaTeX commands (mainly in TeX).
## What is LaTeX?
LaTeX is a processor of specialized texts in the scientific field, however, manim only uses TeX commands (with some exceptions), which refers to the writing of formulas. An example of the code in TeX is:
```latex
\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}.
```
If I built this command TeX return:
<p align="center"><img src ="https://raw.githubusercontent.com/Elteoremadebeethoven/AnimacionesConManim/master/TeX.png" /></p>
## Who is tutorials for?
This course is mainly aimed at teachers who want to explain a didactic and graphic form a mathematical development or the resolution of especially complex problems. The course extends to anyone who wants to explain a scientific topic in a original way.
## I need to know Python 3 and LaTeX to take this tutorials?
No, it is not necesary to know something of programming (although it is preferable for faster learning). In addition to learning Python3, teX knowledge is required to write the formulas. Likewise will mention tools such as [Pencil chromestore](http://s1.daumcdn.net/editor/fp/service_nc/pencil/Pencil_chromestore.html), [Codecogs](https://www.codecogs.com/latex/eqneditor.php), [Rinconmatematico](http://rinconmatematico.com/mathjax/), [latex4technics](https://www.latex4technics.com/), [sciweavers](http://www.sciweavers.org/free-online-latex-equation-editor) in other pages to learn and write formulas in TeX.
## I need a modern PC to run Manim?
No, with 512 MB of RAM and an Intel Core Duo processor (or similar) is more than enough, the difference is the compile time (fewer the resources, the longer it will take to render).
## What advantages does Manim offer with respect to other animation tools?
### Advantages:
* It is free and legal.
* Works on Windows, GNU/Linux (any distribution) and Mac perfectly.
* Can be used in old computers.
* Being open source, it is completely customizable to the user's taste.
* It is constantly improving.
* The video files are very high quality and light.
* The formulas are created using TeX commands, so they are of professional quality.
* In the case of not having programming knowledge, it is a good tool to start learning Python and LaTeX.
### Disadvantages:
* If you do not have the LaTeX package (complete) installed, it will occupy more than 4 GB of space on your computer (Though you can opt for basic instead of complete installation of LaTex which is efficient in terms of download size, and then download other package as per the need).
* A graphic interface is not used to perform the animations, everything is based on the Python 3 and TeX commands. The example of the classic Hello world! would be
```python
from manimlib.imports import *
class HelloWorld(Scene):
def construct(self):
helloWorld = TextMobject("Hello world!")
self.play(Write(helloWorld))
self.wait()
```
<p align="center"><img src ="https://raw.githubusercontent.com/Elteoremadebeethoven/AnimacionesConManim/master/HelloWorld.gif" /></p>
## Requirements
* Python 3.7
* pip (to install plug ins of python)
* Cairo
* FFmpeg
* LaTeX (complete)
* Sox
* A few plug ins on the list requirements.txt
|
AnimationsWithManim_Elteoremadebeethoven/ParticularAdvice.md
|
# Particular advice.
Donations depend on the type of question you ask, if it is very basic it can be 10 USD, but if it is more complex, it can reach up to 50 USD. Contact me (private Discord chat, Reddit chat, Email) and ask the question, I will tell you how much the donation should be.
In case you want me to make a complete animation (that is, all the work of an animation) you can also request it, I will indicate the price.
**email: [email protected]**
# Asesoramiento particular.
Las donaciones dependen del tipo de pregunta que hagas, si es muy básica puede ser de 10 dólares, pero si es más compleja, puede llegar hasta los 50 dólares. Contacta conmigo (chat privado en Discord, chat de Reddit, Email) y realiza la pregunta, yo te diré de cuanto debe de ser la donación.
En caso de que quieras que yo realize una animación completa (es decir, todo el trabajo de una animación) también la puedes solocitar, yo te indicaré el precio.
**email: [email protected]**
# Hire me as a freelance
To apply for the job, some requirements must be met.
1. You must be very clear about the progression of your animation, preferably have sketches of how you want to have your animation, step by step, in great detail.
2. Work less than 100 USD is paid half in advance, if it exceeds 100 USD one third is paid in advance.
3. If you want the source code to be shared (via GitHub or GitLab) the price increases by 25% to the initial price.
4. The cost of the animation depends on:
* The duration.
* The complexity of programming.
* If there is a need to optimize the resources of the PC the price increases.
* If advanced knowledge of Mathematics, Physics or other science is required, the price increases.
* If you want an abstract class (generic code to create animations) the price can even triple due to the modularization of the code.
* The time to make the code.
5. Payment is made via [PayPal](https://www.paypal.me/zavdn).
Contact:
Gmail: [email protected]
Or Discord: theoremofbeethoven#2781
# Contrátame como freelance
Para solicitar el trabajo se deben cumplir algunos requisitos.
1. Debes de tener muy claro la progresión de tu animación, de preferencia tener bocetos de cómo la quieres, paso a paso, con lujo de detalles.
2. Los trabajos menores a 100 USD se paga la mitad por adelantado, si supera los 100 USD se paga una tercera parte por adelantado.
3. Si se desea que el código fuente sea compartido (via GitHub o GitLab) el precio se incrementa un 25% a la cotización inicial.
4. El costo de la animación depende de:
* La duración.
* La complejidad de programación.
* Si hay necesidad de optimizar los recursos de la PC el precio aumenta.
* Si se requieren conocimientos avanzados de Matemáticas, Física u otra ciencia el precio aumenta.
* Si se desea una clase abstracta (código genérico para crear animaciones) el precio puede hasta triplicarse debido a la modularización del código.
* El tiempo para realizar el código.
5. El pago se realiza via [PayPal](https://www.paypal.me/zavdn).
Contacto:
Gmail: [email protected]
O Discord: theoremofbeethoven#2781
|
AnimationsWithManim_Elteoremadebeethoven/math_capsules/inscribed_angle.py
|
from manimlib.imports import *
class DecimalTextNumber(VMobject):
CONFIG = {
"num_decimal_places": 2,
"include_sign": False,
"group_with_commas": True,
"digit_to_digit_buff": 0.05,
"show_ellipsis": False,
"unit_type": "font", # tex or font
"unit": None, # Aligned to bottom unless it starts with "^"
"unit_custom_position": lambda mob: mob.set_color(GREEN).shift(RIGHT*0.1),
"include_background_rectangle": False,
"edge_to_fix": LEFT,
"unit_config": {
"font": "Digital-7",
"stroke_width": 0,
},
"number_config": {
"font": r"Digital-7",
"stroke_width": 0,
}
}
def __init__(self, number=0, **kwargs):
super().__init__(**kwargs)
self.number = number
self.initial_config = kwargs
if isinstance(number, complex):
formatter = self.get_complex_formatter()
else:
formatter = self.get_formatter()
num_string = formatter.format(number)
rounded_num = np.round(number, self.num_decimal_places)
if num_string.startswith("-") and rounded_num == 0:
if self.include_sign:
num_string = "+" + num_string[1:]
else:
num_string = num_string[1:]
self.add(*[
Text(char,color=self.color,**self.number_config)
for char in num_string
])
# Add non-numerical bits
if self.show_ellipsis:
self.add(SingleStringTexMobject("\\dots"))
if num_string.startswith("-"):
minus = self.submobjects[0]
minus.next_to(
self.submobjects[1], LEFT,
buff=self.digit_to_digit_buff
)
self.num_string = num_string
if self.unit is not None:
if self.unit_type == "font":
self.unit_sign = Text(self.unit,**self.unit_config)
elif self.unit_type == "tex":
del self.unit_config["font"]
self.unit_sign = TexMobject(self.unit,**self.unit_config)
self.add(self.unit_sign)
self.arrange(
buff=self.digit_to_digit_buff,
aligned_edge=DOWN
)
# Handle alignment of parts that should be aligned
# to the bottom
for i, c in enumerate(num_string):
if c == "-" and len(num_string) > i + 1:
self[i].align_to(self[i + 1], UP)
self[i].shift(self[i+1].get_height() * DOWN / 2)
elif c == ",":
self[i].shift(self[i].get_height() * DOWN / 2)
if self.unit and self.unit.startswith("^"):
self.unit_sign.align_to(self, UP)
#
if self.include_background_rectangle:
self.add_background_rectangle()
self.unit_custom_position(self.unit_sign)
# if num_string[0] == "-" or num_string[0] == "+":
# self[0].set_width(0.2)
# self[0].set_color(RED)
def get_formatter(self, **kwargs):
config = dict([
(attr, getattr(self, attr))
for attr in [
"include_sign",
"group_with_commas",
"num_decimal_places",
]
])
config.update(kwargs)
return "".join([
"{",
config.get("field_name", ""),
":",
"+" if config["include_sign"] else "",
"," if config["group_with_commas"] else "",
".", str(config["num_decimal_places"]), "f",
"}",
])
def get_complex_formatter(self, **kwargs):
return "".join([
self.get_formatter(field_name="0.real"),
self.get_formatter(field_name="0.imag", include_sign=True),
"i"
])
def set_value(self, number, **config):
full_config = dict(self.CONFIG)
full_config.update(self.initial_config)
full_config.update(config)
new_decimal = DecimalTextNumber(number, **full_config)
# Make sure last digit has constant height
#new_decimal.scale(
# self[-1].get_height() / new_decimal[-1].get_height()
#)
#"""
height = new_decimal.get_height()
yPos = new_decimal.get_center()[1]
for nr in new_decimal:
if "." != nr.text :
nr.scale(height/nr.get_height())
nr.shift([0,(yPos-nr.get_center()[1]),0])
max_width = max(*[f.get_width() for f in new_decimal[1:]])
if new_decimal[0].text == "-" or new_decimal[0].text == "+":
new_decimal[0].set_width(max_width)
new_decimal[0].set_color(RED)
#"""
new_decimal.move_to(self, self.edge_to_fix)
new_decimal.match_style(self)
old_family = self.get_family()
self.submobjects = new_decimal.submobjects
for mob in old_family:
# Dumb hack...due to how scene handles families
# of animated mobjects
mob.points[:] = 0
self.number = number
# if num_string[0] == "-" or num_string[0] == "+":
# self[0].set_width(0.2)
# self[0].set_color(RED)
return self
def get_value(self):
return self.number
def increment_value(self, delta_t=1):
self.set_value(self.get_value() + delta_t)
class ChangingDecimalText(Animation):
CONFIG = {
"suspend_mobject_updating": False,
}
def __init__(self, decimal_mob, number_update_func, **kwargs):
self.check_validity_of_input(decimal_mob)
self.yell_about_depricated_configuration(**kwargs)
self.number_update_func = number_update_func
super().__init__(decimal_mob, **kwargs)
def check_validity_of_input(self, decimal_mob):
if not isinstance(decimal_mob, DecimalTextNumber):
raise Exception(
"ChangingDecimal can only take "
"in a DecimalNumber"
)
def yell_about_depricated_configuration(self, **kwargs):
# Obviously this would optimally be removed at
# some point.
for attr in ["tracked_mobject", "position_update_func"]:
if attr in kwargs:
warnings.warn("""
Don't use {} for ChangingDecimal,
that functionality has been depricated
and you should use a mobject updater
instead
""".format(attr)
)
def interpolate_mobject(self, alpha):
self.mobject.set_value(
self.number_update_func(alpha)
)
class ChangeDecimalToValueText(ChangingDecimalText):
def __init__(self, decimal_mob, target_number, **kwargs):
start_number = decimal_mob.number
super().__init__(
decimal_mob,
lambda a: interpolate(start_number, target_number, a),
**kwargs
)
class ArcBetweenVectors(Arc):
def __init__(self, radius, d1, d2, center, invert_angle=False,**kwargs):
line1 = Line(center.get_center(),d1.get_center())
line2 = Line(center.get_center(),d2.get_center())
h = Line(center.get_center(),center.get_center()+RIGHT)
angle = angle_between_vectors(line1.get_unit_vector(),line2.get_unit_vector())
h1 = angle_between_vectors(h.get_unit_vector(),line1.get_unit_vector())
h2 = angle_between_vectors(h.get_unit_vector(),line2.get_unit_vector())
if line1.get_angle() <= line2.get_angle():
start_angle = h1
else:
start_angle = h2
if invert_angle:
start_angle = -start_angle
super().__init__(start_angle, angle,radius=radius,arc_center=center.get_center(), **kwargs)
def get_angle(self):
return self.angle
class LabelFromArc(TexMobject):
CONFIG = {
"distance_proportion": 1.2
}
def __init__(self, arc, tex_height, *tex_strings, **kwargs):
super().__init__(*tex_strings, **kwargs)
self.set_height(tex_height)
center = arc.get_arc_center()
max_size = max(self.get_width(),self.get_height()) * self.distance_proportion/ 2
vector = Line(center,arc.point_from_proportion(0.5)).get_vector()
end_coord = center+vector + normalize(vector)*max_size
self.move_to(end_coord)
class CircleWithAngles(VGroup):
CONFIG = {
"inner_line_config": {"color":PURPLE_A},
"outer_line_config": {"color":TEAL_A},
"inner_arc_config": {"color":PURPLE_A},
"outer_arc_config": {"color":TEAL_A},
"tex_1_config": {"color": TEAL_A},
"tex_2_config": {"color": PURPLE_A},
}
def __init__(self, radius=3, ang1=30, ang2=130, ang3=260, small_radius=0.4, **kwargs):
digest_config(self, kwargs)
super().__init__(**kwargs)
circle = Circle(radius=radius)
vt_1 = ValueTracker(ang1)
vt_2 = ValueTracker(ang2)
vt_3 = ValueTracker(ang3)
p1 = Dot(circle.point_at_angle(ang1*DEGREES))
p2 = Dot(circle.point_at_angle(ang2*DEGREES))
p3 = Dot(circle.point_at_angle(ang3*DEGREES))
in_lines = VMobject(**self.inner_line_config)
# ------------- LINES
out_lines = VMobject(**self.outer_line_config)
# ------------- ANGLES
out_arc = self.get_arc_between_lines(small_radius,p1,p2,p3)
in_arc = self.get_inner_angle(small_radius,p1,p2,p3,circle)
# ------------- LABELS
theta_2 = TexMobject("2\\theta",**self.tex_2_config)
theta_1 = TexMobject("\\theta",**self.tex_1_config)
# ------------- Equals
theta_1_val = DecimalTextNumber(0,unit="deg",num_decimal_places=3,**self.tex_2_config)
theta_2_val = DecimalTextNumber(0,unit="deg",num_decimal_places=3,**self.tex_1_config)
equal = Text("= 2 * ",font="Digital-7")
theta_eq = VGroup(theta_1_val, equal, theta_2_val)
theta_eq_temp = VGroup(theta_1_val, equal, theta_2_val)
theta_eq.arrange(RIGHT,buff=0.6,aligned_edge=DOWN)
theta_2_val.shift(LEFT*max(*[f.get_width() for f in theta_2_val])*1)
rectangle = Rectangle(width=theta_eq.get_width()+0.2,height=theta_eq.get_height()+0.2)
rectangle.move_to(theta_eq)
theta_eq.add(rectangle)
# UPDATERS
p1.add_updater(lambda mob: mob.move_to(circle.point_at_angle(vt_1.get_value()*DEGREES)))
p2.add_updater(lambda mob: mob.move_to(circle.point_at_angle(vt_2.get_value()*DEGREES)))
p3.add_updater(lambda mob: mob.move_to(circle.point_at_angle(vt_3.get_value()*DEGREES)))
in_lines.add_updater(lambda mob: mob.set_points_as_corners([
p1.get_center(),circle.get_center(),p2.get_center()
]))
out_lines.add_updater(lambda mob: mob.set_points_as_corners([
p1.get_center(),p3.get_center(),p2.get_center()
]))
out_arc.add_updater(lambda mob: mob.become(self.get_arc_between_lines(small_radius,p1,p2,p3)))
in_arc.add_updater(lambda mob: mob.become(self.get_inner_angle(small_radius,p1,p2,p3,circle)))
theta_1.add_updater(
lambda mob: mob.move_to(
p3.get_center()+Line(p3.get_center(),out_arc.point_from_proportion(0.5)).get_vector()*1.7)
)
theta_2.add_updater(
lambda mob: mob.move_to(
circle.get_center()+Line(circle.get_center(),in_arc.point_from_proportion(0.5)).get_vector()*1.7)
)
theta_1_val.add_updater(lambda mob: mob.set_value(self.get_inner_angle(1,p1,p2,p3,circle,False)*180/PI))
theta_2_val.add_updater(lambda mob: mob.set_value(self.get_arc_between_lines(1,p1,p2,p3,False)*180/PI))
rectangle.max_width = rectangle.get_width()
def rect_up(mob):
line = Line(theta_eq_temp.get_left()+LEFT*0.2,theta_eq_temp.get_right()+RIGHT*0.2)
if line.get_width() > mob.max_width:
mob.max_width = line.get_width()
mob.set_width(mob.max_width)
# mob.move_to(line)
mob.align_to(theta_1_val,LEFT)
mob.shift(LEFT*0.1)
rectangle.add_updater(rect_up)
# ------------- Groups
dots = VGroup(p1,p2,p3)
vts = Group(vt_1,vt_2,vt_3)
self.vts = vts
self.add(
circle,dots,
in_lines,out_lines,
in_arc,out_arc,
theta_1,theta_2,
theta_eq,
)
def get_arc_between_lines(self, radius, d1, d2, center,mob=True):
line1 = Line(center.get_center(),d1.get_center())
line2 = Line(center.get_center(),d2.get_center())
h = Line(center.get_center(),center.get_center()+RIGHT)
angle = angle_between_vectors(line1.get_unit_vector(),line2.get_unit_vector())
h1 = angle_between_vectors(h.get_unit_vector(),line1.get_unit_vector())
h2 = angle_between_vectors(h.get_unit_vector(),line2.get_unit_vector())
if line1.get_angle() <= line2.get_angle():
start_angle = h1
else:
start_angle = h2
arc = Arc(start_angle, angle,radius=radius,arc_center=center.get_center(),**self.outer_arc_config)
if mob:
return arc
else:
return angle
def get_inner_angle(self, radius,d1,d2,out_center,in_center,mob=True):
line1 = Line(out_center.get_center(),d1.get_center())
line2 = Line(out_center.get_center(),d2.get_center())
h = Line(out_center.get_center(),out_center.get_center()+RIGHT)
angle = angle_between_vectors(line1.get_unit_vector(),line2.get_unit_vector())
v1 = Line(in_center.get_center(),d1.get_center())
start_angle = angle_between_vectors(h.get_unit_vector(),v1.get_unit_vector())
arc = Arc(start_angle, angle*2,radius=radius,arc_center=in_center.get_center(),**self.inner_arc_config)
if mob:
return arc
else:
return angle*2
class InscribedAngle(MovingCameraScene):
def construct(self):
circle_grp = CircleWithAngles()
v1, v2, v3 = circle_grp.vts
eq = circle_grp[-1]
circle_grp.to_edge(LEFT,buff=1)
eq.to_edge(RIGHT,buff=1)
for mob in circle_grp:
mob.suspend_updating()
mob.update()
self.play(Write(circle_grp))
for mob in circle_grp:
mob.resume_updating()
self.wait()
self.play(v1.set_value,-10,run_time=3,rate_func=linear)
self.wait()
self.play(v2.set_value,225,run_time=5,rate_func=there_and_back)
self.wait()
self.play(
v1.set_value,47,
v2.set_value,110,
v3.set_value,335,
run_time=3,
rate_func=there_and_back
)
self.wait()
circle_grp.remove(eq)
self.play(
FadeOut(eq),
circle_grp[0].scale,0.64,
circle_grp[0].move_to,ORIGIN,
circle_grp[0].to_edge,DOWN,{"buff":0.2}
)
self.wait()
# ---------------------- Transform 2theta by varphi
theta_2 = circle_grp[-1]
varphi = TexMobject("\\varphi")
varphi.match_color(theta_2)
varphi.move_to(theta_2)
varphi.match_updaters(theta_2)
self.play(Transform(theta_2,varphi))
self.wait()
# ---------------------- Cases
titles = VGroup(*[
TextMobject(f) for f in ["Case 1", "Case 2", "Case 3"]
])
titles.arrange(RIGHT,buff=3).to_edge(UP)
# ---------------------- Case 1
self.play(Write(titles[0]))
self.wait()
self.play(
v1.set_value,40,
v2.set_value,290-180,
v3.set_value,290,
run_time=3,
)
case_1 = circle_grp.deepcopy()
case_1.clear_updaters()
self.play(
case_1.set_width,2,
case_1.next_to,titles[0],DOWN,buff=0.2
)
self.wait()
self.bring_to_front(case_1[1])
# ---------------------- Case 2
self.play(Write(titles[1]))
self.wait()
self.play(
v1.set_value,30,
v2.set_value,140,
v3.set_value,260,
run_time=3,
)
self.wait()
case_2 = circle_grp.deepcopy()
case_2.clear_updaters()
self.play(
case_2.set_width,2,
case_2.next_to,titles[1],DOWN,buff=0.2
)
self.wait()
self.bring_to_front(case_2[1])
# ---------------------- Case 3
self.play(Write(titles[2]))
self.wait()
self.play(
v1.set_value,30,
v2.set_value,90,
v3.set_value,325,
run_time=3,
)
case_3 = circle_grp.deepcopy()
case_3.clear_updaters()
self.bring_to_front(case_3[1])
self.wait()
self.play(
case_3.set_width,2,
case_3.next_to,titles[2],DOWN,buff=0.2
)
# ---------------------- Remove updaters
circle_grp.clear_updaters()
self.play(Write(circle_grp,rate_func=lambda t: smooth(1-t),run_time=2.5))
self.wait()
# ------------ Case by case
cases = VGroup(case_1,case_2,case_3)
SCREEN = Rectangle(width=FRAME_WIDTH,height=FRAME_HEIGHT)
grps = VGroup(*[VGroup(t,c) for t,c in zip(titles,cases)])
grps.generate_target()
gt = grps.target[1:]
gp = grps.target[0]
gt.align_to(SCREEN,UP)
gt.shift(UP*grps.get_height())
gp[1].set_height(6)
gp[1].move_to(ORIGIN)
gp[1].to_edge(DOWN)
gp[1].to_edge(LEFT,buff=2)
gp[0].set_x(0)
gt[-1].shift(UP*0.2)
self.play(
MoveToTarget(grps)
)
self.wait()
self.cases_group_1 = VGroup(case_1,titles[0])
self.proof_1(case_1)
# next case
def next_proof(height=6, buff_down=1, buff_left=0.5):
def func(vgr):
tit, gr = vgr
tit.move_to(ORIGIN)
tit.to_edge(UP)
gr.set_height(height)
gr.move_to(ORIGIN)
gr.to_edge(DOWN,buff=buff_down)
gr.to_edge(LEFT,buff=buff_left)
return vgr
return func
frame_1 = self.get_screen_rect()
self.cases_group_1.add(frame_1)
self.play(FadeIn(frame_1))
self.play(
self.cases_group_1.set_height,1,
self.cases_group_1.to_corner,UL,{"buff":0.1},
run_time=2
)
self.play(ApplyFunction(next_proof(), grps[1]))
self.wait()
# case 2
self.cases_group_2 = VGroup(titles[1],case_2)
self.proof_2(case_2)
frame_2 = self.get_screen_rect()
self.cases_group_2.add(frame_2)
self.play(FadeIn(frame_2))
self.play(
self.cases_group_2.set_height,1,
self.cases_group_2.next_to,self.cases_group_1,RIGHT,0,
run_time=2
)
self.play(ApplyFunction(next_proof(6,0.2), grps[2]))
# case 3
self.cases_group_3 = VGroup(titles[2],case_3)
self.proof_3(case_3)
frame_3 = self.get_screen_rect()
self.cases_group_3.add(frame_3)
self.play(FadeIn(frame_3))
all_cases = VGroup(self.cases_group_1,self.cases_group_2,self.cases_group_3)
self.play(
self.camera_frame.set_width,VGroup(frame_1,frame_2).get_width()*1,
self.camera_frame.move_to,VGroup(frame_1,frame_2).get_center(),
self.camera_frame.shift,DOWN*VGroup(frame_1,frame_2).get_height()/2,
self.cases_group_3.set_height,1,
self.cases_group_3.next_to,VGroup(frame_1,frame_2),DOWN,0,
run_time=2
)
# self.play(MoveToTarget(all_cases))
self.wait()
# self.play(v2.set_value,190,run_time=5,rate_func=linear)
def proof_1(self, case):
print("Proof 1")
dots = case[1]
d1, d2, d3 = dots
center = case[0]
theta = case[-2]
varphi = case[-1]
# Radius
r1 = Line(center.get_center(),d1.get_center(),color=RED_A,stroke_width=8)
r2 = Line(center.get_center(),d3.get_center(),color=RED_A,stroke_width=8)
r1_tex = TexMobject("r").add_background_rectangle()
r1_tex.move_to(r1)
r2_tex = r1_tex.deepcopy()
r2_tex.move_to(r2)
# self.add(r1,r2,r1_tex,r2_tex)
self.cases_group_1.add(case,r1,r2,r1_tex,r2_tex,)
self.play(
ShowCreation(r1),
ShowCreation(r2),
Write(r1_tex),
Write(r2_tex),
Animation(dots),
)
self.bring_to_front(dots)
self.wait()
# Arc and theta
arc_p1 = ArcBetweenVectors(0.6,center,d3,d1,True)
arc_p1.match_color(theta)
theta_copy = LabelFromArc(arc_p1, theta.get_height(), "\\theta", distance_proportion=1.5)
theta_copy.match_style(theta)
# psi
arc_psi = ArcBetweenVectors(0.4,d3,d1,center,True)
arc_psi.set_color(RED_A)
psi = LabelFromArc(arc_psi, theta.get_height(), "\\psi", distance_proportion=1.3)
psi.match_color(arc_psi)
# self.add(arc_p1,theta_copy,arc_psi,psi)
self.cases_group_1.add(arc_p1,theta_copy,arc_psi,psi)
self.play(
TransformFromCopy(theta,theta_copy),
ShowCreation(arc_p1),
run_time=2
)
self.wait(2)
self.play(
ShowCreation(arc_psi),
Write(psi),
run_time=2
)
self.wait(2)
# formulas develop
t1 = TexMobject("\\psi","+","2","\\theta","=","180^\\circ",
tex_to_color_map={
"\\psi": psi.get_color(), "\\theta": theta.get_color(),
},
)
t2 = TexMobject("\\psi","+","\\varphi","=","180^\\circ",
tex_to_color_map={
"\\psi": psi.get_color(), "\\varphi": varphi.get_color(),
},
)
t3 = TexMobject("\\psi","+","2","\\theta","=","\\psi","+","\\varphi",
tex_to_color_map={
"\\psi": psi.get_color(), "\\varphi": varphi.get_color(),
"\\theta": theta.get_color()
},
)
t4 = TexMobject("2","\\theta","=","\\varphi",
tex_to_color_map={
"\\psi": psi.get_color(), "\\varphi": varphi.get_color(),
"\\theta": theta.get_color()
},
)
tg = VGroup(t1,t2,t3,t4).arrange(DOWN,buff=0.6)
self.cases_group_1.add(t1,t2,t3,t4)
tg.scale(1.35)
self.align_formulas_with_equal(t2, t1, -2, -2)
self.align_formulas_with_equal(t3, t1, 4, -2)
self.align_formulas_with_equal(t4, t1, -2, -2)
tg.to_edge(RIGHT,buff=0.7)
# row 1
tc1 = theta.deepcopy()
tc2 = theta_copy.deepcopy()
self.play(
TransformFromCopy(psi, t1[0]),
ReplacementTransform(tc1.copy(), t1[3]),
ReplacementTransform(tc2.copy(), t1[3]),
# Transform(tc2, t1[3].copy()),
*[Write(t1[i]) for i in [1,2,-2,-1]],
run_time=3
)
self.cases_group_1.add(tc1,tc2)
self.wait()
self.play(
TransformFromCopy(t1[0],t2[0]),
TransformFromCopy(varphi,t2[2],path_arc=-PI/2),
*[Write(t2[i]) for i in [1,*range(3,len(t2))]],
run_time=3
)
self.wait()
self.play(
TransformFromCopy(t1[:4],t3[:4]),
TransformFromCopy(t2[:3],t3[-3:]),
Write(t3[4]),
run_time=3
)
self.wait()
self.play(
t3[0].fade,0.5,
t3[-3].fade,0.5,
)
self.wait()
self.play(
TransformFromCopy(t3[2:4],t4[:2]),
TransformFromCopy(t3[-1],t4[-1]),
Write(t4[2]),
run_time=3
)
self.wait()
self.play(
Succession(
FadeToColor(t4,YELLOW),
FadeToColor(t4,PURPLE_A),
),
AnimationGroup(
ShowCreationThenDestructionAround(t4.deepcopy()),
ShowCreationThenDestructionAround(t4.deepcopy()),
lag_ratio=1
)
)
self.wait()
# n = 0
# for mob in self.mobjects:
# try:
# t = Text(f"{n}").next_to(mob,UP,0)
# self.add(t)
# n += 1
# except:
# n += 1
# pass
def proof_2(self, case):
print("Proof 2")
dots = case[1]
d1, d2, d3 = dots
center = case[0]
theta = case[-2]
varphi = case[-1]
# Radius
r1 = Line(center.get_center(),d1.get_center(),color=RED_A,stroke_width=8)
r2 = Line(center.get_center(),d2.get_center(),color=RED_A,stroke_width=8)
r3 = Line(center.get_center(),d3.get_center(),color=RED_A,stroke_width=8)
r1_tex = TexMobject("r").add_background_rectangle()
r1_tex.move_to(r1)
r2_tex = r1_tex.deepcopy()
r2_tex.move_to(r2)
r3_tex = r1_tex.deepcopy()
r3_tex.move_to(r3)
arc_p3_2 = ArcBetweenVectors(0.8,center,d2,d3).set_color(TEAL)
arc_p3_1 = ArcBetweenVectors(1,d1,center,d3).set_color(TEAL)
# theta.shift(LEFT*0.2)
th_1 = LabelFromArc(arc_p3_1,theta.get_height()*0.8,"\\theta_1",color=theta.get_color(),distance_proportion=2)
th_2 = LabelFromArc(arc_p3_2,theta.get_height()*0.8,"\\theta_2",color=theta.get_color(),distance_proportion=2)
self.add_foreground_mobjects(dots,case[5])
self.cases_group_2.add(th_1,th_2)
self.play(theta.next_to,d3,DOWN,buff=0.2)
self.wait()
self.play(
ShowCreation(r1),
ShowCreation(r2),
ShowCreation(r3),
Write(r1_tex),
Write(r2_tex),
Write(r3_tex),
)
self.wait()
self.play(
ReplacementTransform(theta.copy()[0],th_1[0]),
ReplacementTransform(theta.copy()[0],th_2[0]),
ShowCreation(arc_p3_1),
ShowCreation(arc_p3_2),
run_time=3.5
)
self.wait()
# self.remove(theta)
self.cases_group_2.add(r1,r2,r3,r1_tex,r2_tex,r3_tex,arc_p3_1,arc_p3_2)
# ---------------- ARC PSI
arc_psi_1 = ArcBetweenVectors(0.4,d3,d1,center,True).set_color(RED_A)
arc_psi_2 = ArcBetweenVectors(0.4,d3,d2,center,True).set_color(RED_A)
arc_psi_2.rotate(-arc_psi_2.get_angle(),about_point=center.get_center())
psi_1 = LabelFromArc(arc_psi_1,theta.get_height()*0.8,"\\psi_1",color=RED_A,distance_proportion=1.6)
psi_2 = LabelFromArc(arc_psi_2,theta.get_height()*0.8,"\\psi_2",color=RED_A,distance_proportion=1.6)
self.play(
*list(map(Write,[arc_psi_1,arc_psi_2,psi_1,psi_2])),
run_time=2
)
self.wait()
self.cases_group_2.add(arc_psi_1,arc_psi_2,psi_1,psi_2)
# ---------------- FORMUAS transformn
tex_formulas_kwargs = {
"tex_to_color_map": {
"\\psi_1": psi_1.get_color(), "\\psi_2": psi_2.get_color(), "\\varphi": varphi.get_color(),
"\\theta_1": th_1.get_color(), "\\theta_2": th_1.get_color(),
}
}
# FORMULAS
f1 = TexMobject(
"\\psi_1","+","\\psi_2","+","\\varphi","=","360^\\circ",**tex_formulas_kwargs
)
f2 = TexMobject(
"(","180^\\circ","-","2","\\theta_1",")","+","(","180^\\circ","-","2","\\theta_2",")","+","\\varphi","=","360^\\circ",
**tex_formulas_kwargs
)
f2.add_background_rectangle()
f3 = TexMobject(
"-","2","\\theta_1","-","2","\\theta_2","+","\\varphi","=","0",**tex_formulas_kwargs
)
f4 = TexMobject(
"\\varphi","=","2","\\theta_1","+","2","\\theta_2",**tex_formulas_kwargs
)
f5 = TexMobject(
"\\varphi","=","2","(","\\theta_1","+","\\theta_2",")",**tex_formulas_kwargs
)
f6 = TexMobject(
"\\varphi","=","2","\\theta",**tex_formulas_kwargs
)
f6[-1].set_color(theta.get_color())
# f2[0].set_color(RED)
fg = VGroup(f1,f2,f3,f4,f5,f6).arrange(DOWN,buff=0.6)
fg.to_edge(RIGHT).to_edge(DOWN)
self.align_formulas_with_equal(f3,f1,-2,5)
self.align_formulas_with_equal(f4,f1,1,5)
self.align_formulas_with_equal(f5,f1,1,5)
self.align_formulas_with_equal(f6,f1,1,5)
# ---------------- FORMUAS transformn
by_case_1 = TextMobject("By Case 1").to_edge(RIGHT)
self.play(
LaggedStart(
TransformFromCopy(psi_1[0],f1[0],path_arc=-PI/2),
TransformFromCopy(psi_2[0],f1[2],path_arc=-PI/2),
TransformFromCopy(varphi,f1[4],path_arc=-PI/2),
lag_ratio=0.6
),
LaggedStart(*[Write(f1[i]) for i in [1,3,5,6]]),
run_time=6
)
self.wait()
self.play(Write(by_case_1))
self.wait()
self.play(
FadeIn(f2[0]),
*[
TransformFromCopy(f1[i],f2[j+1])
for i,j in zip(
[1,3,4,5,6],
[6,13,14,15,16]
)
],
TransformFromCopy(f1[0],f2[1:6+1]),
TransformFromCopy(f1[2],f2[7+1:13+1]),
# LaggedStart(*[Write(f2[i+1]) for i in [6,13]]),
run_time=4
)
self.wait()
self.play(Write(by_case_1,rate_func=lambda t: smooth(1-t)))
self.wait()
self.play(
*[
ApplyMethod(mob.fade,0.7)
for mob in [f2[i+1] for i in [1,8,16]]
]
)
self.wait(2)
self.play(
*[
TransformFromCopy(f2[i+1],f3[j])
for i,j in zip(
[2,3,4,9,10,11,13,14,15],
[*range(len(f3)-1)]
)
],
Write(f3[-1]),
# LaggedStart(*[Write(f2[i+1]) for i in [6,13]]),
run_time=4
)
self.wait()
self.play(
*[
TransformFromCopy(f3[i],f4[j])
for i,j in zip(
[1,2,4,5,7,8],
[2,3,5,6,0,1]
)
],
Write(f4[4]),
# LaggedStart(*[Write(f2[i+1]) for i in [6,13]]),
run_time=4
)
self.wait()
self.play(
*[
ReplacementTransform(f4[i].deepcopy(),f5[j])
for i,j in zip(
[0,1,2,3,4,5,6],
[0,1,2,4,5,2,6]
)
],
Write(f5[3]),
Write(f5[-1]),
# LaggedStart(*[Write(f2[i+1]) for i in [6,13]]),
run_time=4
)
self.wait()
self.play(
*[
ReplacementTransform(f5[i].deepcopy(),f6[j])
for i,j in zip(
[0,1,2],
[0,1,2]
)
],
TransformFromCopy(f5[-5:],f6[-1]),
run_time=4
)
self.foreground_mobjects = []
self.wait()
self.play(
Succession(
FadeToColor(f6,YELLOW),
FadeToColor(f6,PURPLE_A),
),
AnimationGroup(
ShowCreationThenDestructionAround(f6.deepcopy()),
ShowCreationThenDestructionAround(f6.deepcopy()),
lag_ratio=1
)
)
# self.play(
# *[
# TransformFromCopy()
# ],
# )
# self.add(fg)
# VGroup(case,*self.mobjects[start_index:]).set_color(TEAL)
self.cases_group_2.add(fg,by_case_1)
self.wait()
def proof_3(self, case):
print("Proof 3")
dots = case[1]
d1, d2, d3 = dots
center = case[0]
theta = case[-2]
varphi = case[-1]
self.add_foreground_mobject(dots)
def fade_mobs(fade=0.9):
def update(mob):
mob.fade(fade)
return mob
return update
# ---------------- FIGURES DEFINITION
diameter_vector = Line(d3.get_center(),center.get_center()).get_vector()
diameter = Line(d3.get_center(),d3.get_center()+diameter_vector*2,color=RED_A)
d4 = Dot(diameter.get_end())
arc_psi_1 = ArcBetweenVectors(0.6,d2,d4,d3,color=RED_A)
arc_psi_2 = ArcBetweenVectors(0.6,d2,d4,center,color=RED_A)
arc_alpha_1 = ArcBetweenVectors(0.7,d1,d4,d3,color=YELLOW_B,stroke_width=8)
arc_alpha_2 = ArcBetweenVectors(0.7,d1,d4,center,color=YELLOW_B,stroke_width=8)
psi_1 = LabelFromArc(arc_psi_1,theta.get_height()*0.8,"\\psi_1",color=RED_A,distance_proportion=2.1)
psi_2 = LabelFromArc(arc_psi_2,theta.get_height()*0.8,"\\psi_2",color=RED_A,distance_proportion=2.1)
alpha_1 = LabelFromArc(arc_alpha_1,theta.get_height()*0.8,"\\alpha_1",color=YELLOW_B,distance_proportion=2.5)
back_1 = BackgroundRectangle(alpha_1)
alpha_2 = LabelFromArc(arc_alpha_2,theta.get_height()*0.8,"\\alpha_2",color=YELLOW_B,distance_proportion=2.3)
back_2 = BackgroundRectangle(alpha_2)
line_1 = Line(center.get_center(),d1.get_center(),color=varphi.get_color())
line_2 = Line(d3.get_center(),d1.get_center(),color=varphi.get_color())
# ---------
psi_g = VGroup(arc_psi_1,arc_psi_2,psi_1,psi_2)
alpha_g = VGroup(arc_alpha_1,arc_alpha_2,alpha_1,alpha_2)
theta_g = VGroup(theta,varphi,case[-3],case[-4],case[2],case[3])
self.wait()
self.play(
GrowFromCenter(diameter)
)
self.wait()
self.play(
LaggedStart(*[
Write(arc)
for arc in psi_g
]),
)
self.wait(2)
self.play(
*list(map(FadeIn,[back_1,back_2])),
LaggedStart(*[
Write(arc)
for arc in alpha_g
]),
)
self.wait(2)
self.add_foreground_mobjects(back_1,back_2,alpha_g)
self.cases_group_3.add(
arc_psi_1,arc_psi_2,arc_alpha_1,arc_alpha_2,diameter,
psi_1,psi_2,alpha_1,alpha_2,
)
self.add(line_1,line_2)
for i in [psi_g,theta_g]:
for j in i:
j.save_state()
self.play(
*[ApplyFunction(fade_mobs(),i) for i in psi_g],
*[ApplyFunction(fade_mobs(),i) for i in theta_g],
)
self.wait()
# self.play(
# Restore(psi_g),
# Restore(theta_g),
# )
# self.wait()
# self.play(ApplyFunction(show_mobs(),psi_g))
# ---------------- FORMULAS DEFINITION
formulas = [
["\\alpha_1","=","\\psi_1","+","\\theta"],
["\\alpha_2","=","\\psi_2","+","\\varphi"],
["\\alpha_2","=","2","\\alpha_1"],
["\\psi_2","+","\\varphi","=","2","(","\\psi_1","+","\\theta",")"],
["\\psi_2","=","2","\\psi_1"],
["2","\\psi_1","+","\\varphi","=","2","\\psi_1","+","2","\\theta"],
["\\varphi","=","2","\\theta"],
]
tex_formulas_kwargs = {
"tex_to_color_map": {
"\\psi_1": psi_1.get_color(), "\\psi_2": psi_2.get_color(), "\\varphi": varphi.get_color(),
"\\theta": theta.get_color(), "\\alpha_1": alpha_1.get_color(), "\\alpha_2": alpha_2.get_color()
}
}
f = VGroup(*[
TexMobject(*formula, **tex_formulas_kwargs)
for formula in formulas
])
f.arrange(DOWN)
f.scale(1.3)
for fi,i in zip(f[1:],[1,1,3,1,4,1]):
self.align_formulas_with_equal(fi,f[0],i,1)
f.to_edge(RIGHT,buff=1.8)
# --------------------------------------
by_case_1 = TextMobject("By case 1")
by_case_1.next_to(f[2],RIGHT)
by_case_2 = by_case_1.copy()
by_case_2.next_to(f[4],RIGHT)
# ----------- FORMULAS ANIMATIONS
self.play(
FadeOut(back_1),
Restore(theta),
Restore(psi_1),
ReplacementTransform(alpha_1[0],f[0][0]),
run_time=2,
)
self.play(
TransformFromCopy(psi_1[0],f[0][2]),
TransformFromCopy(theta[0],f[0][-1]),
*[Write(f[0][i]) for i in [1,3]],
run_time=3,
)
self.wait()
self.play(
FadeOut(back_2),
Restore(varphi),
Restore(psi_2),
ReplacementTransform(alpha_2[0],f[1][0]),
run_time=2,
)
self.play(
TransformFromCopy(psi_2[0],f[1][2]),
TransformFromCopy(varphi[0],f[1][-1]),
*[Write(f[1][i]) for i in [1,3]],
run_time=3,
)
self.wait()
# By case 1 - 1
self.play(
Write(by_case_1)
)
self.wait()
self.play(
Write(f[2])
)
self.wait()
# -----------------
self.play(
TransformFromCopy(f[0][-3:],f[3][6:9]),
TransformFromCopy(f[1][-3:],f[3][:3]),
*[
TransformFromCopy(f[2][i],f[3][j])
for i,j in zip(
[1,2],
[3,4]
)
],
*[Write(f[3][i]) for i in [5,9]],
run_time=3
)
self.wait()
# ---------------------------
self.wait()
line_3 = Line(d3.get_center(),d2.get_center(),color=TEAL_A)
line_4 = Line(center.get_center(),d2.get_center(),color=PURPLE_A)
save_grp = VGroup(arc_alpha_1,arc_alpha_2,varphi,theta)
for i in save_grp:
try:
i.save_state()
except:
pass
self.play(
FadeOut(line_1),
FadeOut(line_2),
# line_1.fade,1,
# line_2.fade,1,
FadeIn(line_3),
FadeIn(line_4),
*[ApplyMethod(i.fade,0.92) for i in save_grp],
*[Restore(i) for i in [arc_psi_1,arc_psi_2]]
)
self.wait(3)
# by case 2
self.play(
Write(by_case_2)
)
self.wait()
self.play(
Write(f[4])
)
self.wait(3)
self.play(
*[Restore(i) for i in [*save_grp,*case[2:6]]]
)
self.wait()
# ---------------------------
self.play(
# TransformFromCopy(f[3][-3:],f[5][6:9]),
TransformFromCopy(f[3][0],f[5][:2]),
*[
TransformFromCopy(f[3][i],f[5][j])
for i,j in zip(
[1,2,3,4,6,7,8,4],
[2,3,4,5,6,7,9,8]
)
],
run_time=3
)
self.wait()
self.play(
*[ApplyMethod(f[5][i].fade,0.8) for i in [0,1,5,6]],
run_time=2
)
self.play(
*[
TransformFromCopy(f[5][i],f[6][j])
for i,j in zip(
[3,4,8,9],
[0,1,2,3]
)
],
run_time=3
)
# self.play(
# *{Restore(i) for i in [case[2],case[3]]}
# )
# self.add(f,by_case_1,by_case_2)
self.play(
Succession(
FadeToColor(f[6],YELLOW),
FadeToColor(f[6],PURPLE_A),
),
AnimationGroup(
ShowCreationThenDestructionAround(f[6].deepcopy()),
ShowCreationThenDestructionAround(f[6].deepcopy()),
lag_ratio=1
)
)
self.cases_group_3.add(line_1,line_2,line_3,line_4,by_case_1,by_case_2,f)
self.wait()
def align_formulas_with_equal(self, f1, f2, i1, i2):
c1 = f1[i1].get_center()
c2 = f2[i2].get_center()
distance = c2 - c1
f1.shift(RIGHT*distance[0])
def get_screen_rect(self):
return Rectangle(width=FRAME_WIDTH,height=FRAME_HEIGHT)
|
AnimationsWithManim_Elteoremadebeethoven/math_capsules/sine_cosine_laws.py
|
from manimlib.imports import *
class MeasureDistance(VGroup):
CONFIG = {
"color":RED_B,
"buff":0.3,
"lateral":0.3,
"invert":False,
"dashed_segment_length":0.09,
"dashed":True,
"ang_arrows":30*DEGREES,
"size_arrows":0.2,
"stroke":2.4,
}
def __init__(self,mob,**kwargs):
VGroup.__init__(self,**kwargs)
if self.dashed==True:
medicion=DashedLine(ORIGIN,mob.get_length()*RIGHT,dashed_segment_length=self.dashed_segment_length).set_color(self.color)
else:
medicion=Line(ORIGIN,mob.get_length()*RIGHT)
medicion.set_stroke(None,self.stroke)
pre_medicion=Line(ORIGIN,self.lateral*RIGHT).rotate(PI/2).set_stroke(None,self.stroke)
pos_medicion=pre_medicion.copy()
pre_medicion.move_to(medicion.get_start())
pos_medicion.move_to(medicion.get_end())
angulo=mob.get_angle()
matriz_rotacion=rotation_matrix(PI/2,OUT)
vector_unitario=mob.get_unit_vector()
direccion=np.matmul(matriz_rotacion,vector_unitario)
self.direccion=direccion
self.add(medicion,pre_medicion,pos_medicion)
self.rotate(angulo)
self.move_to(mob)
if self.invert==True:
self.shift(-direccion*self.buff)
else:
self.shift(direccion*self.buff)
self.set_color(self.color)
self.tip_point_index = -np.argmin(self.get_all_points()[-1, :])
def get_tex(self, tex,scale=1,buff=1,invert_dir=False,invert_texto=False,remove_rot=True,**moreargs):
linea_referencia=Line(self[0][0].get_start(),self[0][-1].get_end())
texto=TexMobject(tex,**moreargs)
ancho=texto.get_height()/2
if invert_texto:
inv=PI
else:
inv=0
if remove_rot:
texto.scale(scale).move_to(self)
else:
texto.rotate(linea_referencia.get_angle()).scale(scale).move_to(self)
texto.rotate(inv)
if invert_dir:
inv=-1
else:
inv=1
texto.shift(self.direccion*(buff+1)*ancho)
return texto
class ArcBetweenVectors(Arc):
def __init__(self, radius, d1, d2, center, invert_angle=False,**kwargs):
line1 = Line(center.get_center(),d1.get_center())
line2 = Line(center.get_center(),d2.get_center())
h = Line(center.get_center(),center.get_center()+RIGHT)
angle = angle_between_vectors(line1.get_unit_vector(),line2.get_unit_vector())
h1 = angle_between_vectors(h.get_unit_vector(),line1.get_unit_vector())
h2 = angle_between_vectors(h.get_unit_vector(),line2.get_unit_vector())
if line1.get_angle() <= line2.get_angle():
start_angle = h1
else:
start_angle = h2
if invert_angle:
start_angle = -start_angle
super().__init__(start_angle, angle,radius=radius,arc_center=center.get_center(), **kwargs)
def get_angle(self):
return self.angle
class LabelFromArc(TexMobject):
CONFIG = {
"distance_proportion": 1.2
}
def __init__(self, arc, tex_height, *tex_strings, **kwargs):
super().__init__(*tex_strings, **kwargs)
self.set_height(tex_height)
center = arc.get_arc_center()
max_size = max(self.get_width(),self.get_height()) * self.distance_proportion/ 2
vector = Line(center,arc.point_from_proportion(0.5)).get_vector()
end_coord = center+vector + normalize(vector)*max_size
self.move_to(end_coord)
class Polygon(Polygon):
def get_center_of_edges(self,buff=SMALL_BUFF*3):
vertices = self.get_vertices()
coords_vertices = []
for i in range(len(vertices)):
if i < len(vertices)-1:
p1,p2 = [vertices[i],vertices[i+1]]
else:
p1,p2 = [vertices[-1],vertices[0]]
guide_line = Line(p1,p2)
side = guide_line.get_center()
normal_direction = guide_line.copy()
normal_direction.rotate(-PI/2)
vector_normal_direction = normal_direction.get_unit_vector()
direction = Dot(side).shift(vector_normal_direction*buff).get_center()
coords_vertices.append(direction)
return coords_vertices
class SineCosineLaws(Scene):
CONFIG = {
"triangle_config": {
"color": RED,
"stroke_width": 8,
},
"tex_map": {
"tex_to_color_map": {
"\\alpha": RED_A,
"\\beta": TEAL_A,
"\\gamma": PURPLE_A,
"A": RED_A,
"B": TEAL_A,
"C": PURPLE_A,
"x": GREEN_A,
"y": GOLD_B,
"h_1": YELLOW_B,
"h_2": BLUE_B,
}
}
}
def construct(self):
self.wait(0.5)
du = UP*1.5
d1 = Dot(LEFT*4+du)
d2 = Dot(RIGHT*2+du)
d3 = Dot(RIGHT*4+UP*2+du)
triangle = Polygon(
d1.get_center(),d2.get_center(),d3.get_center(),**self.triangle_config
)
def frac_string(n,d):
return ["{",n,"\\over",d,"}"]
def frac_strings(n,d):
return ["{",*n,"\\over",*d,"}"]
sina_t = ["{\\rm sin}","\\alpha"]
sinb_t = ["{\\rm sin}","\\beta"]
sinc_t = ["{\\rm sin}","\\gamma"]
cosa_t = ["\\,{\\rm cos}","\\alpha"]
cosb_t = ["\\,{\\rm cos}","\\beta"]
cosc_t = ["\\,{\\rm cos}","\\gamma"]
formulas_sine_string_1 = [
[*sinb_t,"=",*frac_string("h_1","C")],
[*sinc_t,"=",*frac_string("h_1","B")],
["C","\\,",*sinb_t,"=","h_1"],
["B","\\,",*sinc_t,"=","h_1"],
["C","\\,",*sinb_t,"=","B","\\,",*sinc_t],
[*frac_strings(["C"],sinc_t),"=",*frac_strings(["B"],sinb_t)]
]
formulas_sine_string_2 = [
[*sina_t,"=",*frac_string("h_2","B")],
[*sinb_t,"=",*frac_string("h_2","A")],
["B","\\,",*sina_t,"=","h_2"],
["A","\\,",*sinb_t,"=","h_2"],
["B","\\,",*sina_t,"=","A","\\,",*sinb_t],
[*frac_strings(["B"],sinb_t),"=",*frac_strings(["A"],sina_t)]
]
sine_law = TexMobject(*[
*frac_strings(["C"],sinc_t),"=",*frac_strings(["B"],sinb_t),"=",*frac_strings(["A"],sina_t),
],**self.tex_map).scale(0.9)
formulas_sine_1 = VGroup(*[
TexMobject(*f,**self.tex_map) for f in formulas_sine_string_1
])
# formulas_sine.arrange_in_grid(None,2)
formulas_sine_arrange_1 = VGroup(
formulas_sine_1[:2].arrange(RIGHT,buff=1),
formulas_sine_1[2:4].arrange(RIGHT,buff=1),
formulas_sine_1[4:].arrange(DOWN),
).arrange(DOWN,buff=0.7).scale(0.9)
formulas_sine_2 = VGroup(*[
TexMobject(*f,**self.tex_map) for f in formulas_sine_string_2
])
# formulas_sine.arrange_in_grid(None,2)
formulas_sine_arrange_2 = VGroup(
formulas_sine_2[:2].arrange(RIGHT,buff=1),
formulas_sine_2[2:4].arrange(RIGHT,buff=1),
formulas_sine_2[4:].arrange(DOWN),
).arrange(DOWN,buff=0.7).scale(0.9)
formulas_sine_arrange_1.to_edge(DOWN,buff=0.3)
formulas_sine_arrange_1.to_edge(LEFT,buff=1)
formulas_sine_arrange_2.to_edge(DOWN,buff=0.3)
formulas_sine_arrange_2.to_edge(RIGHT,buff=1)
sine_law.align_to(formulas_sine_arrange_1,DOWN)
triangle.set_x(0)
center_vertices = triangle.get_center_of_edges()
labels = VGroup(*[
TexMobject(label,**self.tex_map).move_to(point) for label,point in zip(["C","B","A"],center_vertices)
])
fs1 = formulas_sine_1
fs2 = formulas_sine_2
# ------------------------------
h1 = TexMobject("h_1",**self.tex_map)
h2 = TexMobject("h_2",**self.tex_map)
x = TexMobject("x",**self.tex_map)
h1_line = self.get_h(d2,d1,d3)
h2_line = DashedLine(d3.get_center()+RIGHT*0.09,[d3.get_x()+0.09,d2.get_y()-0.09,0])
h3_line = DashedLine(d2.get_center()+RIGHT*0.09,h2_line.get_end())
rec_1 = Square().set_width(0.25)
rec_1 = VMobject().set_points_as_corners([rec_1.get_corner(v) for v in [UR,UL,DL]])
rec_2 = rec_1.deepcopy()
rec_1.next_to(h2_line.get_end(),UL,buff=0)
rec_2.rotate(h1_line.get_angle())
rec_2.next_to(h1_line.get_end(),DL,buff=0)
rec_2.shift(DOWN*0.1+RIGHT*0.05)
x.next_to(h3_line,DOWN,0.1)
h1.next_to(h1_line,RIGHT,0.1)
h1.shift(LEFT*0.15)
h2.next_to(h2_line,RIGHT,0.1)
# h2_line.rotate(PI,about_point=h2_line.get_start())
# ------------------------------
alpha_arc = ArcBetweenVectors(0.3,d1,d3,d2)
beta_arc = ArcBetweenVectors(1.7,d2,d3,d1)
gamma_arc = ArcBetweenVectors(1,d1,d2,d3)
alpha_p_arc = ArcBetweenVectors(0.4,Dot(h2_line.get_end()),d3,d2)
gamma_arc.rotate(gamma_arc.get_angle()*0.9,about_point=gamma_arc.get_arc_center())
alpha = LabelFromArc(alpha_arc,labels[0].get_width()*0.7,"\\alpha",distance_proportion=1.9,**self.tex_map)
beta = LabelFromArc(beta_arc,labels[0].get_width()*1.1,"\\beta",distance_proportion=1.9,**self.tex_map)
gamma = LabelFromArc(gamma_arc,labels[0].get_width()*1.1,"\\gamma",distance_proportion=1.9,**self.tex_map)
alpha_p = LabelFromArc(alpha_p_arc,labels[0].get_width()*1.1,"\\alpha'",distance_proportion=1.9,**self.tex_map)
alpha.shift(LEFT*0.25+DOWN*0.1)
but = TexMobject("{\\rm sin}(\\pi-\\alpha)={\\rm sin}(\\alpha)",**self.tex_map)
but.to_corner(UL)
t1 = Polygon(
d1.get_center(),d2.get_center(),h1_line.get_end(),
color=ORANGE,stroke_width=0,fill_opacity=0
)
t2 = Polygon(
d2.get_center(),d3.get_center(),h1_line.get_end(),
color=ORANGE,stroke_width=0,fill_opacity=0
)
t3 = Polygon(
d2.get_center(),h3_line.get_end(),h2_line.get_start(),
color=ORANGE,stroke_width=0,fill_opacity=0
)
t4 = Polygon(
d1.get_center(),h3_line.get_end(),h2_line.get_start(),
color=ORANGE,stroke_width=0,fill_opacity=0
)
def show_triange(t):
t.set_fill(None,0.3)
return t
def hide_triange(t):
t.set_fill(None,0)
return t
self.add(t1,t2,t3,t4)
# - SHOW CREATIONS
self.add_foreground_mobject(triangle)
self.play(
ShowCreation(triangle,rate_func=linear),
LaggedStart(*list(map(Write,labels)),lag_ratio=0.8),
run_time=2.5
)
self.wait()
self.play(
LaggedStart(*[
TransformFromCopy(m1,m2)
for m1,m2 in zip(labels[::-1],[alpha,beta,gamma])
],lag_ratio=0.7),
LaggedStart(*list(map(ShowCreation,[alpha_arc,beta_arc,gamma_arc])),lag_ratio=0.7),
run_time=3.5
)
self.wait()
self.play(LaggedStart(*list(map(Write,[h1_line,h1,rec_2])),lag_ratio=0.5))
self.all_mobs = VGroup(
fs1,fs2,labels,t1,t2,t3,t4,alpha,beta,gamma,alpha_arc,beta_arc,gamma_arc,
but,h1,h2,rec_1,rec_2,h1_line,h2_line,h3_line,x,sine_law,alpha_p,alpha_p_arc
)
self.funcs = [show_triange,hide_triange]
self.remove_foreground_mobject(triangle)
self.bring_to_front(triangle)
self.laws = VGroup()
self.sine_law()
self.add(h1,h2,x,alpha_p,alpha_p_arc,rec_1,rec_2,h1_line,h2_line,h3_line)
self.cosine_mobs = [labels,t1,t2,t3,t4,alpha,beta,gamma,h1,h2,x,alpha_p,h2_line]
self.cosine_utils = [cosa_t,cosb_t,cosc_t,frac_string,frac_strings]
self.cosine_law_A()
self.cosine_law_B()
self.cosine_law_C()
self.laws.generate_target()
laws = self.laws.target
for i in laws[:-1]:
i.set_width(laws[-1].get_width())
laws.arrange(DOWN)
laws.set_fill(None,1)
laws.shift(DOWN*0.5)
self.play(MoveToTarget(self.laws))
self.wait()
sine_law.shift(UP*0.7)
self.play(*[Write(mob) for mob in sine_law if mob.get_width() > 0.01])
self.wait()
def sine_law(self):
fs1,fs2,labels,t1,t2,t3,t4,alpha,beta,gamma,alpha_arc,beta_arc,gamma_arc,but,h1,h2,rec_1,rec_2,h1_line,h2_line,h3_line,x,sine_law,alpha_p,alpha_p_arc = self.all_mobs
# - TRANSFORMATIONS
show_triange,hide_triange = self.funcs
C,B,A = labels
# ----------------- Sine la
self.play(ApplyFunction(show_triange,t1))
self.wait()
self.play(
LaggedStart(
TransformFromCopy(beta[0],fs1[0][1]),
TransformFromCopy(h1[0],fs1[0][-4]),
TransformFromCopy(C[0],fs1[0][-2]),
lag_ratio=0.7
),
LaggedStart(*[Write(fs1[0][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(ApplyFunction(hide_triange,t1))
self.wait()
self.play(ApplyFunction(show_triange,t2))
self.wait()
self.play(
LaggedStart(
TransformFromCopy(gamma[0],fs1[1][1]),
TransformFromCopy(h1[0],fs1[1][-4]),
TransformFromCopy(B[0],fs1[1][-2]),
lag_ratio=0.7
),
LaggedStart(*[Write(fs1[1][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(ApplyFunction(hide_triange,t2))
# - - - - - - - -
self.wait()
self.play(
LaggedStart(
TransformFromCopy(fs1[0][-2],fs1[2][0]),
AnimationGroup(
TransformFromCopy(fs1[0][0],fs1[2][2]),
TransformFromCopy(fs1[0][1],fs1[2][3]),
lag_ratio=0
),
TransformFromCopy(fs1[0][2],fs1[2][4]),
TransformFromCopy(fs1[0][-4],fs1[2][-1]),
lag_ratio=0.3
),
# LaggedStart(*[Write(fs1[1][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(
LaggedStart(
TransformFromCopy(fs1[1][-2],fs1[3][0]),
AnimationGroup(
TransformFromCopy(fs1[1][0],fs1[3][2]),
TransformFromCopy(fs1[1][1],fs1[3][3]),
lag_ratio=0
),
TransformFromCopy(fs1[1][2],fs1[3][4]),
TransformFromCopy(fs1[1][-4],fs1[3][-1]),
lag_ratio=0.3
),
# LaggedStart(*[Write(fs1[1][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(
TransformFromCopy(fs1[2][:4],fs1[4][:4]),
TransformFromCopy(fs1[3][:4],fs1[4][-4:]),
Write(fs1[4][4]),
run_time=5
)
self.wait()
self.play(
LaggedStart(
TransformFromCopy(fs1[4][0],fs1[5][1]),
TransformFromCopy(fs1[4][-2:],fs1[5][3:5]),
TransformFromCopy(fs1[4][-4],fs1[5][-5]),
TransformFromCopy(fs1[4][2:4],fs1[5][-3:-1]),
lag_ratio=0.5
),
# TransformFromCopy(fs1[4][-2:],fs1[5][3:5]),
# TransformFromCopy(fs1[3][:4],fs1[4][-4:]),
LaggedStart(
Write(fs1[5][2]),
Write(fs1[5][-4]),
Write(fs1[5][6]),
lag_ratio=0.5
),
run_time=5
)
self.wait()
# ------------------------------
self.play(LaggedStart(*list(map(Write,[h2_line,h2,h3_line,x,rec_1])),lag_ratio=0.5))
self.wait()
self.play(Write(alpha_p),Write(alpha_p_arc))
self.wait()
self.play(Write(but))
self.wait()
self.play(Indicate(but),Indicate(alpha_p),Indicate(alpha_p_arc),run_time=3)
self.wait()
self.play(ApplyFunction(show_triange,t3))
self.wait()
self.play(
LaggedStart(
TransformFromCopy(alpha_p[0],fs2[0][1]),
TransformFromCopy(h2[0],fs2[0][-4]),
TransformFromCopy(B[0],fs2[0][-2]),
lag_ratio=0.7
),
LaggedStart(*[Write(fs2[0][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(ApplyFunction(hide_triange,t3))
self.wait()
self.play(ApplyFunction(show_triange,t4))
self.wait()
self.play(
LaggedStart(
TransformFromCopy(beta[0],fs2[1][1]),
TransformFromCopy(h2[0],fs2[1][-4]),
TransformFromCopy(A[0],fs2[1][-2]),
lag_ratio=0.7
),
LaggedStart(*[Write(fs2[1][i]) for i in [0,2,-3]]),
run_time=5
)
self.wait()
self.play(ApplyFunction(hide_triange,t4))
# ------------------------------
self.play(
LaggedStart(*[FadeIn(f) for f in fs2[2:]],lag_ratio=0.5),
run_time=8
)
self.wait()
# self.add(sine_law)
self.play(
ReplacementTransform(fs1[-1],sine_law[:len(fs1[-1])]),
ReplacementTransform(fs2[-1],sine_law[-len(fs2[-1]):]),
run_time=2.5
)
sine_law.save_state()
self.wait()
self.play(
Succession(
FadeToColor(sine_law,YELLOW),
Restore(sine_law)
),
AnimationGroup(
ShowCreationThenDestructionAround(sine_law.copy()),
ShowCreationThenDestructionAround(sine_law.copy()),
lag_ratio=1
)
)
self.wait()
self.remove(sine_law)
self.play(FadeOut(VGroup(fs1,fs2,but)))
self.wait()
def cosine_law_A(self):
labels,t1,t2,t3,t4,alpha,beta,gamma,h1,h2,x,alpha_p,h2_line = self.cosine_mobs
C,B,A = labels
cosa_t,cosb_t,cosc_t,frac_string,frac_strings = self.cosine_utils
show_triange,hide_triange = self.funcs
strings = [
["A","^2=","(","C","+","x",")","^2","+","{h_2}","^2"],
["A","^2=","C","^2","+","2","C","x","+","x^2","+","{h_2}","^2"],
["A","^2=","C","^2","+","2","C","x","+","B^2"],
["A","^2=","B","^2","+","C^2","+","2","C","x"],
["A","^2=","B","^2","+","C^2","+","2","C","B",*cosa_t],
["A","^2=","B","^2","+","C^2","-","2","B","C",*cosa_t],
]
f = VGroup(*[
TexMobject(*f,**self.tex_map)
for f in strings
])
for mob in f[:2]:
# mob[-1].set_color(self.tex_map["tex_to_color_map"]["h_2"])
mob[-1].align_to(mob[-3][-1],LEFT)
f.arrange(DOWN)
for mob in f[1:]:
mob.align_to(f[0],LEFT)
# mob.align_to(f[0],DOWN)
f.to_edge(DOWN,buff=1)
f.shift(LEFT)
f.shift(DOWN)
n = VGroup(*[self.get_label_numbers(fi) for fi in f])
# self.add(f,n)
# ---------------- Animations
self.play(ApplyFunction(show_triange,t4))
self.wait()
LAG = 0.4
h2_c = h2.copy()
self.play(
LaggedStart(
*[
TransformFromCopy(mob,f[0][i])
for mob,i in zip([A,C,x],[0,3,5])
],
ApplyMethod(h2_c.move_to,f[0][10]),
lag_ratio=LAG,
),
LaggedStart(
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
*[Write(f[0][i]) for i in [1,2,4,6,7,8,9,12]],
lag_ratio=LAG*2,
),
run_time=7
)
self.wait()
self.play(ApplyFunction(hide_triange,t4))
LAG = 0.4
self.play(
LaggedStart(
*[
ReplacementTransform(f[0][i].copy(),f[1][j])
for i,j in zip(
[0,1,3,3,4,4,5,5,7,7,7 ,8 ,10,12],
[0,1,2,6,4,8,7,9,3,5,10,11,13,15]
)
],
# ApplyMethod(h2.copy().move_to,f[0][10]),
lag_ratio=0,
),
run_time=7
)
brace = Brace(f[1][9:-2],DOWN)
self.play(GrowFromCenter(brace))
# self.play(LaggedStart(FocusOn(t3),FocusOn(t3),lag_ratio=0.4))
self.play(ApplyFunction(show_triange,t3))
self.play(*[Indicate(mob,run_time=2) for mob in [x,B,h2]])
B2 = brace.get_tex("B^2")[0]
B2[0].set_color(self.tex_map["tex_to_color_map"]["B"])
self.play(Write(B2))
self.play(
LaggedStart(
*[
ReplacementTransform(f[1][i].copy(),f[2][j])
for i,j in zip(
[*range(9)],
[*range(9)],
)
],
lag_ratio=0,
),
run_time=2
)
self.play(ReplacementTransform(B2,f[2][9:]),FadeOut(brace))
# F 2 - 3
self.wait(0.5)
f[3].align_to(f[2],UP)
self.play(
*[
ReplacementTransform(f[2][i],f[3][j])
for i,j in zip([*range(len(f[2]))],[0,1,5,6,4,8,9,10,7,2,3])
],
run_time=2.5
)
but = TexMobject("{\\rm cos}(\\pi\\pm \\alpha)=-{\\rm cos}\\alpha",tex_to_color_map={"\\alpha":RED_A})
but.to_corner(UL)
c1 = TexMobject("-","{\\rm cos}","\\alpha","=","{","x","\\over","B","}",**self.tex_map)
c1[-1].set_color(ORANGE)
c1.to_edge(RIGHT)
c1.shift(DOWN)
c2 = TexMobject("-","B",*cosa_t,"=","x",**self.tex_map)
c2.move_to(c1).align_to(c1,LEFT).shift(LEFT*c1[0].get_width())
self.play(Write(but),run_time=2.5)
self.wait()
self.play(Write(VGroup(*[c for c in c1 if c.get_width() > 0.1])))
self.play(ApplyFunction(hide_triange,t3))
self.wait()
# self.add(c1,c2)
# print
self.play(
*[ReplacementTransform(c1[i],c2[j]) for i,j in zip(
[0,1,2,3,5,7],
[0,2,3,4,5,1]
)],
FadeOut(c1[6]),
run_time=2
)
f[4].next_to(f[3],DOWN,aligned_edge=LEFT)
self.wait()
self.play(
*[TransformFromCopy(f[3][i],f[4][j]) for i,j in zip(range(10),range(10))],
run_time=2
)
self.wait()
self.play(
*[
TransformFromCopy(c2[i],f[4][j])
for i,j in zip([1,2,3],[10,11,12]
)],
ApplyMethod(c2[0].move_to,f[4][7]),
FadeOut(f[4][7]),
run_time=2
)
f[4][7].become(c2[0])
self.wait()
f[5].align_to(f[4],UP)
self.play(*[
ReplacementTransform(f[4][i],f[5][j])
for i,j in zip([*range(len(f[4]))],[*range(9),10,9,11,12])
])
self.wait()
f4 = f[5].copy()
f4.fade(0.5)
self.play(Write(f4,stroke_width=6),FadeToColor(f[4],YELLOW,rate_func=there_and_back,run_time=2))
self.wait()
self.remove(f4,f[4])
self.remove(c2[0])
self.play(
f[5].scale,0.8,
f[5].to_corner,DR,{"buff":0.1},
)
self.play(
f[5].set_fill,None,0.5,
FadeOut(VGroup(*[f[i] for i in [0,1,3]])),
FadeOut(c2[1:]),FadeOut(h2_c),FadeOut(but)
)
self.remove(c2[0])
self.laws.add(f[5])
# ---------------------
# self.add(brace)
def cosine_law_C(self):
labels,t1,t2,t3,t4,alpha,beta,gamma,h1,h2,x,alpha_p,h2_line = self.cosine_mobs
C,B,A = labels
cosa_t,cosb_t,cosc_t,frac_string,frac_strings = self.cosine_utils
show_triange,hide_triange = self.funcs
strings = [
["C","^2=","(","A","-","y",")","^2","+","{h_1}","^2"],
["C","^2=","A","^2","-","2","A","y","+","y","^2","+","{h_1}","^2"],
["C","^2=","A","^2","-","2","A","y","+","B^2"],
["C","^2=","A","^2","+","B^2","-","2","A","y"],
["C","^2=","A","^2","+","B^2","-","2","A","B",*cosc_t],
]
p1,p2,p3 = t2.get_vertices()
y_masure = MeasureDistance(Line(p3,h2_line.get_start()),buff=0.2)
y = y_masure.get_tex("y",**self.tex_map)
# self.add(y_masure,y)
# self.add(*[Dot(p) for p in [p2,p3]])
f = VGroup(*[
TexMobject(*f,**self.tex_map)
for f in strings
])
for mob in f[:2]:
# mob[-1].set_color(self.tex_map["tex_to_color_map"]["h_2"])
mob[-1].align_to(mob[-3][-1],LEFT)
f.arrange(DOWN)
for mob in f[1:]:
mob.align_to(f[0],LEFT)
# mob.align_to(f[0],DOWN)
f.to_edge(DOWN,buff=1)
f.shift(LEFT)
# f.shift(DOWN)
n = VGroup(*[self.get_label_numbers(fi) for fi in f])
# self.add(f,n)
# ---------------- Animations
self.play(LaggedStartMap(FadeIn,y_masure),Write(y))
self.play(ApplyFunction(show_triange,t1))
self.wait()
LAG = 0.4
h2_c = h1.copy()
self.play(
LaggedStart(
*[
TransformFromCopy(mob,f[0][i])
for mob,i in zip([C,A,y],[0,3,5])
],
ApplyMethod(h2_c.move_to,f[0][10]),
lag_ratio=LAG,
),
LaggedStart(
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
*[Write(f[0][i]) for i in [1,2,4,6,7,8,9,12]],
lag_ratio=LAG*2,
),
run_time=7
)
self.wait()
# self.add(n,f)
self.play(ApplyFunction(hide_triange,t1))
LAG = 0.4
self.play(
LaggedStart(
*[
ReplacementTransform(f[0][i].copy(),f[1][j])
for i,j in zip(
[0,1,3,3,4,4,5,5,7,7,7 ,8 ,10,12],
[0,1,2,6,4,8,7,9,3,5,10,11,13,15]
)
],
# ApplyMethod(h2.copy().move_to,f[0][10]),
lag_ratio=0,
),
run_time=7
)
brace = Brace(f[1][9:-2],DOWN)
self.play(GrowFromCenter(brace))
# self.play(LaggedStart(FocusOn(t3),FocusOn(t3),lag_ratio=0.4))
self.play(ApplyFunction(show_triange,t2))
self.play(*[Indicate(mob,run_time=2) for mob in [y,B,h1]])
B2 = brace.get_tex("B^2")[0]
B2[0].set_color(self.tex_map["tex_to_color_map"]["B"])
self.play(Write(B2))
self.play(
LaggedStart(
*[
ReplacementTransform(f[1][i].copy(),f[2][j])
for i,j in zip(
[*range(9)],
[*range(9)],
)
],
lag_ratio=0,
),
run_time=2
)
self.play(ReplacementTransform(B2,f[2][9:]),FadeOut(brace))
# F 2 - 3
self.wait(0.5)
f[3].align_to(f[2],UP)
self.play(
*[
ReplacementTransform(f[2][i],f[3][j])
for i,j in zip([*range(len(f[2]))],[0,1,2,3,7,8,9,10,4,5,6])
],
run_time=2.5
)
c1 = TexMobject("{\\rm cos}","\\gamma","=","{","y","\\over","B","}",**self.tex_map)
c1[-1].set_color(ORANGE)
c1.to_edge(RIGHT)
c1.shift(DOWN)
c2 = TexMobject("B",*cosc_t,"=","y",**self.tex_map)
c2.move_to(c1).align_to(c1,LEFT).shift(LEFT*c1[0].get_width())
self.play(Write(VGroup(*[c for c in c1 if c.get_width() > 0.1])))
self.play(ApplyFunction(hide_triange,t2))
self.wait()
self.play(
*[ReplacementTransform(c1[i],c2[j]) for i,j in zip([0,1,2,4,6],[1,2,3,4,0])],
FadeOut(c1[5]),
run_time=2
)
f[4].next_to(f[3],DOWN,aligned_edge=LEFT)
self.wait()
self.play(
*[TransformFromCopy(f[3][i],f[4][j]) for i,j in zip(range(10),range(10))],
run_time=2
)
self.wait()
self.play(
*[TransformFromCopy(c2[i],f[4][j]) for i,j in zip([0,1,2],[10,11,12])],
run_time=2
)
self.wait()
self.play(FadeOut(c2))
self.wait()
f4 = f[4].copy()
f4.set_fill(None,0)
self.play(Write(f4,stroke_width=6),FadeToColor(f[4],YELLOW,rate_func=there_and_back,run_time=2))
self.wait()
self.laws.add(f[4])
self.remove(h2_c)
self.play(FadeOut(f[:4]))
# self.remove(f4,f[4])
# self.play(f[5].to_corner,DL)
# ---------------------
# self.add(brace)
def cosine_law_B(self):
labels,t1,t2,t3,t4,alpha,beta,gamma,h1,h2,x,alpha_p,h2_line = self.cosine_mobs
C,B,A = labels
cosa_t,cosb_t,cosc_t,frac_string,frac_strings = self.cosine_utils
show_triange,hide_triange = self.funcs
strings = [
["B","^2","=","x","^2","+","h_2","^2",],
["B","^2","=","x","^2","+","A","^2","-","(","C","+","x",")","^2"],
["B","^2","=","x","^2","+","A","^2","-","C","^2","-","2","C","x","-","x","^2"],
["B","^2","=","A","^2","-","C","^2","-","2","C","x"],
["B","^2","=","A","^2","-","C","^2","-","2","C","(","A",*cosb_t,"-","C",")"],
["B","^2","=","A","^2","-","C","^2","-","2","C","A",*cosb_t,"+","2","C","^2"],
["B","^2","=","A","^2","+","C","^2","-","2","A","C",*cosb_t],
]
c_string = [
["A","^2","=","h_2","^2","+","(C","+","x",")","^2"],
["A","^2","-","(C","+","x",")","^2","=","h_2","^2"],
[*cosb_t,"=",*frac_strings(["C","+","x"],["A"])],
["A",*cosb_t,"-","C","=","x"]
]
# self.add(y_masure,y)
# self.add(*[Dot(p) for p in [p2,p3]])
f = VGroup(*[
TexMobject(*i,**self.tex_map)
for i in strings
])
c = VGroup(*[
TexMobject(*i,**self.tex_map)
for i in c_string
])
# f[1].remove(f[1][-1])
for mob,i in zip([f[0],c[0],c[1]],[7,4,11]):
mob[i][0].set_color(BLUE_B)
ex = mob[i-1][-1]
ex.set_color(WHITE)
mob[i-1].remove(ex)
mob.add(ex)
f.arrange(DOWN)
for mob in f[1:]:
mob.align_to(f[0],LEFT)
# mob.align_to(f[0],DOWN)
f.to_edge(DOWN,buff=0.2)
f.to_edge(LEFT,buff=0.2)
c.arrange(DOWN)
c.to_edge(RIGHT,buff=0.1)
c.shift(DOWN*1.3)
c[0].shift(UP*0.3)
c[1].align_to(c[0][:5],RIGHT)
c[1].align_to(c[0],UP)
# f.shift(LEFT)
# f.shift(DOWN)
n = VGroup(*[self.get_label_numbers(fi) for fi in f])
n2 = VGroup(*[self.get_label_numbers(fi) for fi in c])
# self.add(f,c)
# -----------------------------------------------------
# -----------------------------------------------------
self.play(ApplyFunction(show_triange,t3))
self.wait()
LAG = 0.4
h2_c = h1.copy()
f.shift(DOWN*0.5+RIGHT*2)
self.play(
LaggedStart(
*[
TransformFromCopy(mob,f[0][i])
for mob,i in zip([B,x],[0,3])
],
AnimationGroup(
TransformFromCopy(h2[0][0],f[0][6]),
TransformFromCopy(h2[0][1],f[0][7]),
lag_ratio=0
),
lag_ratio=LAG,
),
LaggedStart(
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
*[Write(f[0][i]) for i in [1,2,4,5,8]],
lag_ratio=LAG*2,
),
run_time=7
)
self.wait()
# self.add(n,f)
self.play(ApplyFunction(hide_triange,t3))
self.wait()
self.play(ApplyFunction(show_triange,t4))
self.wait()
self.play(
LaggedStart(
*[
TransformFromCopy(mob,c[0][i])
for mob,i in zip([A],[0])
],
AnimationGroup(
TransformFromCopy(h2[0][0],c[0][3]),
TransformFromCopy(h2[0][1],c[0][4]),
lag_ratio=0
),
*[
TransformFromCopy(mob,c[0][i])
for mob,i in zip([C,x],[7,9])
],
lag_ratio=LAG,
),
LaggedStart(
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
Animation(Mobject()),
*[Write(c[0][i]) for i in [1,2,12,5,6,8,10,11]],
lag_ratio=LAG*2,
),
run_time=7
)
self.wait()
self.play(*[
ReplacementTransform(c[0][i],c[1][j])
for i,j in zip(range(len(c[0])),[0,1,9,10,11,2,3,4,5,6,7,8,12])
],run_time=3)
self.wait()
self.play(*[TransformFromCopy(f[0][i],f[1][j])
for i,j in zip(range(6),range(6))
])
self.wait()
self.play(*[TransformFromCopy(c[1][i],f[1][j])
for i,j in zip(range(9),range(6,15))
],run_time=3.5)
self.wait()
self.play(ApplyFunction(hide_triange,t4))
self.wait()
self.play(c[1].to_edge,RIGHT,c[1].fade,1)
self.wait()
self.play(*[ReplacementTransform(f[1][i].copy(),f[2][j])
for i,j in zip([*range(9),10,10,11,11,12,12,14,14,14],
[*range(9),9, 13,11,15,14,16,10,12,17]
)
],run_time=3.5)
self.wait()
self.play(*[
ApplyMethod(f[2][i].fade,0.7)
for i in [3,4,15,16,17]
])
self.wait()
self.play(*[ReplacementTransform(f[2][i].copy(),f[3][j])
for i,j in zip([*range(3),*range(6,15)],
[*range(len(f[3]))]
)
],run_time=3.5)
self.wait()
# --------- Show cos beta = (c+x) / a
self.play(ApplyFunction(show_triange,t4))
self.wait()
self.play(
LaggedStart(
Write(c[2][0]),
TransformFromCopy(beta,c[2][1]),
Animation(Mobject()),
Write(c[2][2]),
TransformFromCopy(C,c[2][4]),
Animation(Mobject()),
Write(c[2][5]),
TransformFromCopy(x,c[2][6]),
Animation(Mobject()),
Write(c[2][7]),
TransformFromCopy(A,c[2][8]),
lag_ratio=0.4
),
run_time=10
)
self.wait()
c[3].shift(LEFT*abs(c[2][2].get_x()-c[3][5].get_x()))
c[3].align_to(c[2][1],UP)
self.play(
FadeOut(c[2][7]),
*[
ReplacementTransform(c[2][i],c[3][j])
for i,j in zip(
[0,1,2,4,5,6,8],
[1,2,5,4,3,6,0]
)
],run_time=4)
# ---------------- Trabsfirn 2Cx to 2C(Acos beta + C)
self.wait()
self.play(
*[TransformFromCopy(f[3][i],f[4][j]) for i,j in zip(range(11),range(11))],
*[Write(f[4][i]) for i in [11,17]],
*[TransformFromCopy(c[3][i],f[4][j]) for i,j in zip(range(5),range(12,17))],
run_time=4
)
self.wait()
self.play(ApplyFunction(hide_triange,t4))
self.play(c[3].to_edge,RIGHT,c[3].fade,1)
# ---------------- Expand 2C(Acos beta + C)
self.wait()
self.play(
*[ReplacementTransform(f[4][i].copy(),f[5][j]) for i,j in zip(range(9),range(9))],
*[ReplacementTransform(f[4][i].copy(),f[5][j]) for i,j in zip(
[9,9, 10,10,12,13,14,15,16],
[9,15,10,16,11,12,13,14,16])
],
AnimationGroup(
Animation(Mobject()),
Animation(Mobject()),
Write(f[5][-1]),
lag_ratio=1
),
run_time=4
)
# ------------------------------ LAST
f[6].align_to(f[5],UP)
self.wait()
self.play(*[ShowCreationThenDestructionAround(i,run_time=2.3) for i in [f[5][6:8],f[5][15:]]])
self.wait()
self.play(
*[
ReplacementTransform(f[5][i],f[6][j])
for i,j in zip(
[*range(10),10,11,12,13,14,16,17],
[*range(10),11,10,12,13, 5,6 ,7]
)
],
FadeOut(f[5][15]),
run_time=4
)
# ------ Show
f4 = f[6].copy()
f4.set_fill(None,0)
self.wait()
self.play(Write(f4,stroke_width=6),FadeToColor(f[6],YELLOW,rate_func=there_and_back,run_time=2))
self.wait()
self.play(
f[6].scale,0.8,
f[6].next_to,self.laws[-1],UP,0.2,
f[6].align_to,self.laws[-1],LEFT,
f[6].set_fill,None,0.5
)
self.laws.add(f[6])
self.play(FadeOut(f[:5]))
def get_label_numbers(self,formula,**tex_kwargs):
n = VGroup()
for i,e in enumerate(formula):
t = Text(f"{i}",font="DejaVu").set_height(0.2)
t.next_to(e,DOWN,0)
if e.get_width() > 0.01:
n.add(t)
# else:
# n.add(t)
return n
def get_h(self, dot, d1, d2,invert=True):
line = Line(d1.get_center(),d2.get_center())
vector = line.get_unit_vector()
sign = 1 if invert else -1
normal_vector = rotate_vector(vector,sign*PI/2)
def get_distance_point_line(line,dot):
x_0, y_0, z_0 = dot.get_center()
X_0 = line.point_from_proportion(0)
X_1 = line.point_from_proportion(1)
x_1, y_1, z_1 = X_0
x_2, y_2, z_2 = X_1
return abs((x_2-x_1)*(y_1-y_0)-(x_1-x_0)*(y_2-y_1)/get_norm(line.get_vector()))
distance = get_distance_point_line(line,dot)
return DashedLine(dot.get_center(),dot.get_center()+distance*normal_vector)
|
AnimationsWithManim_Elteoremadebeethoven/math_capsules/mnemonics_trig.py
|
from manimlib.imports import *
class Sqrt2(VGroup):
def __init__(self, n, **kwargs):
super().__init__(**kwargs)
body = TexMobject("\\frac{\\sqrt{%s}}{2}"%n)[0]
number = body[2]
self.top = body[:3]
body.remove(body[2])
self.add(body,number)
class Mnemonics(Scene):
def construct(self):
# MOBS DEFINITIONS ----------------------------------
l_buff = 1.2
left_labels = VGroup(*[
TextMobject(t) for t in ["Radians:","Degrees:","sin","cos","tan"]
])
left_labels.arrange(DOWN,buff=l_buff)
radians_grp = VGroup(*[
TexMobject(t) for t in ["0",*["\\frac{\\pi}{%s}"%n for n in [6,4,3,2]]]
])
radians_grp.arrange(RIGHT,buff=l_buff)
radians_grp.next_to(left_labels[0],RIGHT,buff=l_buff)
degrees_grp = VGroup(*[
TexMobject(f"{t}^\\circ") for t in [0,30,45,60,90]
])
# TRIG PRE
sin_vals = VGroup(*[
Sqrt2(n) for n in range(5)
])
cos_vals = sin_vals.deepcopy()
cos_vals = cos_vals[::-1]
tan_vals = VGroup(*[
TexMobject("\\frac{\\sqrt{%s}}{\\sqrt{%s}}"%(n,d))[0]
for n,d in zip(range(5),list(range(5))[::-1])
])
# TRIG POST
sin_vals_p = VGroup(*[
TexMobject(t)[0] for t in ["0","\\frac{1}{2}","\\frac{\\sqrt{2}}{2}","\\frac{\\sqrt{3}}{2}","1"]
])
cos_vals_p = VGroup(*[
TexMobject(t)[0] for t in ["0","\\frac{1}{2}","\\frac{\\sqrt{2}}{2}","\\frac{\\sqrt{3}}{2}","1"][::-1]
])
tan_vals_p = VGroup(*[
TexMobject(t)[0] for t in ["0","\\frac{\\sqrt{3}}{3}","1","\\sqrt{3}","\\infty"]
])
degrees_grp.next_to(left_labels[1],RIGHT,buff=1.2)
all_grp = VGroup(
left_labels,
radians_grp,
degrees_grp,
sin_vals,
cos_vals,
tan_vals,
sin_vals_p,
cos_vals_p,
tan_vals_p,
)
all_grp.move_to(ORIGIN)
# - Order the values
for i in range(len(degrees_grp)):
for j,mob in zip(range(1,5),[degrees_grp,sin_vals,cos_vals,tan_vals]):
mob[i].set_x(radians_grp[i].get_x())
mob[i].set_y(left_labels[j].get_y())
for i in range(len(degrees_grp)):
for j,mob in zip(range(2,5),[sin_vals_p,cos_vals_p,tan_vals_p]):
mob[i].set_x(radians_grp[i].get_x())
mob[i].set_y(left_labels[j].get_y())
v_l_buff = 0.5*UP
h_l_buff = 0.7*RIGHT
v_line = Line(left_labels.get_corner(UR)+v_l_buff*0.9,left_labels.get_corner(DR)-v_l_buff)
v_line.shift(RIGHT*0.6)
h_line = Line(all_grp.get_corner(UL)-h_l_buff,all_grp.get_corner(UR)+h_l_buff)
h_line.set_y(v_line.get_start()[1])
h_line_d = h_line.deepcopy().set_y(v_line.get_end()[1])
h_lines = VGroup(h_line,h_line_d)
for i in range(1,4):
line = h_line.copy()
line.set_y((left_labels[i].get_y()+left_labels[i+1].get_y())/2)
h_lines.add(line)
# self.add(*all_grp,v_line,h_lines)
# ----------------------------------------------
# ANIMATIONS -----------------------------------
# ----------------------------------------------
self.play(
LaggedStart(*list(map(GrowFromCenter,[v_line,*h_lines])),run_time=2.5,lag_ratio=0),
Write(left_labels,run_time=2.5),
Write(radians_grp,run_time=2.5),
Write(degrees_grp,run_time=2.5),
)
self.wait()
s_grp = VGroup(*[f[0] for f in sin_vals])
c_grp = VGroup(*[f[0] for f in cos_vals])
s_vals = VGroup(*[f[1] for f in sin_vals])
c_vals = VGroup(*[f[1] for f in cos_vals])[::-1]
self.play(
Write(s_grp),
Write(c_grp),
run_time=3.5
)
self.wait()
self.play(Write(s_vals),run_time=4)
self.play(Write(c_vals),run_time=4)
self.wait()
LAG_RATIO = 0.4
PATH_ARC = 120*DEGREES
self.play(
LaggedStart(*[
Write(tv[3])
for tv in tan_vals
],lag_ratio=LAG_RATIO*3.2),
LaggedStart(*[
TransformFromCopy(sn,tv[:3],path_arc=PATH_ARC,run_time=3)
for sn,tv in zip([t.top for t in sin_vals],tan_vals)
],lag_ratio=LAG_RATIO),
LaggedStart(*[
TransformFromCopy(cn,tv[4:],path_arc=PATH_ARC,run_time=3)
for cn,tv in zip([t.top for t in cos_vals],tan_vals)
],lag_ratio=LAG_RATIO),
)
self.wait()
LAG_RATIO = 0.4
self.play(
AnimationGroup(
LaggedStart(*[
ReplacementTransform(sv,svp)
for sv,svp in zip(sin_vals,sin_vals_p)
],lag_ratio=LAG_RATIO),
LaggedStart(*[
ReplacementTransform(sv,svp)
for sv,svp in zip(cos_vals,cos_vals_p)
],lag_ratio=LAG_RATIO),
LaggedStart(*[
ReplacementTransform(sv,svp)
for sv,svp in zip(tan_vals,tan_vals_p)
],lag_ratio=LAG_RATIO),
lag_ratio=0.8
)
)
self.wait(3)
self.play(*list(map(FadeOut,self.mobjects)))
self.wait()
|
AnimationsWithManim_Elteoremadebeethoven/.github/ISSUE_TEMPLATE.md
|
# __**WARNING**__
**Before writing an issue, please check the following links if someone has already resolved your question. If you are asking things that have already been resolved I will have no choice but to close your issue.**
* [Manim issues](https://github.com/3b1b/manim/issues?q=is%3Aissue+is%3Aclosed)
* [Stackoverflow](https://stackoverflow.com/questions/tagged/manim)
* [Reddit](https://www.reddit.com/r/manim/)
* [Official documentation](https://www.eulertour.com/learn/manim/)
* [My documentation](https://elteoremadebeethoven.github.io/manim_3feb_docs.github.io/html/index.html)
* [Todd tutorial](https://talkingphysics.wordpress.com/2019/01/08/getting-started-animating-with-manim-and-python-3-7/)
* [Malhora tutorial](https://github.com/malhotra5/Manim-Tutorial)
* [My tutorials](https://www.youtube.com/watch?v=ENMyFGmq5OA&list=PL2B6OzTsMUrwo4hA3BBfS7ZR34K361Z8F)
**You can joined to the Discord community [here](https://discordapp.com/invite/mMRrZQW)**
# Points to consider before writing your issue
* This repository works with the Manim version of February 3, unless otherwise indicated. If your code does not work, check that you are using the correct version.
* At the moment Manim works with Python 3.7, not with 3.8. This is because several of the dependencies have not yet been updated.
* If the terminal throws an error, please write it completely with the markdown format.
* Be clear and specific with your problem, share the code (and files, if applicable) and the command you use when rendering the video.
# Fast markdown tutorial.
## Inline code:
**INPUT**
The code is \`TexMobject\` write \`TeX\`.
**OUTPUT**
The code is `TexMobject` write `TeX`.
## Multiline code
**INPUT**
My code is:
\`\`\`python
Here is
a multiline
code
\`\`\`
**OUTPUT**
My code is:
```python
Here is
a multiline
code
```
**[LEARN MORE HERE](https://guides.github.com/features/mastering-markdown/#what)**
|
AnimationsWithManim_Elteoremadebeethoven/English/4_transform/transform_issues.md
|
# Bad animation with Transform
```python3
class TransformIssues(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# 0
text_2=TextMobject("B")
text_2.next_to(text_1,UP,buff=1)
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
ReplacementTransform(text_2,text_1[1])
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformIssues.gif" /></p>
```python3
class TransformIssuesSolution1(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# 0
text_2=TextMobject("B")
text_2.next_to(text_1,UP,buff=1)
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
# Add [:] to the firts or second parameter
ReplacementTransform(text_2[:],text_1[1])
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformIssuesSolution1.gif" /></p>
```python3
class TransformIssuesSolutionInfallible(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# 0
text_2=TextMobject("B")
text_2.next_to(text_1,UP,buff=1)
#Create a copy of the objects
text_1_1_c=TextMobject("B")\
.match_style(text_1[1])\
.match_width(text_1[1])\
.move_to(text_1[1])
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
# Add [:] to the firts or second parameter
ReplacementTransform(text_2,text_1_1_c)
)
self.remove(text_1_1_c)
self.add(text_1[1])
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformIssuesSolutionInfallible.gif" /></p>
# For more information see [this](https://github.com/3b1b/manim/issues/425).
|
AnimationsWithManim_Elteoremadebeethoven/English/4_transform/4_transform.py
|
from big_ol_pile_of_manim_imports import *
class TransformationText1V1(Scene):
def construct(self):
texto1 = TextMobject("First text")
texto2 = TextMobject("Second text")
self.play(Write(texto1))
self.wait()
self.play(Transform(texto1,texto2))
self.wait()
class TransformationText1V2(Scene):
def construct(self):
texto1 = TextMobject("First text")
texto1.to_edge(UP)
texto2 = TextMobject("Second text")
self.play(Write(texto1))
self.wait()
self.play(Transform(texto1,texto2))
self.wait()
class TransformationText2(Scene):
def construct(self):
text1 = TextMobject("Function")
text2 = TextMobject("Derivative")
text3 = TextMobject("Integral")
text4 = TextMobject("Transformation")
self.play(Write(text1))
self.wait()
#Trans text1 -> text2
self.play(ReplacementTransform(text1,text2))
self.wait()
#Trans text2 -> text3
self.play(ReplacementTransform(text2,text3))
self.wait()
#Trans text3 -> text4
self.play(ReplacementTransform(text3,text4))
self.wait()
class CopyTextV1(Scene):
def construct(self):
formula = TexMobject(
"\\frac{d}{dx}", #0
"(", #1
"u", #2
"+", #3
"v", #4
")", #5
"=", #6
"\\frac{d}{dx}", #7
"u", #8
"+", #9
"\\frac{d}{dx}", #10
"v" #11
)
formula.scale(2)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9])
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10])
)
self.wait()
class CopyTextV2(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
class CopyTextV3(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
formula[8].set_color(RED)
formula[11].set_color(BLUE)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
class CopyTextV4(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
for letter,color in [("u",RED),("v",BLUE)]:
formula.set_color_by_tex(letter,color)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
class CopyTwoFormulas1(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg", #0
"\\forall", #1
"x", #2
":", #3
"P(x)" #4
)
formula2 = TexMobject(
"\\exists", #0
"x", #1
":", #2
"\\neg", #3
"P(x)" #4
)
for size,pos,formula in [(2,2*UP,formula1),(2,2*DOWN,formula2)]:
formula.scale(size)
formula.move_to(pos)
self.play(Write(formula1))
self.wait()
changes = [
[(0,1,2,3,4),
# | | | | |
# v v v v v
(3,0,1,2,4)],
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
class CopyTwoFormulas2(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
for tam,pos,formula in [(2,2*UP,formula1),(2,2*DOWN,formula2)]:
formula.scale(tam)
formula.move_to(pos)
self.play(Write(formula1))
self.wait()
changes = [
# First time
[(2,3,4),
# | | |
# v v v
(1,2,4)],
# Second time
[(0,),
# |
# v
(3,)],
# Third time
[(1,),
# |
# v
(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
class CopyTwoFormulas2Color(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
parametters = [(2,2*UP,formula1,GREEN,"\\forall"),
(2,2*DOWN,formula2,ORANGE,"\\exists")]
for size,pos,formula,col,sim in parametters:
formula.scale(size)
formula.move_to(pos)
formula.set_color_by_tex(sim,col)
formula.set_color_by_tex("\\neg",PINK)
self.play(Write(formula1))
self.wait()
changes = [
[(2,3,4),(1,2,4)],
[(0,),(3,)],
[(1,),(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
class CopyTwoFormulas3(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
parametters = [(2,2*UP,formula1,GREEN,"\\forall"),
(2,2*DOWN,formula2,ORANGE,"\\exists")]
for size,pos,formula,col,sim in parametters:
formula.scale(size)
formula.move_to(pos)
formula.set_color_by_tex(sim,col)
formula.set_color_by_tex("\\neg",PINK)
self.play(Write(formula1))
self.wait()
changes = [
[(2,3,4),(1,2,4)],
[(0,),(3,)],
[(1,),(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i],formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
class ChangeTextColorAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(3)
self.play(Write(text))
self.wait()
self.play(
text.set_color, YELLOW,
run_time=2
)
self.wait()
class ChangeSizeAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
self.play(Write(text))
self.wait()
self.play(
text.scale, 3,
run_time=2
)
self.wait()
class MoveText(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
text.shift(LEFT*2)
self.play(Write(text))
self.wait()
self.play(
text.shift, RIGHT*2,
run_time=2,
path_arc=0 #Change 0 by -np.pi
)
self.wait()
class ChangeColorAndSizeAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
text.shift(LEFT*2)
self.play(Write(text))
self.wait()
self.play(
text.shift, RIGHT*2,
text.scale, 2,
text.set_color, RED,
run_time=2,
)
self.wait()
|
AnimationsWithManim_Elteoremadebeethoven/English/4_transform/transform_issues.py
|
from big_ol_pile_of_manim_imports import *
class TextLike1DArrays(Scene):
def construct(self):
text=TextMobject("Te","xt")
# text=TextMobject("Te","xt")[0] # <- Recent versions
for i in text:
self.play(FadeIn(i))
self.wait()
self.play(FadeOut(i))
self.wait()
class TextLike2DArraysV1(Scene):
def construct(self):
text=TextMobject("Te","xt")
# text=TextMobject("Te","xt")[0] # <- Recent versions
self.play(FadeIn(text[0][0]))
self.play(FadeIn(text[0][1]))
self.play(FadeIn(text[1][0]))
self.play(FadeIn(text[1][1]))
self.wait()
class TextLike2DArraysV2(Scene):
def construct(self):
text=TextMobject("Te","xt")
for i in text:
for j in i:
self.play(FadeIn(j))
self.wait()
class TextLike2DArraysV3(Scene):
def construct(self):
text=TextMobject("Te","xt")
# text=TextMobject("Te","xt")[0] # <- Recent versions
for i in range(len(text)):
for j in range(len(text[i])):
self.play(FadeIn(text[i][j]))
self.wait()
class TransformIssues(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# text_1=TextMobject("A","B","C")[0] # <- Recent versions
# 0
text_2=TextMobject("B")
# text_2=TextMobject("B")[0]
text_2.next_to(text_1,UP,buff=1)
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
ReplacementTransform(text_2,text_1[1])
)
self.wait()
class TransformVGroup(Scene):
def construct(self):
text_n=TextMobject("A")
text_v=VGroup(TextMobject("A")).next_to(text_n,DOWN)
self.play(Write(text_n))
self.play(ReplacementTransform(text_n,text_v))
#Solution
# ReplacementTransform(text_n,text_v[0])
self.wait()
class TransformIssuesSolution1(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# text_1=TextMobject("A","B","C")[0] # <- Recent versions
# 0
text_2=TextMobject("B")
# text_2=TextMobject("B")[0]
text_2.next_to(text_1,UP,buff=1)
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
# Add [:] to the firts or second parameter
ReplacementTransform(text_2[:],text_1[1])
)
self.wait()
class TransformIssuesSolutionInfallible(Scene):
def construct(self):
# 0 1 2
text_1=TextMobject("A","B","C")
# text_1=TextMobject("A","B","C")[0] # <- Recent versions
# 0
text_2=TextMobject("B")
# text_2=TextMobject("B")[0]
text_2.next_to(text_1,UP,buff=1)
#Create a copy of the objects
text_1_1_c=TextMobject("B")\
.match_style(text_1[1])\
.match_width(text_1[1])\
.move_to(text_1[1])
#Add the elements 0 and 2 of text_1 to screen and text_2
self.play(
*[
FadeIn(text_1[i])
for i in [0,2]
],
FadeIn(text_2)
)
self.wait()
self.play(
# Add [:] to the firts or second parameter
ReplacementTransform(text_2,text_1_1_c)
)
self.remove(text_1_1_c)
self.add(text_1[1])
self.wait()
|
AnimationsWithManim_Elteoremadebeethoven/English/4_transform/scenes.md
|
# Programs
```python3
class TransformationText1V1(Scene):
def construct(self):
texto1 = TextMobject("First text")
texto2 = TextMobject("Second text")
self.play(Write(texto1))
self.wait()
self.play(Transform(texto1,texto2))
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformationText1V1.gif" /></p>
```python3
class TransformationText1V2(Scene):
def construct(self):
texto1 = TextMobject("First text")
texto1.to_edge(UP)
texto2 = TextMobject("Second text")
self.play(Write(texto1))
self.wait()
self.play(Transform(texto1,texto2))
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformationText1V2.gif" /></p>
```python3
class TransformationText2(Scene):
def construct(self):
text1 = TextMobject("Function")
text2 = TextMobject("Derivative")
text3 = TextMobject("Integral")
text4 = TextMobject("Transformation")
self.play(Write(text1))
self.wait()
#Trans text1 -> text2
self.play(ReplacementTransform(text1,text2))
self.wait()
#Trans text2 -> text3
self.play(ReplacementTransform(text2,text3))
self.wait()
#Trans text3 -> text4
self.play(ReplacementTransform(text3,text4))
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/TransformationText2.gif" /></p>
```python3
class CopyTextV1(Scene):
def construct(self):
formula = TexMobject(
"\\frac{d}{dx}", #0
"(", #1
"u", #2
"+", #3
"v", #4
")", #5
"=", #6
"\\frac{d}{dx}", #7
"u", #8
"+", #9
"\\frac{d}{dx}", #10
"v" #11
)
formula.scale(2)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9])
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10])
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTextV1.gif" /></p>
```python3
class CopyTextV2(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTextV2.gif" /></p>
```python3
class CopyTextV3(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
formula[8].set_color(RED)
formula[11].set_color(BLUE)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTextV3.gif" /></p>
```python3
class CopyTextV4(Scene):
def construct(self):
formula = TexMobject("\\frac{d}{dx}",
"(","u","+","v",")","=",
"\\frac{d}{dx}","u","+","\\frac{d}{dx}","v"
)
formula.scale(2)
for letter,color in [("u",RED),("v",BLUE)]:
formula.set_color_by_tex(letter,color)
self.play(Write(formula[0:7]))
self.wait()
self.play(
ReplacementTransform(formula[2].copy(),formula[8]),
ReplacementTransform(formula[4].copy(),formula[11]),
ReplacementTransform(formula[3].copy(),formula[9]),
run_time=3
)
self.wait()
self.play(
ReplacementTransform(formula[0].copy(),formula[7]),
ReplacementTransform(formula[0].copy(),formula[10]),
run_time=3
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTextV4.gif" /></p>
```python3
class CopyTwoFormulas1(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg", #0
"\\forall", #1
"x", #2
":", #3
"P(x)" #4
)
formula2 = TexMobject(
"\\exists", #0
"x", #1
":", #2
"\\neg", #3
"P(x)" #4
)
for size,pos,formula in [(2,2*UP,formula1),(2,2*DOWN,formula2)]:
formula.scale(size)
formula.move_to(pos)
self.play(Write(formula1))
self.wait()
changes = [
[(0,1,2,3,4),
# | | | | |
# v v v v v
(3,0,1,2,4)],
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTwoFormulas1.gif" /></p>
```python3
class CopyTwoFormulas2(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
for tam,pos,formula in [(2,2*UP,formula1),(2,2*DOWN,formula2)]:
formula.scale(tam)
formula.move_to(pos)
self.play(Write(formula1))
self.wait()
changes = [
# First time
[(2,3,4),
# | | |
# v v v
(1,2,4)],
# Second time
[(0,),
# |
# v
(3,)],
# Third time
[(1,),
# |
# v
(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTwoFormulas2.gif" /></p>
```python3
class CopyTwoFormulas2Color(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
parametters = [(2,2*UP,formula1,GREEN,"\\forall"),
(2,2*DOWN,formula2,ORANGE,"\\exists")]
for size,pos,formula,col,sim in parametters:
formula.scale(size)
formula.move_to(pos)
formula.set_color_by_tex(sim,col)
formula.set_color_by_tex("\\neg",PINK)
self.play(Write(formula1))
self.wait()
changes = [
[(2,3,4),(1,2,4)],
[(0,),(3,)],
[(1,),(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i].copy(),formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTwoFormulas2Color.gif" /></p>
```python3
class CopyTwoFormulas3(Scene):
def construct(self):
formula1 = TexMobject(
"\\neg","\\forall","x",":","P(x)"
)
formula2 = TexMobject(
"\\exists","x",":","\\neg","P(x)"
)
parametters = [(2,2*UP,formula1,GREEN,"\\forall"),
(2,2*DOWN,formula2,ORANGE,"\\exists")]
for size,pos,formula,col,sim in parametters:
formula.scale(size)
formula.move_to(pos)
formula.set_color_by_tex(sim,col)
formula.set_color_by_tex("\\neg",PINK)
self.play(Write(formula1))
self.wait()
changes = [
[(2,3,4),(1,2,4)],
[(0,),(3,)],
[(1,),(0,)]
]
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
formula1[i],formula2[j]
)
for i,j in zip(pre_ind,post_ind)
],
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/CopyTwoFormulas3.gif" /></p>
```python3
class ChangeTextColorAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(3)
self.play(Write(text))
self.wait()
self.play(
text.set_color, YELLOW,
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/ChangeTextColorAnimation.gif" /></p>
```python3
class ChangeSizeAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
self.play(Write(text))
self.wait()
self.play(
text.scale, 3,
run_time=2
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/ChangeSizeAnimation.gif" /></p>
```python3
class MoveText(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
text.shift(LEFT*2)
self.play(Write(text))
self.wait()
self.play(
text.shift, RIGHT*2,
run_time=2,
path_arc=0 #Change 0 by -np.pi
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/MoveText.gif" /></p>
```python3
class ChangeColorAndSizeAnimation(Scene):
def construct(self):
text = TextMobject("Text")
text.scale(2)
text.shift(LEFT*2)
self.play(Write(text))
self.wait()
self.play(
text.shift, RIGHT*2,
text.scale, 2,
text.set_color, RED,
run_time=2,
)
self.wait()
```
<p align="center"><img src ="/English/4_transform/gifs/ChangeColorAndSizeAnimation.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/6b_plots_3D/6b_plots_3D.py
|
from big_ol_pile_of_manim_imports import *
#There seems to be no change between Scene and ThreeDScene
class CameraPosition1(ThreeDScene):
def construct(self):
circulo=Circle()
self.play(ShowCreation(circulo))
self.wait()
'''
We have to add this line:
def get_axis(self, min_val, max_val, axis_config):
new_config = merge_config([
axis_config,
{"x_min": min_val, "x_max": max_val},
self.number_line_config,
])
return NumberLine(**new_config)
in manimlib/mobject/coordinate_systems.py
Use:
self.set_camera_orientation(phi,theta,distance,gamma)
to change the camera position
You can change the domain with:
ThreeDAxes(
x_min.
x_max,
y_min,
y_max,
z_min,
z_max
)
'''
class CameraPosition2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=0 * DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
class CameraPosition3(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
class CameraPosition4(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES,distance=6)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
class CameraPosition5(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES,distance=6,gamma=30*DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
#------ Move camera
class MoveCamera1(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.play(ShowCreation(circle),ShowCreation(axes))
self.move_camera(phi=30*DEGREES,theta=-45*DEGREES,run_time=3)
self.wait()
class MoveCamera2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.begin_ambient_camera_rotation(rate=0.1) #Start move camera
self.wait(5)
self.stop_ambient_camera_rotation() #Stop move camera
self.move_camera(phi=80*DEGREES,theta=-PI/2) #Return the position of the camera
self.wait()
#----------- Funciones parametricas
class ParametricCurve1(ThreeDScene):
def construct(self):
curve1=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u/2
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve2=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u
]),color=RED,t_min=-TAU,t_max=TAU,
)
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=80 * DEGREES,theta=-60*DEGREES)
self.begin_ambient_camera_rotation(rate=0.1)
self.play(ShowCreation(curve1))
self.wait()
self.play(Transform(curve1,curve2),rate_func=there_and_back,run_time=3)
self.wait()
# Add this in the object: .set_shade_in_3d(True)
class ParametricCurve2(ThreeDScene):
def construct(self):
curve1=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u/2
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve2=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve1.set_shade_in_3d(True)
curve2.set_shade_in_3d(True)
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=80 * DEGREES,theta=-60*DEGREES)
self.begin_ambient_camera_rotation(rate=0.1)
self.play(ShowCreation(curve1))
self.wait()
self.play(Transform(curve1,curve2),rate_func=there_and_back,run_time=3)
self.wait()
class ParametricCurve2(ThreeDScene):
def construct(self):
curve1=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u/2
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve2=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve1.set_shade_in_3d(True)
curve2.set_shade_in_3d(True)
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=80 * DEGREES,theta=-60*DEGREES)
self.begin_ambient_camera_rotation(rate=0.1)
self.play(ShowCreation(curve1))
self.wait()
self.play(Transform(curve1,curve2),rate_func=there_and_back,run_time=3)
self.wait()
#----- Surfaces
class SurfacesAnimation(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
cylinder = ParametricSurface(
lambda u, v: np.array([
np.cos(TAU * v),
np.sin(TAU * v),
2 * (1 - u)
]),
resolution=(6, 32)).fade(0.5) #Resolution of the surfaces
paraboloid = ParametricSurface(
lambda u, v: np.array([
np.cos(v)*u,
np.sin(v)*u,
u**2
]),v_max=TAU,
checkerboard_colors=[PURPLE_D, PURPLE_E],
resolution=(10, 32)).scale(2)
para_hyp = ParametricSurface(
lambda u, v: np.array([
u,
v,
u**2-v**2
]),v_min=-2,v_max=2,u_min=-2,u_max=2,checkerboard_colors=[BLUE_D, BLUE_E],
resolution=(15, 32)).scale(1)
cone = ParametricSurface(
lambda u, v: np.array([
u*np.cos(v),
u*np.sin(v),
u
]),v_min=0,v_max=TAU,u_min=-2,u_max=2,checkerboard_colors=[GREEN_D, GREEN_E],
resolution=(15, 32)).scale(1)
hip_one_side = ParametricSurface(
lambda u, v: np.array([
np.cosh(u)*np.cos(v),
np.cosh(u)*np.sin(v),
np.sinh(u)
]),v_min=0,v_max=TAU,u_min=-2,u_max=2,checkerboard_colors=[YELLOW_D, YELLOW_E],
resolution=(15, 32))
ellipsoid=ParametricSurface(
lambda u, v: np.array([
1*np.cos(u)*np.cos(v),
2*np.cos(u)*np.sin(v),
0.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[TEAL_D, TEAL_E],
resolution=(15, 32)).scale(2)
sphere = ParametricSurface(
lambda u, v: np.array([
1.5*np.cos(u)*np.cos(v),
1.5*np.cos(u)*np.sin(v),
1.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[RED_D, RED_E],
resolution=(15, 32)).scale(2)
self.set_camera_orientation(phi=75 * DEGREES)
self.begin_ambient_camera_rotation(rate=0.2)
self.add(axes)
self.play(Write(sphere))
self.wait()
self.play(ReplacementTransform(sphere,ellipsoid))
self.wait()
self.play(ReplacementTransform(ellipsoid,cone))
self.wait()
self.play(ReplacementTransform(cone,hip_one_side))
self.wait()
self.play(ReplacementTransform(hip_one_side,para_hyp))
self.wait()
self.play(ReplacementTransform(para_hyp,paraboloid))
self.wait()
self.play(ReplacementTransform(paraboloid,cylinder))
self.wait()
self.play(FadeOut(cylinder))
#---- Text on 3D
class Text3D1(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text").scale(2)
self.add(axes,text3d)
# This text appears in XY plane, to rotate:
class Text3D2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text").scale(2).set_shade_in_3d(True)
text3d.rotate(PI/2,axis=RIGHT)
self.add(axes,text3d)
# To see the text in the traditional form:
class Text3D3(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text")
self.add_fixed_in_frame_mobjects(text3d) #<----- Add this
text3d.to_corner(UL)
self.add(axes)
self.begin_ambient_camera_rotation()
self.play(Write(text3d))
sphere = ParametricSurface(
lambda u, v: np.array([
1.5*np.cos(u)*np.cos(v),
1.5*np.cos(u)*np.sin(v),
1.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[RED_D, RED_E],
resolution=(15, 32)).scale(2)
self.play(LaggedStart(ShowCreation,sphere))
self.wait(2)
|
AnimationsWithManim_Elteoremadebeethoven/English/6b_plots_3D/scenes.md
|
# Configuration
We have to add this method:
```python3
def get_axis(self, min_val, max_val, axis_config):
new_config = merge_config([
axis_config,
{"x_min": min_val, "x_max": max_val},
self.number_line_config,
])
return NumberLine(**new_config)
```
in Axes class: manimlib/mobject/coordinate_systems.py
Use:
```self.set_camera_orientation(phi,theta,distance,gamma)```
to change the camera position
You can change the domain with:
```
ThreeDAxes(
x_min.
x_max,
y_min,
y_max,
z_min,
z_max
)
```
# Programs
```python3
#There seems to be no change between Scene and ThreeDScene
class CameraPosition1(ThreeDScene):
def construct(self):
circulo=Circle()
self.play(ShowCreation(circulo))
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/CameraPosition1.gif" /></p>
```python3
class CameraPosition2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=0 * DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/CameraPosition2.gif" /></p>
```python3
class CameraPosition3(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/CameraPosition3.gif" /></p>
```python3
class CameraPosition4(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES,distance=6)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/CameraPosition4.gif" /></p>
```python3
class CameraPosition5(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES,theta=45*DEGREES,distance=6,gamma=30*DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/CameraPosition5.gif" /></p>
```python3
#------ Move camera
class MoveCamera1(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.play(ShowCreation(circle),ShowCreation(axes))
self.move_camera(phi=30*DEGREES,theta=-45*DEGREES,run_time=3)
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/MoveCamera1.gif" /></p>
```python3
class MoveCamera2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
circle=Circle()
self.set_camera_orientation(phi=80 * DEGREES)
self.play(ShowCreation(circle),ShowCreation(axes))
self.begin_ambient_camera_rotation(rate=0.1) #Start move camera
self.wait(5)
self.stop_ambient_camera_rotation() #Stop move camera
self.move_camera(phi=80*DEGREES,theta=-PI/2) #Return the position of the camera
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/MoveCamera2.gif" /></p>
```python3
#----------- Parametric functions
class ParametricCurve1(ThreeDScene):
def construct(self):
curve1=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u/2
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve2=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u
]),color=RED,t_min=-TAU,t_max=TAU,
)
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=80 * DEGREES,theta=-60*DEGREES)
self.begin_ambient_camera_rotation(rate=0.1)
self.play(ShowCreation(curve1))
self.wait()
self.play(Transform(curve1,curve2),rate_func=there_and_back,run_time=3)
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/ParametricCurve1.gif" /></p>
```python3
# Add this in the object: .set_shade_in_3d(True)
class ParametricCurve2(ThreeDScene):
def construct(self):
curve1=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u/2
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve2=ParametricFunction(
lambda u : np.array([
1.2*np.cos(u),
1.2*np.sin(u),
u
]),color=RED,t_min=-TAU,t_max=TAU,
)
curve1.set_shade_in_3d(True)
curve2.set_shade_in_3d(True)
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=80 * DEGREES,theta=-60*DEGREES)
self.begin_ambient_camera_rotation(rate=0.1)
self.play(ShowCreation(curve1))
self.wait()
self.play(Transform(curve1,curve2),rate_func=there_and_back,run_time=3)
self.wait()
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/ParametricCurve2.gif" /></p>
```python3
#----- Surfaces
class SurfacesAnimation(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
cylinder = ParametricSurface(
lambda u, v: np.array([
np.cos(TAU * v),
np.sin(TAU * v),
2 * (1 - u)
]),
resolution=(6, 32)).fade(0.5) #Resolution of the surfaces
paraboloid = ParametricSurface(
lambda u, v: np.array([
np.cos(v)*u,
np.sin(v)*u,
u**2
]),v_max=TAU,
checkerboard_colors=[PURPLE_D, PURPLE_E],
resolution=(10, 32)).scale(2)
para_hyp = ParametricSurface(
lambda u, v: np.array([
u,
v,
u**2-v**2
]),v_min=-2,v_max=2,u_min=-2,u_max=2,checkerboard_colors=[BLUE_D, BLUE_E],
resolution=(15, 32)).scale(1)
cone = ParametricSurface(
lambda u, v: np.array([
u*np.cos(v),
u*np.sin(v),
u
]),v_min=0,v_max=TAU,u_min=-2,u_max=2,checkerboard_colors=[GREEN_D, GREEN_E],
resolution=(15, 32)).scale(1)
hip_one_side = ParametricSurface(
lambda u, v: np.array([
np.cosh(u)*np.cos(v),
np.cosh(u)*np.sin(v),
np.sinh(u)
]),v_min=0,v_max=TAU,u_min=-2,u_max=2,checkerboard_colors=[YELLOW_D, YELLOW_E],
resolution=(15, 32))
ellipsoid=ParametricSurface(
lambda u, v: np.array([
1*np.cos(u)*np.cos(v),
2*np.cos(u)*np.sin(v),
0.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[TEAL_D, TEAL_E],
resolution=(15, 32)).scale(2)
sphere = ParametricSurface(
lambda u, v: np.array([
1.5*np.cos(u)*np.cos(v),
1.5*np.cos(u)*np.sin(v),
1.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[RED_D, RED_E],
resolution=(15, 32)).scale(2)
self.set_camera_orientation(phi=75 * DEGREES)
self.begin_ambient_camera_rotation(rate=0.2)
self.add(axes)
self.play(Write(sphere))
self.wait()
self.play(ReplacementTransform(sphere,ellipsoid))
self.wait()
self.play(ReplacementTransform(ellipsoid,cone))
self.wait()
self.play(ReplacementTransform(cone,hip_one_side))
self.wait()
self.play(ReplacementTransform(hip_one_side,para_hyp))
self.wait()
self.play(ReplacementTransform(para_hyp,paraboloid))
self.wait()
self.play(ReplacementTransform(paraboloid,cylinder))
self.wait()
self.play(FadeOut(cylinder))
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/SurfacesAnimation.gif" /></p>
```python3
#---- Text on 3D
class Text3D1(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text").scale(2)
self.add(axes,text3d)
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/Text3D1.png" /></p>
```python3
# This text appears in XY plane, to rotate:
class Text3D2(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text").scale(2).set_shade_in_3d(True)
text3d.rotate(PI/2,axis=RIGHT)
self.add(axes,text3d)
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/Text3D2.png" /></p>
```python3
# To see the text in the traditional form:
class Text3D3(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.set_camera_orientation(phi=75 * DEGREES,theta=-45*DEGREES)
text3d=TextMobject("This is a 3D text")
self.add_fixed_in_frame_mobjects(text3d) #<----- Add this
text3d.to_corner(UL)
self.add(axes)
self.begin_ambient_camera_rotation()
self.play(Write(text3d))
sphere = ParametricSurface(
lambda u, v: np.array([
1.5*np.cos(u)*np.cos(v),
1.5*np.cos(u)*np.sin(v),
1.5*np.sin(u)
]),v_min=0,v_max=TAU,u_min=-PI/2,u_max=PI/2,checkerboard_colors=[RED_D, RED_E],
resolution=(15, 32)).scale(2)
self.play(LaggedStart(ShowCreation,sphere))
self.wait(2)
```
<p align="center"><img src ="/English/6b_plots_3D/gifs/Text3D3.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/2_formulas_tex/2_formulas_tex.py
|
from big_ol_pile_of_manim_imports import *
|
AnimationsWithManim_Elteoremadebeethoven/English/2_formulas_tex/scenes.md
|
#
## Programas
###
```python3
````
<p align="center"><img src ="/.gif" /></p>
###
```python3
````
<p align="center"><img src ="/.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/0_instalation/conda_installation.md
|
# Conda installation
## Steps
You need to have LaTeX (MikTeX, TeXLive or MacTeX), FFmpeg and Sox installed.
1. Open your conda shell
2. Clone the repository: `git clone https://github.com/3b1b/manim.git`
3. Move to the repository: `cd manim`
4. Create the enviroment: `conda env create --file=environment.yml --name manimenv`
5. Wait for the installation to complete, and actiavate the enviroment with: `conda activate manimenv`
6. Run: `python -m manim example_scenes.py SquareToCircle -pl`
It may be that you need to install ffmpeg with x264 support, if that is the case try **some** of this lines:
```sh
conda install x264=='1!152.20180717' ffmpeg=4.0.2 -c conda-forge
# or
conda install -c conda-forge x264
```
|
AnimationsWithManim_Elteoremadebeethoven/English/0_instalation/windows/INSTRUCCIONES.md
|
# Instalación en Windows
La instalación en Windows es particularmente elaborada, por lo que recomiendo ver el video tutorial de instalación en YouTube, pero aquí se esbozarán los pasos para la gente que tenga más conocimientos en computación.
En caso de haber concluido todos los pasos y no lograr compilar los archivos es recomendable instalar una versión ligera de GNU/Linux (como [Lubuntu](https://lubuntu.net/downloads/)) en una máquina viritual y realizar el proceso de instalación de [GNU/Linux](https://github.com/Elteoremadebeethoven/AnimacionesConManim/blob/master/Espa%C3%B1ol/0_instalacion/gnuLinux/INSTRUCCIONES.md). La única desventaja será que este proceso necesitará unos 10 GB de espacio en tu disco duro.
[Video](https://www.youtube.com/watch?v=44fthwtnrF0) de como instalar Lubuntu en una máquina virtual usando VirtualBox.
## Instalar editor de texto plano.
Yo recomiendo [Sublime Text](https://www.sublimetext.com/).
## Descargar Manim del [repositorio oficial](https://github.com/3b1b/manim).
Descomprimir el archivo donde el usuario desee (en este ejemplo lo descomprimiré en Documentos).
## Modificar el archivo constants.py
Cambiar el código al archivo constants.py, en la linea que dice:
"Dropbox (3Blue1Brown)/3Blue1Brown Team Folder"
por la dirección de una carpeta dedicada los videos de manim, yo recomiendo la carpeta de videos "Videos" en el directorio principal.
## Instalación de LaTeX
Instalar la versión completa de [MikTeX](https://miktex.org/download).
1. Vas a "Downloads", luego a "All donwloads".
2. Seleccionar "Net Installar" de 32 bits o 64 bits dependiendo de tu PC.
3. Descargar e instalar, es un proceso que puede durar varias horas ([ver video ayuda](https://www.youtube.com/watch?v=yPnfHRE_W_g) del minuto 0:00 hasta el 6:19, lo demás no se necesita).
## Instalar Python 3.
Ir a la página oficial de [Python](https://www.python.org/), luego a Donwloads y descargar alguna versión de Python superior a la 3.6 (recomiendo la versión más reciente), el instalador debe decir "Windows x86-64 executable installer" e instalar.
## Modificar la variable PATH
Añadir a la variable PATH la carpeta donde se instalo Python 3 (ve a Inicio, busca Python 3, dale click derecho a algún archivo y luego click en "Abrir la ubicación del archivo"), además de la subcarpeta "Scripts".
La ubicación por defecto de la instalación suele ser:
```
C:\Users\Pc\AppData\Local\Programs\Python\Python37
```
Y la subcarpeta "Scripts":
```
C:\Users\Pc\AppData\Local\Programs\Python\Python37\Scripts
```
## Instalar [ffmpeg](https://ffmpeg.zeranoe.com/builds/)
Descargar e instalar de manera normal ([video ayuda](https://www.youtube.com/watch?v=X7wLMejOjjM)) y añade la carpeta de instalación a la variable PATH.
## Instalar [sox](https://sourceforge.net/projects/sox/)
Descarga e instala de manera normal y añade la carpeta de instalación a la variable PATH.
## Instalar Pycairo
1. Ir a esta [página](https://www.lfd.uci.edu/~gohlke/pythonlibs/)
2. Buscar pycairo (pulsa F3 y escirbe pycairo para encontrarlo más rápido).
3. Descarga todas las versiones para Python 3 (dependiendo si tu PC es de 64 o 32 bits).
4. Ir a la ubicación de la carpeta de Python 3 y copia la versión más reciente del archivo .whl a la carpeta.
5. Abre la terminal y muevete a la dirección de la carpeta de Python 3.
Ejemplo:
```
cd C:\Users\Pc\AppData\Local\Programs\Python\Python37
```
6. Ingresa el siguiente comando:
```
python -3 -m pip install
```
Seguido del paquete, por ejemplo:
```
python -3 -m pip install pycairo-pycairo‑1.17.1‑cp37‑cp37m‑win_amd64.whl
```
Si sale el error:
```
Unknown option: -3
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
```
Elimina el "-3" y escribe solo:
```
python -m pip install pycairo-pycairo‑1.17.1‑cp37‑cp37m‑win_amd64.whl
```
En caso de que emita un error elimina el archivo de la carpeta de Python 3 y copia una versión anterior a la carpeta y vuelve a intentar compilar el comando anterior (modificando el nombre del paquete).
Realiza esto hasta que alguna de las versiones sea instalada correctamente.
## Instala los requerimientos
Muevete a la carpeta de manim-master que descargaste usando la terminal y ejecuta el comando:
```
python -m pip install -r requirements.txt
```
# Ejecución
En la misma carpeta de manim-master compila por primiera vez un archivo de Manim usando:
```
python extract_scene.py example_scenes.py WriteStuff -l
```
# Almacenamiento
El video se pudo haber guardado ya sea en una subcarpeta de "manim-master" llamada igual al archivo .py que compilaste, es decir
```
manim-master/example_scenes/WriteStuff/420p15
```
O bien en la carpeta que definiste en constants.py en una subcarpeta llamada "animations"
```
Videos/example_scenes/WriteStuff/420p15
```
El 420p15 se refiere a la calidad del video a la que fue exportado. Dependerá de la versión de manim que descargaste el lugar donde se guarde el archivo.
|
AnimationsWithManim_Elteoremadebeethoven/English/0_instalation/gnuLinux/INSTRUCTIONS.md
|
# Instalation on GNU/Linux
Link to [video tutorial](https://www.youtube.com/watch?v=z_WJaHYH66M).
## Instalation with the terminal:
Open a terminal an run the follow commands:
### Install de LaTeX:
Debian distributions:
```sh
$ sudo apt-get install texlive-full
```
Arch distributions:
```sh
$ sudo pacman -S texlive-most
```
Fedora distributions:
```sh
# yum -y install texlive-collection-latexextra
```
### Install python3.7
Debian distributions:
```sh
$ sudo apt-get install python3.7-minimal
```
Arch distributions: always is update
Fedora distributions:
```sh
# yum install gcc openssl-devel bzip2-devel libffi-devel
# cd /usr/src
# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
# tar xzf Python-3.7.3.tgz
# cd Python-3.7.3
# ./configure --enable-optimizations
# make altinstall
# rm /usr/src/Python-3.7.3.tgz
```
### Install pip:
All distributions:
```sh
$ mkdir pip
$ cd pip
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3.7 get-pip.py
```
### Install ffmpeg:
Debian
```sh
$ sudo apt-get install ffmpeg
```
Arch-Linux:
```sh
$ sudo pacman -S ffmpeg
```
Fedora:
```sh
$ sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
$ sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
$ sudo dnf install ffmpeg ffmpeg-devel
```
### Install sox:
Debian
```sh
$ sudo apt-get install sox
```
Arch-Linux (with AUR):
```sh
$ aurman -S sox
```
Fedora:
Download it from: https://pkgs.org/download/sox
### Install pycairo dependences (only for Debian distributions):
Only for Debian distros:
```sh
$ sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev python3-dev libffi-dev
```
### Install pyreadline, pydub:
All distributions:
```sh
$ python3.7 -m pip install pyreadline
$ python3.7 -m pip install pydub
```
### Download Manim from [actual version](https://github.com/3b1b/manim), or [3/Feb/2019 version](https://github.com/3b1b/manim/tree/3b088b12843b7a4459fe71eba96b70edafb7aa78).
<p align="center"><img src ="/English/0_instalation/gnuLinux/gifs/manimDescarga.png" /></p>
Unzip the file into a directory that does not have spaces
## Install list requirements.txt:
Move the terminal to the manim-master directory:
```sh
~/manim-master$
```
Then run:
```sh
$ python3.7 -m pip install -r requirements.txt
```
# Run Manim
Run this command in manim-master directory:
```sh
$ python3.7 -m manim example_scenes.py SquareToCircle -pl
```
|
AnimationsWithManim_Elteoremadebeethoven/English/0_instalation/macOS/INSTRUCTIONS.md
|
# Installation on MacOS
Link to [video tutorial](https://www.youtube.com/watch?v=uZj_GQc6pN4).
## Install dependencies.
### Open a terminal
Search "terminal" on Spotlight
<p align="center"><img src ="/English/0_instalation/macOS/gifs/terminal.png" /></p>
### Install Homebrew
Copy the code from [Homebrew](https://brew.sh) and paste it in the terminal
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP1.gif" /></p>
### Install LaTeX (versión completa)
Go to [MacTeX](http://www.tug.org/mactex/), download the .pkg file and install it ([help](https://www.youtube.com/watch?v=5CNmIaRxS20)).
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP2.gif" /></p>
### Install Python 3
Go to the official website of [Python](https://www.python.org/), and download the 3.7 version ([help](https://www.youtube.com/watch?v=0hGzGdRQeak)).
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP3.gif" /></p>
### Install PIP
Run the follow commands:
```sh
brew install curl
mkdir ManimInstall
cd ManimInstall
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
```
### Install FFmpeg, SoX and Cairo.
Run the follow commands:
#### FFmpeg
```sh
brew install ffmpeg
```
#### Sox
```sh
brew install sox
```
#### More packages
```sh
brew install cairo
```
If that does not works use:
```sh
brew install cairo --use-clang
```
```sh
brew install py2cairo
```
```sh
brew install pkg-config
```
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP5.gif" /></p>
### Download Manim from [actual version](https://github.com/3b1b/manim), or [3/Feb/2019 version](https://github.com/3b1b/manim/tree/3b088b12843b7a4459fe71eba96b70edafb7aa78).
<p align="center"><img src ="/English/0_instalation/macOS/gifs/DescargarManim.gif" /></p>
### Unzip the file into a directory that does not have spaces
<p align="center"><img src ="/English/0_instalation/macOS/gifs/pd.png" /></p>
### Install list requirements.txt
Move the terminal to manim-master folder and run this:
```sh
python3 -m pip install pyreadline
python3 -m pip install pydub
```
#### Download the rest
Open `requirements.txt` and replace the content with [this](https://github.com/3b1b/manim/blob/master/requirements.txt) and use:
```
python3 -m pip install -r requirements.txt
```
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP6.gif" /></p>
# Run Manim
With the terminal in manim-master directory run this:
```sh
python3 -m manim example_scenes.py WriteStuff -pl
```
That command have to build the follow video:
<p align="center"><img src ="/English/0_instalation/macOS/gifs/MacP8.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/5_visual_tools/5_visual_tools.py
|
from big_ol_pile_of_manim_imports import *
class MoveBraces(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=", #0
"f(x)\\frac{d}{dx}g(x)", #1
"+", #2
"g(x)\\frac{d}{dx}f(x)" #3
)
self.play(Write(text))
brace1 = Brace(text[1], UP, buff = SMALL_BUFF)
brace2 = Brace(text[3], UP, buff = SMALL_BUFF)
t1 = brace1.get_text("$g'f$")
t2 = brace2.get_text("$f'g$")
self.play(
GrowFromCenter(brace1),
FadeIn(t1),
)
self.wait()
self.play(
ReplacementTransform(brace1,brace2),
ReplacementTransform(t1,t2)
)
self.wait()
class MoveBracesCopy(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
brace1 = Brace(text[1], UP, buff = SMALL_BUFF)
brace2 = Brace(text[3], UP, buff = SMALL_BUFF)
t1 = brace1.get_text("$g'f$")
t2 = brace2.get_text("$f'g$")
self.play(
GrowFromCenter(brace1),
FadeIn(t1),
)
self.wait()
self.play(
ReplacementTransform(brace1.copy(),brace2),
ReplacementTransform(t1.copy(),t2)
)
self.wait()
class MoveFrameBox(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
self.play(
ShowCreation(framebox1),
)
self.wait()
self.play(
ReplacementTransform(framebox1,framebox2),
)
self.wait()
class MoveFrameBoxCopy(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
self.play(ShowCreation(framebox1))
self.wait()
self.play(
ReplacementTransform(framebox1.copy(),framebox2),
path_arc=-np.pi
)
self.wait()
class MoveFrameBoxCopy2(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
t1 = TexMobject("g'f")
t2 = TexMobject("f'g")
t1.next_to(framebox1, UP, buff=0.1)
t2.next_to(framebox2, UP, buff=0.1)
self.play(
ShowCreation(framebox1),
FadeIn(t1)
)
self.wait()
self.play(
ReplacementTransform(framebox1.copy(),framebox2),
ReplacementTransform(t1.copy(),t2),
)
self.wait()
class Arrow1(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
arrow = Arrow(LEFT,RIGHT)
step1.move_to(LEFT*2)
arrow.next_to(step1,RIGHT,buff = .1)
step2.next_to(arrow,RIGHT,buff = .1)
self.play(Write(step1))
self.wait()
self.play(GrowArrow(arrow))
self.play(Write(step2))
self.wait()
class Arrow2(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = Arrow(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Arrow(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(arrow1))
self.play(GrowArrow(arrow2))
self.wait()
class LineAnimation(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = Line(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Line(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(ShowCreation(arrow1))
self.play(ShowCreation(arrow2))
self.wait()
class DashedLineAnimation(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = DashedLine(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Line(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(ShowCreation(arrow1))
self.play(ShowCreation(arrow2))
self.wait()
class LineAnimation2(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
line = Line(step1.get_right(),step2.get_left(),buff=0.1)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(line))
self.play(
step2.next_to, step2, LEFT*2,
)
self.wait()
class LineAnimation3(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step3 = step2.copy()
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
step3.next_to(step2, LEFT*2)
line = Line(step1.get_right(),step2.get_left(),buff=0.1)
lineCopy = Line(step1.get_right(),step3.get_bottom(),buff=0.1)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(line))
self.play(
ReplacementTransform(step2,step3),
ReplacementTransform(line,lineCopy)
)
self.wait()
|
AnimationsWithManim_Elteoremadebeethoven/English/5_visual_tools/scenes.md
|
# Programs
```python3
class MoveBraces(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=", #0
"f(x)\\frac{d}{dx}g(x)", #1
"+", #2
"g(x)\\frac{d}{dx}f(x)" #3
)
self.play(Write(text))
brace1 = Brace(text[1], UP, buff = SMALL_BUFF)
brace2 = Brace(text[3], UP, buff = SMALL_BUFF)
t1 = brace1.get_text("$g'f$")
t2 = brace2.get_text("$f'g$")
self.play(
GrowFromCenter(brace1),
FadeIn(t1),
)
self.wait()
self.play(
ReplacementTransform(brace1,brace2),
ReplacementTransform(t1,t2)
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/MoveBraces.gif" /></p>
```python3
class MoveBracesCopy(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
brace1 = Brace(text[1], UP, buff = SMALL_BUFF)
brace2 = Brace(text[3], UP, buff = SMALL_BUFF)
t1 = brace1.get_text("$g'f$")
t2 = brace2.get_text("$f'g$")
self.play(
GrowFromCenter(brace1),
FadeIn(t1),
)
self.wait()
self.play(
ReplacementTransform(brace1.copy(),brace2),
ReplacementTransform(t1.copy(),t2)
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/MoveBracesCopy.gif" /></p>
```python3
class MoveFrameBox(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
self.play(
ShowCreation(framebox1),
)
self.wait()
self.play(
ReplacementTransform(framebox1,framebox2),
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/MoveFrameBox.gif" /></p>
```python3
class MoveFrameBoxCopy(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
self.play(ShowCreation(framebox1))
self.wait()
self.play(
ReplacementTransform(framebox1.copy(),framebox2),
path_arc=-np.pi
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/MoveFrameBoxCopy.gif" /></p>
```python3
class MoveFrameBoxCopy2(Scene):
def construct(self):
text=TexMobject(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
t1 = TexMobject("g'f")
t2 = TexMobject("f'g")
t1.next_to(framebox1, UP, buff=0.1)
t2.next_to(framebox2, UP, buff=0.1)
self.play(
ShowCreation(framebox1),
FadeIn(t1)
)
self.wait()
self.play(
ReplacementTransform(framebox1.copy(),framebox2),
ReplacementTransform(t1.copy(),t2),
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/MoveFrameBoxCopy2.gif" /></p>
```python3
class Arrow1(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
arrow = Arrow(LEFT,RIGHT)
step1.move_to(LEFT*2)
arrow.next_to(step1,RIGHT,buff = .1)
step2.next_to(arrow,RIGHT,buff = .1)
self.play(Write(step1))
self.wait()
self.play(GrowArrow(arrow))
self.play(Write(step2))
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/Arrow1.gif" /></p>
```python3
class Arrow2(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = Arrow(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Arrow(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(arrow1))
self.play(GrowArrow(arrow2))
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/Arrow2.gif" /></p>
```python3
class LineAnimation(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = Line(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Line(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(ShowCreation(arrow1))
self.play(ShowCreation(arrow2))
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/LineAnimation.gif" /></p>
```python3
class DashedLineAnimation(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
arrow1 = DashedLine(step1.get_right(),step2.get_left(),buff=0.1)
arrow1.set_color(RED)
arrow2 = Line(step1.get_top(),step2.get_bottom(),buff=0.1)
arrow2.set_color(BLUE)
self.play(Write(step1),Write(step2))
self.play(ShowCreation(arrow1))
self.play(ShowCreation(arrow2))
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/DashedLineAnimation.gif" /></p>
```python3
class LineAnimation2(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
line = Line(step1.get_right(),step2.get_left(),buff=0.1)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(line))
self.play(
step2.next_to, step2, LEFT*2,
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/LineAnimation2.gif" /></p>
```python3
class LineAnimation3(Scene):
def construct(self):
step1 = TextMobject("Step 1")
step2 = TextMobject("Step 2")
step3 = step2.copy()
step1.move_to(LEFT*2+DOWN*2)
step2.move_to(4*RIGHT+2*UP)
step3.next_to(step2, LEFT*2)
line = Line(step1.get_right(),step2.get_left(),buff=0.1)
lineCopy = Line(step1.get_right(),step3.get_bottom(),buff=0.1)
self.play(Write(step1),Write(step2))
self.play(GrowArrow(line))
self.play(
ReplacementTransform(step2,step3),
ReplacementTransform(line,lineCopy)
)
self.wait()
```
<p align="center"><img src ="/English/5_visual_tools/gifs/LineAnimation3.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/9_project/svg_classes.py
|
from big_ol_pile_of_manim_imports import *
class CheckSVG(Scene):
CONFIG={
"camera_config":{"background_color": WHITE},
"svg_type":"svg",
"file":"",
"svg_scale":0.9,
"angle":0,
"flip_svg":False,
"fill_opacity": 1,
"remove": [],
"stroke_color": BLACK,
"fill_color": BLACK,
"stroke_width": 3,
"numbers_scale":0.5,
"show_numbers": False,
"animation": False,
"direction_numbers": UP,
"color_numbers": RED,
"space_between_numbers":0,
"show_elements":[],
"color_element":BLUE,
"set_size":"width",
"remove_stroke":[],
"show_stroke":[],
"stroke_":1
}
def construct(self):
if self.set_size=="width":
width_size=FRAME_WIDTH
height_size=None
else:
width_size=None
height_size=FRAME_HEIGHT
if self.svg_type=="svg":
self.imagen=SVGMobject(
"%s"%self.file,
#fill_opacity = 1,
stroke_width = self.stroke_width,
stroke_color = self.stroke_color,
width=width_size,
height=height_size
).rotate(self.angle).set_fill(self.fill_color,self.fill_opacity).scale(self.svg_scale)
else:
self.imagen=self.import_text().set_fill(self.fill_color,self.fill_opacity).rotate(self.angle).set_stroke(self.stroke_color,0)
if self.set_size=="width":
self.imagen.set_width(FRAME_WIDTH)
else:
self.imagen.set_height(FRAME_HEIGHT)
self.imagen.scale(self.svg_scale)
self.personalize_image()
if self.flip_svg==True:
self.imagen.flip()
if self.show_numbers==True:
self.print_formula(self.imagen,
self.numbers_scale,
self.direction_numbers,
self.remove,
self.space_between_numbers,
self.color_numbers)
self.return_elements(self.imagen,self.show_elements)
for st in self.remove_stroke:
self.imagen[st].set_stroke(None,0)
for st in self.show_stroke:
self.imagen[st].set_stroke(None,self.stroke_)
if self.animation==True:
self.play(DrawBorderThenFill(self.imagen))
else:
self.add(self.imagen)
self.wait()
def import_text(self):
return TexMobject("")
def personalize_image(self):
pass
def print_formula(self,text,inverse_scale,direction,exception,buff,color):
text.set_color(RED)
self.add(text)
c = 0
for j in range(len(text)):
permission_print=True
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add(text[j].set_color(self.stroke_color))
c = c + 1
c=0
for j in range(len(text)):
permission_print=True
element = TexMobject("%d" %c,color=color)
element.scale(inverse_scale)
element.next_to(text[j],direction,buff=buff)
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add(element)
c = c + 1
def return_elements(self,formula,adds):
for i in adds:
self.add_foreground_mobjects(formula[i].set_color(self.color_element),
TexMobject("%d"%i,color=self.color_element,background_stroke_width=0).scale(self.numbers_scale).next_to(formula[i],self.direction_numbers,buff=self.space_between_numbers))
class CheckFormula(Scene):
CONFIG={
"camera_config":{"background_color": BLACK},
"svg_type":"text",
"file":"",
"svg_scale":0.9,
"angle":0,
"flip_svg":False,
"fill_opacity": 1,
"remove": [],
"stroke_color": WHITE,
"fill_color": WHITE,
"stroke_width": 3,
"numbers_scale":0.5,
"show_numbers": True,
"animation": False,
"direction_numbers": UP,
"color_numbers": RED,
"space_between_numbers":0,
"show_elements":[],
"color_element":BLUE,
"set_size":"width",
"remove_stroke":[],
"show_stroke":[],
"stroke_":1
}
def construct(self):
if self.set_size=="width":
width_size=FRAME_WIDTH
height_size=None
else:
width_size=None
height_size=FRAME_HEIGHT
if self.svg_type=="svg":
self.imagen=SVGMobject(
"%s"%self.file,
#fill_opacity = 1,
stroke_width = self.stroke_width,
stroke_color = self.stroke_color,
width=width_size,
height=height_size
).rotate(self.angle).set_fill(self.fill_color,self.fill_opacity).scale(self.svg_scale)
else:
self.imagen=self.import_text()
if self.set_size=="width":
self.imagen.set_width(FRAME_WIDTH)
else:
self.imagen.set_height(FRAME_HEIGHT)
self.imagen.scale(self.svg_scale)
if self.flip_svg==True:
self.imagen.flip()
if self.show_numbers==True:
self.print_formula(self.imagen.copy(),
self.numbers_scale,
self.direction_numbers,
self.remove,
self.space_between_numbers,
self.color_numbers)
self.return_elements(self.imagen.copy(),self.show_elements)
for st in self.remove_stroke:
self.imagen[st].set_stroke(None,0)
for st in self.show_stroke:
self.imagen[st].set_stroke(None,self.stroke_)
if self.animation==True:
self.play(DrawBorderThenFill(self.imagen))
else:
self.add(self.imagen)
self.personalize_image()
self.wait()
def import_text(self):
return TexMobject("")
def personalize_image(self):
pass
def print_formula(self,text,inverse_scale,direction,exception,buff,color):
text.set_color(RED)
self.add(text)
c = 0
for j in range(len(text)):
permission_print=True
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add(text[j].set_color(self.stroke_color))
c = c + 1
c=0
for j in range(len(text)):
permission_print=True
element = TexMobject("%d" %c,color=color)
element.scale(inverse_scale)
element.next_to(text[j],direction,buff=buff)
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add_foreground_mobjects(element)
c = c + 1
def return_elements(self,formula,adds):
for i in adds:
self.add_foreground_mobjects(formula[i].set_color(self.color_element),
TexMobject("%d"%i,color=self.color_element,background_stroke_width=0).scale(self.numbers_scale).next_to(formula[i],self.direction_numbers,buff=self.space_between_numbers))
class CheckFormulaByTXT(Scene):
CONFIG={
"camera_config":{"background_color": BLACK},
"svg_type":"text",
"text": TexMobject(""),
"file":"",
"svg_scale":0.9,
"angle":0,
"flip_svg":False,
"fill_opacity": 1,
"remove": [],
"stroke_color": WHITE,
"fill_color": WHITE,
"stroke_width": 3,
"numbers_scale":0.5,
"show_numbers": True,
"animation": False,
"direction_numbers": UP,
"color_numbers": RED,
"space_between_numbers":0,
"show_elements":[],
"color_element":PURPLE,
"set_size":"width",
"remove_stroke":[],
"show_stroke":[],
"warning_color":RED,
"stroke_":1
}
def construct(self):
self.imagen=self.text
if self.set_size=="width":
self.imagen.set_width(FRAME_WIDTH)
else:
self.imagen.set_height(FRAME_HEIGHT)
self.imagen.scale(self.svg_scale)
if self.flip_svg==True:
self.imagen.flip()
if self.show_numbers==True:
self.print_formula(self.imagen.copy(),
self.numbers_scale,
self.direction_numbers,
self.remove,
self.space_between_numbers,
self.color_numbers)
self.return_elements(self.imagen.copy(),self.show_elements)
for st in self.remove_stroke:
self.imagen[st].set_stroke(None,0)
for st in self.show_stroke:
self.imagen[st].set_stroke(None,self.stroke_)
if self.animation==True:
self.play(DrawBorderThenFill(self.imagen))
else:
c=0
for j in range(len(self.imagen)):
permission_print=True
for w in self.remove:
if j==w:
permission_print=False
if permission_print:
self.add(self.imagen[j])
c = c + 1
self.personalize_image()
self.wait()
def personalize_image(self):
pass
def print_formula(self,text,inverse_scale,direction,exception,buff,color):
text.set_color(self.warning_color)
self.add(text)
c = 0
for j in range(len(text)):
permission_print=True
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add(text[j].set_color(self.stroke_color))
c = c + 1
c=0
for j in range(len(text)):
permission_print=True
element = TexMobject("%d" %c,color=color)
element.scale(inverse_scale)
element.next_to(text[j],direction,buff=buff)
for w in exception:
if j==w:
permission_print=False
if permission_print:
self.add_foreground_mobjects(element)
c = c + 1
def return_elements(self,formula,adds):
for i in adds:
self.add_foreground_mobjects(formula[i].set_color(self.color_element),
TexMobject("%d"%i,color=self.color_element,background_stroke_width=0).scale(self.numbers_scale).next_to(formula[i],self.direction_numbers,buff=self.space_between_numbers))
|
AnimationsWithManim_Elteoremadebeethoven/English/9_project/9_project.py
|
from big_ol_pile_of_manim_imports import *
#Import formulas:
from tutorial.formulas_txt.formulas import formulas
class SolveGeneralQuadraticEquation(Scene):
def construct(self):
self.import_formulas()
self.write_formulas()
self.set_changes()
self.step_formula(n_step=1,
changes=self.set_of_changes[0],
fade=[10],
path_arc=-PI/2
)
self.step_formula(n_step=2,
changes=self.set_of_changes[1],
write=[6,14],
pre_copy=[0],
pos_copy=[15]
)
self.step_formula(n_step=3,
changes=self.set_of_changes[2],
pos_write=[10, 11, 13, 14, 15, 16, 18, 20, 28, 29, 31, 32, 33, 34, 36, 38],
)
self.step_formula(n_step=4,
changes=self.set_of_changes[3],
)
self.step_formula(n_step=5,
changes=self.set_of_changes[4],
fade=[20,27],
pre_copy=[29],
pos_copy=[28]
)
self.step_formula(n_step=6,
changes=self.set_of_changes[5],
fade=[19],
)
self.step_formula(n_step=7,
changes=self.set_of_changes[6],
pos_write=[25,28],
)
self.step_formula(n_step=8,
changes=self.set_of_changes[7],
pos_write=[32,26],
)
self.step_formula(n_step=9,
changes=self.set_of_changes[8],
)
self.step_formula(n_step=10,
changes=self.set_of_changes[9],
pos_write=[0, 1, 16, 18, 20],
)
self.step_formula(n_step=11,
changes=self.set_of_changes[10],
fade=[0, 1, 2, 12, 14]
)
self.step_formula(n_step=12,
changes=self.set_of_changes[11],
)
self.step_formula(n_step=13,
changes=self.set_of_changes[12],
fade=[25]
)
self.step_formula(n_step=14,
changes=self.set_of_changes[13],
)
#
c1=SurroundingRectangle(self.formulas[14],buff=0.2)
c2=SurroundingRectangle(self.formulas[14],buff=0.2)
c2.rotate(PI)
self.play(ShowCreationThenDestruction(c1),ShowCreationThenDestruction(c2))
self.wait(2)
def import_formulas(self):
self.formulas=formulas
def write_formulas(self):
self.play(Write(self.formulas[0]))
def set_changes(self):
self.set_of_changes=[
#1
[[
( 0, 1, 3, 4, 5, 6, 7, 8, 9 ),
( 0, 1, 3, 4, 5, 6, 8, 9, 7 )
]],
#2
[[
( 0, 1, 3, 4, 5, 6, 7, 8, 9 ),
( 7, 0, 2, 3, 5, 9, 10, 11, 13 )
]],
#3
[[
( 0, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15 ),
( 0, 2, 3, 5, 6, 7, 9, 21, 22, 24, 25, 26 )
]],
#4
[[
( 0, 2, 10, 11, 13, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 28, 29, 31, 32, 33, 34, 36, 38 ,5,6,7,9,3),
( 1, 11, 2, 0, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 17, 19, 20, 22, 23, 24, 25, 27, 29 ,4,5,7,1,2)
]],
#5
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 17, 19, 22, 23, 24, 25, 29),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 17, 19, 21, 24, 25, 26, 23)
]],
#6
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 17, 21, 23, 24, 25, 26, 28 ),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 23, 25, 26, 27, 14, 16, 17, 18, 19, 21 )
]],
#7
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 21, 23, 25, 26, 27 ),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 21, 23, 26, 27, 29 )
]],
#8
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 21, 23, 25, 26, 27, 28, 29, ),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 21, 23, 25, 27, 28, 29, 30, )
]],
#9
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 21, 23, 25, 26, 27, 28, 29, 30, 32, ),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 21, 22, 23, 25, 17, 18, 19, 20, 21, 22, 23, 25, )
]],
#10
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 16, 17, 18, 19, 20, 21, 22, 23, 25, ),
( 2, 3, 5, 6, 7, 8, 10, 12, 14, 15, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, )
]],
#11
[[
( 3, 5, 6, 7, 8, 10, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, ),
( 0, 1, 3, 4, 5, 6, 8, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, )
]],
#12
[[
( 0, 1, 3, 4, 5, 6, 8, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, ),
( 0, 2, 4, 5, 6, 7, 1, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, )
]],
#13
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 24, ),
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 18, 20, 21, 22, 23, )
]],
#14
[[
( 0, 1, 2, 4, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 18, 20, 21, 22, 23, ),
( 0, 1, 3, 4, 16, 17, 18, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16, 17, 18, )
]]
]
def step_formula(self,
pre_write=[],
pos_write=[],
pre_fade=[],
pos_fade=[],
fade=[],
write=[],
changes=[[]],
path_arc=0,
n_step=0,
pre_copy=[],
pos_copy=[],
time_pre_changes=0.3,
time_pos_changes=0.3,
run_time=2,
time_end=0.3,
pre_order=["w","f"],
pos_order=["w","f"]
):
formula_copy=[]
for c in pre_copy:
formula_copy.append(self.formulas[n_step-1][c].copy())
for ani_ in pre_order:
if len(pre_write)>0 and ani_=="w":
self.play(*[Write(self.formulas[n_step-1][w])for w in pre_write])
if len(pre_fade)>0 and ani_=="f":
self.play(*[FadeOut(self.formulas[n_step-1][w])for w in pre_fade])
self.wait(time_pre_changes)
for pre_ind,post_ind in changes:
self.play(*[
ReplacementTransform(
self.formulas[n_step-1][i],self.formulas[n_step][j],
path_arc=path_arc
)
for i,j in zip(pre_ind,post_ind)
],
*[FadeOut(self.formulas[n_step-1][f])for f in fade if len(fade)>0],
*[Write(self.formulas[n_step][w])for w in write if len(write)>0],
*[ReplacementTransform(formula_copy[j],self.formulas[n_step][f])
for j,f in zip(range(len(pos_copy)),pos_copy) if len(pre_copy)>0
],
run_time=run_time
)
self.wait(time_pos_changes)
for ani_ in pos_order:
if len(pos_write)>0 and ani_=="w":
self.play(*[Write(self.formulas[n_step][w])for w in pos_write])
if len(pos_fade)>0 and ani_=="f":
self.play(*[FadeOut(self.formulas[n_step][w])for w in pos_fade])
self.wait(time_end)
|
AnimationsWithManim_Elteoremadebeethoven/English/9_project/scenes.md
|
#
## Programas
###
```python3
````
<p align="center"><img src ="/.gif" /></p>
###
```python3
````
<p align="center"><img src ="/.gif" /></p>
|
AnimationsWithManim_Elteoremadebeethoven/English/9_project/formulas_txt/formulas.py
|
from big_ol_pile_of_manim_imports import *
from tutorial.svg_classes import CheckFormulaByTXT
from io import *
formulas=[]
a_color=RED_B
b_color=BLUE_B
c_color=GREEN_B
x_color=YELLOW_B
for i in range(1,17):
formula_open=open("tutorial/formulas_txt/formula%de.txt"%i,"r")
formula=formula_open.readlines()
formulas.append(TexMobject(*formula).scale(1.7))
for i in range(10):
formulas[i].set_color_by_tex("a", a_color)
formulas[i].set_color_by_tex("b", b_color)
formulas[i].set_color_by_tex("c", c_color)
formulas[i].set_color_by_tex("x", x_color)
set_color_formulas=[
(10,
(
(a_color,[10,25,31]),
(b_color,[6,21]),
(c_color,[26]),
(x_color,[3]))
),
(11,
(
(a_color,[6,18,24]),
(b_color,[3,14]),
(c_color,[19]),
(x_color,[0]))
),
(12,
(
(a_color,[7,18,24]),
(b_color,[4,14]),
(c_color,[19]),
(x_color,[0]))
),
(13,
(
(a_color,[7,18,23]),
(b_color,[4,14]),
(c_color,[20]),
(x_color,[0]))
),
(14,
(
(a_color,[13,18]),
(b_color,[4,9]),
(c_color,[15]),
(x_color,[0]))
),
]
for f,changes in set_color_formulas:
for colors,symbols in changes:
for symbol in symbols:
formulas[f][symbol].set_color(colors)
''' Code:
class ConfigFormula(CheckFormulaByTXT):
CONFIG={
"show_elements":[],
"remove": [],
"text": formulas[]
}
'''
class ConfigFormula0(CheckFormulaByTXT):
CONFIG={
"show_elements":[],
"remove": [], #2
"text": formulas[0]
}
class ConfigFormula1(CheckFormulaByTXT):
CONFIG={
"show_elements":[],
"remove": [], #2
"text": formulas[1]
}
|
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 10