Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Improved first lighthouse scene (now with series on top)

Ben Hambrecht2eb6f7f6146c
diff --git a/active_projects/basel.py b/active_projects/basel.py
index afe564b63..298b34aa4 100644
--- a/active_projects/basel.py
+++ b/active_projects/basel.py
@@ -40,9 +40,13 @@ INDICATOR_STROKE_WIDTH = 1
INDICATOR_STROKE_COLOR = WHITE
INDICATOR_TEXT_COLOR = WHITE
INDICATOR_UPDATE_TIME = 0.2
+FAST_INDICATOR_UPDATE_TIME = 0.1
OPACITY_FOR_UNIT_INTENSITY = 0.2
SWITCH_ON_RUN_TIME = 2.0
-LIGHT_CONE_NUM_SECTORS = 50
+FAST_SWITCH_ON_RUN_TIME = 0.1
+LIGHT_CONE_NUM_SECTORS = 10
+NUM_CONES = 10
+NUM_VISIBLE_CONES = 6
@@ -506,13 +510,16 @@ class FirstLightHouseScene(PiCreatureScene):
color = WHITE,
number_at_center = 1.6,
stroke_width = 1,
- numbers_with_elongated_ticks = [0,1,2,3],
- numbers_to_show = np.arange(1,5),
+ numbers_with_elongated_ticks = range(1,5),
+ numbers_to_show = range(1,5),
unit_size = 2,
tick_frequency = 0.2,
- line_to_number_buff = LARGE_BUFF
+ line_to_number_buff = LARGE_BUFF,
+ label_direction = UP,
)
+ self.number_line.label_direction = DOWN
+
self.number_line_labels = self.number_line.get_number_mobjects()
self.add(self.number_line,self.number_line_labels)
self.wait()
@@ -549,9 +556,22 @@ class FirstLightHouseScene(PiCreatureScene):
lighthouse_pos = []
light_cones = []
- num_cones = 6
- for i in range(1,num_cones+1):
+ euler_sum_above = TexMobject("1", "+", "{1\over 4}",
+ "+", "{1\over 9}", "+", "{1\over 16}", "+", "{1\over 25 }", "+", "{1\over 36}")
+ euler_sum_above.fill_color = YELLOW
+
+ for (i,term) in zip(range(len(euler_sum_above)),euler_sum_above):
+ #horizontal alignment with tick marks
+ term.next_to(self.number_line.number_to_point(0.5*i+1),UP,buff = 2)
+ # vertical alignment with light indicator
+ old_y = term.get_center()[1]
+ new_y = light_indicator.get_center()[1]
+ term.shift([0,new_y - old_y,0])
+
+
+
+ for i in range(1,NUM_CONES+1):
lighthouse = LightHouse()
point = self.number_line.number_to_point(i)
light_cone = Candle(
@@ -571,33 +591,64 @@ class FirstLightHouseScene(PiCreatureScene):
light_indicator.set_intensity(0)
- intensities = np.cumsum(np.array([1./n**2 for n in range(1,num_cones+1)]))
+ intensities = np.cumsum(np.array([1./n**2 for n in range(1,NUM_CONES+1)]))
opacities = intensities * light_indicator.opacity_for_unit_intensity
self.remove_foreground_mobjects(light_indicator)
-
-
- for (i,lc) in zip(range(num_cones),light_cones):
+ # slowly switch on visible light cones and increment indicator
+ for (i,lc) in zip(range(NUM_VISIBLE_CONES),light_cones[:NUM_VISIBLE_CONES]):
+ print i
indicator_start_time = 0.5 * (i+1) * SWITCH_ON_RUN_TIME/lc.radius * self.number_line.unit_size
indicator_stop_time = indicator_start_time + INDICATOR_UPDATE_TIME
indicator_rate_func = squish_rate_func(#smooth, 0.8, 0.9)
smooth,indicator_start_time,indicator_stop_time)
self.play(
SwitchOn(lc),
+ FadeIn(euler_sum_above[2*i], run_time = SWITCH_ON_RUN_TIME,
+ rate_func = indicator_rate_func),
+ FadeIn(euler_sum_above[2*i - 1], run_time = SWITCH_ON_RUN_TIME,
+ rate_func = indicator_rate_func),
ChangeDecimalToValue(light_indicator.reading,intensities[i],
rate_func = indicator_rate_func, run_time = SWITCH_ON_RUN_TIME),
ApplyMethod(light_indicator.foreground.set_fill,None,opacities[i])
)
if i == 0:
- # mvoe a copy out of the thought bubble for comparison
+ # move a copy out of the thought bubble for comparison
light_indicator_copy = light_indicator.copy()
+ old_y = light_indicator_copy.get_center()[1]
+ new_y = self.number_line.get_center()[1]
self.play(
- light_indicator_copy.shift,[2,0,0]
+ light_indicator_copy.shift,[0, new_y - old_y,0]
)
+ print "fast now"
+
+ # quickly switch on off-screen light cones and increment indicator
+ for (i,lc) in zip(range(NUM_VISIBLE_CONES,NUM_CONES),light_cones[NUM_VISIBLE_CONES:NUM_CONES]):
+ print i
+ indicator_start_time = 0.5 * (i+1) * FAST_SWITCH_ON_RUN_TIME/lc.radius * self.number_line.unit_size
+ indicator_stop_time = indicator_start_time + FAST_INDICATOR_UPDATE_TIME
+ indicator_rate_func = squish_rate_func(#smooth, 0.8, 0.9)
+ smooth,indicator_start_time,indicator_stop_time)
+ self.play(
+ SwitchOn(lc, run_time = FAST_SWITCH_ON_RUN_TIME),
+ ChangeDecimalToValue(light_indicator.reading,intensities[i],
+ rate_func = indicator_rate_func, run_time = FAST_SWITCH_ON_RUN_TIME),
+ ApplyMethod(light_indicator.foreground.set_fill,None,opacities[i])
+ )
+
+
+ # show limit value in light indicator and an equals sign
+ limit_reading = TexMobject("{\pi^2 \over 6}")
+ limit_reading.move_to(light_indicator.reading)
+ self.play(
+ FadeOut(indicator.reading),
+ FadeIn(limit_reading)
+# Transform(light_indicator.reading,limit_reading)
+ )
@@ -622,7 +673,7 @@ class SingleLightHouseScene(PiCreatureScene):
lighthouse = LightHouse()
candle = Candle(
- opacity_function = inverse_quadratic(0.3,1),
+ opacity_function = inverse_quadratic(1,1),
num_sectors = LIGHT_CONE_NUM_SECTORS,
radius = 10
)
@@ -650,6 +701,10 @@ class SingleLightHouseScene(PiCreatureScene):
light_screen.screen.fill_opacity = 1
light_screen.update_light_cone(light_cone)
self.add(light_screen)
+ # dim the light that misses the screen
+ self.play(
+ ApplyMethod(light_cone.set_intensity,0.3)
+ )
lc_updater = lambda lc: light_screen.update_light_cone(lc)
sh_updater = lambda sh: light_screen.update_shadow(sh)