Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SCOTT-HAMILTON/33642c47945a4fb7ec5e2795e4e9f439 to your computer and use it in GitHub Desktop.
Save SCOTT-HAMILTON/33642c47945a4fb7ec5e2795e4e9f439 to your computer and use it in GitHub Desktop.
from manimlib.imports import *
from manimlib.mobject.types.vectorized_mobject import VMobject
# To watch one of these scenes, run the following:
# python -m manim example_scenes.py SquareToCircle -pl
#
# Use the flat -l for a faster rendering at a lower
# quality.
# Use -s to skip to the end and just save the final frame
# Use the -p to have the animation (or image, if -s was
# used) pop up once done.
# Use -n <number> to skip ahead to the n'th animation of a scene.
# Use -r <number> to specify a resolution (for example, -r 1080
# for a 1920x1080 video)
def TriangulationScene(scene):
colors = [RED, PINK, YELLOW]
scale = 0.4
shifts = [a*scale for a in [np.array((-0.54,0.59, 0.0)), np.array((-3.0, 4.81, 0.0)), np.array((-7.52, -2.85, 0.0))]]
radiuses = [a*scale for a in [5.3, 4.6, 4.3]]
explanations = ["Le premier cercle donne la distance au GPS du 1er satellite.",
"Le deuxième réduit la recherche aux deux intersections.",
"Le troisième fixe la géolocalisation à un des points d'intersection."]
oldText = TextMobject("")
circles = []
for color, shift, radius, explanation in zip(colors, shifts, radiuses, explanations):
circle = Circle(radius=radius, fill_opacity=0)
circle.shift(shift)
circles.append(circle)
scene.play(ShowCreation(circle))
text = TextMobject(explanation)
text.scale(0.6)
text.shift(np.array((-1.218, -5.74975, 0.0))*scale)
scene.play(ReplacementTransform(oldText, text))
oldText = text
scene.wait()
scene.wait()
newcircles = [circle.set_style(stroke_width=20) for circle in circles]
scene.play(FadeOut(oldText))
text = TextMobject(
"Mais toute mesure à une certaine précision. Ici le trésor ne se situe plus à un point spécifique mais dans une zone.")
text.shift(np.array((2.218, -8.0, 0.0))*scale)
text.scale(0.6)
scene.play(*[TransformFromCopy(oldCircle, newCircle) for oldCircle, newCircle in zip(circles, newcircles)],
ReplacementTransform(oldText, text))
scene.wait()
scene.wait()
circle = Circle(radius=0.2, stroke_width=0, fill_opacity=1, fill_color=WHITE)
circle.shift(np.array((-5.8, 1.1, 0.0))*scale)
scene.play(FadeIn(circle))
scene.wait()
scene.wait()
scene.wait()
scene.wait()
scene.play(*[FadeOut(circle) for circle in circles], FadeOut(text), FadeOut(circle))
def PropagateWave(scene, pos=ORIGIN, start_angle=-10*DEGREES, angle=20*DEGREES, pulses=30):
animations = []
circles = [(Arc(radius=0), 0.0)]
for radius in [2**(i/5) for i in range (10, pulses, 3)]: #range(10,40,1):
circle = Arc(arc_center=LEFT, start_angle=start_angle, angle=angle, radius=radius/10.0)
circle.shift(pos)
for i, (oldCircle, opacity) in enumerate(circles):
opacity *= 0.8
oldCircle.set_opacity(opacity)
circles[i] = (oldCircle, opacity)
scene.play(TransformFromCopy(circle[-1], circle), run_time=0.3)
circles.append((circle, 1.0))
return [circle for circle,_ in circles]
def NewSatellite(pos):
satellite = ImageMobject(filename_or_array = "icons/satellite.png")
satellite.scale(0.3)
satellite.shift(pos)
return (satellite, pos)
def WaveScene(scene):
satellites = []
print("Still")
satellites.append(NewSatellite(LEFT*6))
scene.play(FadeIn(satellites[-1][0]))
circles = PropagateWave(scene, LEFT*5, start_angle=-10*DEGREES, angle=20*DEGREES)
text = TextMobject(
"Pour calculer la distance, c'est-à-dire le rayon du cercle entre votre GPS et le satellite, il faut utiliser le temps.\\\
En effet, le signal émit contient la date d'envoie. Ainsi il suffit de calculer le temps parcouru en comparant la date d'envoie avec la date de reception.")
scale = 0.4
text.shift(np.array((2.218, -8.0, 0.0))*scale)
text.scale(0.6)
scene.play(FadeInFromDown(text))
oldText = text;
scene.play(*[FadeOut(circle) for circle in circles])
satellites.append(NewSatellite(RIGHT*6))
scene.play(FadeIn(satellites[-1][0]))
circles = PropagateWave(scene, RIGHT*6, start_angle=-190*DEGREES, angle=20*DEGREES)
scene.play(*[FadeOut(circle) for circle in circles])
circles = PropagateWave(scene, LEFT*5, start_angle=-10*DEGREES, angle=20*DEGREES)
scene.play(*[FadeOut(circle) for circle in circles])
circles = PropagateWave(scene, RIGHT*6, start_angle=-190*DEGREES, angle=20*DEGREES)
# scene.play(*[FadeOut(circle) for circle in circles])
scene.wait()
scene.wait()
text = TextMobject(
"Plus que 2 satellites et vous connaitrez votre position.")
scale = 0.4
text.shift(np.array((2.218, -9.0, 0.0))*scale)
text.scale(0.6)
scene.play(ReplacementTransform(oldText, text))
satellites.append(NewSatellite(DOWN*3+LEFT))
scene.play(FadeIn(satellites[-1][0]))
circlesUp = PropagateWave(scene, DOWN*3, start_angle=80*DEGREES, angle=20*DEGREES, pulses=20)
satellites.append(NewSatellite(UP*3+LEFT))
scene.play(FadeIn(satellites[-1][0]))
circlesDown = PropagateWave(scene, UP*3, start_angle=-100*DEGREES, angle=20*DEGREES, pulses=20)
scene.play(*[FadeOut(circle) for circle in circlesUp],
*[FadeOut(circle) for circle in circlesDown],
*[FadeOut(circle) for circle in circles],
FadeOut(text))
return satellites
def normalizedAngle(angle):
while (angle>360):
angle-=360
while (angle<0):
angle+=360
return angle
def EarthSatellitesScene(scene, satellites):
earth = ImageMobject(filename_or_array = "icons/planet-earth.png")
earth.scale(2)
satellitesAnimations = []
satellitesPrepareAnimations = []
scene.play(FadeIn(earth))
for startAngle,(satellite, pos) in zip(range(0, 360, int(360/4)), satellites):
circlePath = VMobject()
circle = Circle(radius=3)
circlePath.start_new_path(circle.point_at_angle(startAngle*DEGREES))
preparePath = VMobject()
preparePath.start_new_path(pos)
preparePath.add_line_to(circle.point_at_angle(startAngle*DEGREES))
satellitesPrepareAnimations.append(MoveAlongPath(satellite, preparePath))
circlePath.add_points_as_corners([ circle.point_at_angle(( normalizedAngle( a+startAngle) )*DEGREES) for a in range (1, 360) ])
satellitesAnimations.append(MoveAlongPath(satellite, circlePath))
scene.play(*satellitesPrepareAnimations, run_time=2.0)
scene.play(*satellitesAnimations, run_time=4.0)
text = TextMobject(
"Chaque point de la planète est constamment couvert par au moins 4 satellites.")
scale = 0.4
text.shift(np.array((2.218, -9.0, 0.0))*scale)
text.scale(0.6)
scene.play(FadeInFrom(text, RIGHT))
class Finale(Scene):
def construct(self):
TriangulationScene(self)
# satellites = WaveScene(self)
# EarthSatellitesScene(self, satellites)
# SCENES_IN_ORDER = [
# PropagateWave,
# Wave]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment