A community-maintained Python framework for creating mathematical animations.
microedits
Ben Hambrecht123b45298afe
diff --git a/active_projects/basel.py b/active_projects/basel.pyindex ff8f43169..d85ee9265 100644--- a/active_projects/basel.py+++ b/active_projects/basel.py@@ -18,7 +18,6 @@ from topics.characters import *from topics.functions import *from topics.number_line import *from topics.numerals import *-#from topics.combinatorics import *from scene import Scenefrom camera import Camerafrom mobject.svg_mobject import *@@ -40,14 +39,19 @@ FAST_INDICATOR_UPDATE_TIME = 0.1OPACITY_FOR_UNIT_INTENSITY = 0.2SWITCH_ON_RUN_TIME = 1.5FAST_SWITCH_ON_RUN_TIME = 0.1-NUM_LEVELS = 30NUM_CONES = 7 # in first lighthouse sceneNUM_VISIBLE_CONES = 5 # ibidemARC_TIP_LENGTH = 0.2-AMBIENT_FULL = 0.5-AMBIENT_DIMMED = 0.2-SPOTLIGHT_FULL = 0.9++NUM_LEVELS = 20+AMBIENT_FULL = 0.8+AMBIENT_DIMMED = 0.5+AMBIENT_SCALE = 1.0+AMBIENT_RADIUS = 20.0+SPOTLIGHT_FULL = 0.8SPOTLIGHT_DIMMED = 0.2+SPOTLIGHT_SCALE = 1.0+SPOTLIGHT_RADIUS = 20.0LIGHT_COLOR = YELLOWDEGREES = TAU/360@@ -373,7 +377,7 @@ class IntroScene(PiCreatureScene):rect.stretch_to_fit_height(self.rect_height,)- rect.stretch_to_fit_width(line.get_width())+ rect.stretch_to_fit_width(0.5 * line.get_width())rect.move_to(line)self.rects.add(rect)@@ -604,7 +608,7 @@ class FirstLighthouseScene(PiCreatureScene):width = 2.5, height = 3.5)bubble.next_to(randy,LEFT+UP)bubble.add_content(light_indicator)-+ self.wait()self.play(randy.change, "wave_2",ShowCreation(bubble),@@ -629,15 +633,15 @@ class FirstLighthouseScene(PiCreatureScene):for i in range(1,NUM_CONES+1):light_source = LightSource(- opacity_function = inverse_quadratic(1,2,1),+ opacity_function = inverse_quadratic(1,AMBIENT_SCALE,1),num_levels = NUM_LEVELS,- radius = 12.0,+ radius = AMBIENT_RADIUS,)point = self.number_line.number_to_point(i)light_source.move_source_to(point)light_sources.append(light_source)-+ self.wait()for ls in light_sources:self.add_foreground_mobject(ls.lighthouse)@@ -651,7 +655,7 @@ class FirstLighthouseScene(PiCreatureScene):# slowly switch on visible light cones and increment indicatorfor (i,light_source) in zip(range(NUM_VISIBLE_CONES),light_sources[:NUM_VISIBLE_CONES]):- indicator_start_time = 0.4 * (i+1) * SWITCH_ON_RUN_TIME/light_source.radius * self.number_line.unit_size+ indicator_start_time = 1.0 * (i+1) * SWITCH_ON_RUN_TIME/light_source.radius * self.number_line.unit_sizeindicator_stop_time = indicator_start_time + INDICATOR_UPDATE_TIMEindicator_rate_func = squish_rate_func(smooth,indicator_start_time,indicator_stop_time)@@ -664,10 +668,12 @@ class FirstLighthouseScene(PiCreatureScene):# this last line *technically* fades in the last term, but it is off-screenChangeDecimalToValue(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])+ ApplyMethod(light_indicator.foreground.set_fill,None,opacities[i],+ rate_func = indicator_rate_func, run_time = SWITCH_ON_RUN_TIME))if i == 0:+ self.wait()# move a copy out of the thought bubble for comparisonlight_indicator_copy = light_indicator.copy()old_y = light_indicator_copy.get_center()[1]@@ -676,6 +682,10 @@ class FirstLighthouseScene(PiCreatureScene):light_indicator_copy.shift,[0, new_y - old_y,0])+ self.wait()++ self.wait()+# quickly switch on off-screen light cones and increment indicatorfor (i,light_source) in zip(range(NUM_VISIBLE_CONES,NUM_CONES),light_sources[NUM_VISIBLE_CONES:NUM_CONES]):indicator_start_time = 0.5 * (i+1) * FAST_SWITCH_ON_RUN_TIME/light_source.radius * self.number_line.unit_size@@ -754,10 +764,12 @@ class SingleLighthouseScene(PiCreatureScene):# Light sourceself.light_source = LightSource(- opacity_function = inverse_quadratic(1,2,1),+ opacity_function = inverse_quadratic(1,SPOTLIGHT_SCALE,1),num_levels = NUM_LEVELS,radius = 10,- max_opacity_ambient = AMBIENT_FULL+ max_opacity_ambient = AMBIENT_FULL,+ max_opacity_spotlight = SPOTLIGHT_FULL,+)self.light_source.move_source_to(source_point)@@ -780,7 +792,7 @@ class SingleLighthouseScene(PiCreatureScene):# Screenself.screen = Rectangle(- width = 0.1,+ width = 0.06,height = 2,mark_paths_closed = True,fill_color = WHITE,@@ -797,27 +809,40 @@ class SingleLighthouseScene(PiCreatureScene):self.play(FadeIn(self.screen))- self.light_source.set_max_opacity_spotlight(0.001)- self.add(self.light_source.spotlight)+ #self.light_source.set_max_opacity_spotlight(0.001)+ #self.play(SwitchOn(self.light_source.spotlight))- self.screen_tracker = ScreenTracker(self.light_source)- self.add(self.screen_tracker)self.wait()++# just calling .dim_ambient via ApplyMethod does not work, why?dimmed_ambient_light = self.light_source.ambient_light.deepcopy()dimmed_ambient_light.dimming(AMBIENT_DIMMED)+ self.light_source.update_shadow()self.play(- Transform(self.light_source.ambient_light,dimmed_ambient_light),- self.light_source.set_max_opacity_spotlight,1.0,- FadeIn(self.light_source.shadow)+ FadeIn(self.light_source.shadow),)-+ self.add_foreground_mobject(self.light_source.shadow)self.add_foreground_mobject(morty)+ self.play(+ self.light_source.dim_ambient,+ #Transform(self.light_source.ambient_light,dimmed_ambient_light),+ #self.light_source.set_max_opacity_spotlight,1.0,+ )+ self.play(+ FadeIn(self.light_source.spotlight)+ )++ self.screen_tracker = ScreenTracker(self.light_source)+ self.add(self.screen_tracker)++ self.wait()+@@ -843,7 +868,9 @@ class SingleLighthouseScene(PiCreatureScene):self.angle_indicator = DecimalNumber(arc_angle / DEGREES,num_decimal_points = 0,- unit = "^\\circ")+ unit = "^\\circ",+ fill_opacity = 1.0,+ fill_color = WHITE)self.angle_indicator.next_to(self.angle_arc,RIGHT)angle_update_func = lambda x: self.light_source.spotlight.opening_angle() / DEGREES@@ -866,6 +893,7 @@ class SingleLighthouseScene(PiCreatureScene):self.play(Rotate(self.light_source.spotlight.screen, TAU/8))self.play(Rotate(self.light_source.spotlight.screen, -TAU/4))+self.play(Rotate(self.light_source.spotlight.screen, TAU/8))self.wait()@@ -891,6 +919,7 @@ class SingleLighthouseScene(PiCreatureScene):FadeOut(self.angle_arc),FadeOut(self.angle_indicator))+ self.wait()self.sun = self.light_source.deepcopy()@@ -904,9 +933,10 @@ class SingleLighthouseScene(PiCreatureScene):self.sun.set_radius(150)self.sun.move_source_to(sun_position)- # self.sun.update()+ #self.sun.update()- # self.add(self.sun)+ #self.add(self.sun)+ self.wait()# temporarily remove the screen tracker while we move the source#self.remove(self.screen_tracker)@@ -951,8 +981,8 @@ class EarthScene(Scene):# screenself.screen = VMobject(stroke_color = WHITE, stroke_width = SCREEN_THICKNESS)self.screen.set_points_as_corners([- [3,-self.screen_height/2,0],- [3,self.screen_height/2,0]+ [0,-self.screen_height/2,0],+ [0,self.screen_height/2,0]])# Earth@@ -961,6 +991,7 @@ class EarthScene(Scene):earth_center = [earth_center_x,0,0]earth_radius = 3earth = Circle(radius = earth_radius)+ earth.add(self.screen)earth.move_to(earth_center)#self.remove(self.screen_tracker)@@ -969,8 +1000,15 @@ class EarthScene(Scene):theta1 = theta0 + dthetatheta = (theta0 + theta1)/2- earth.add(self.screen)+ self.add_foreground_mobject(self.screen)+ # background Earth+ background_earth = SVGMobject(+ file_name = "earth",+ width = 2 * earth_radius,+ fill_color = BLUE,+ )+ background_earth.move_to(earth_center)# Mortymorty = Mortimer().scale(0.5).next_to(self.screen, RIGHT, buff = 1.5)@@ -1003,8 +1041,13 @@ class EarthScene(Scene):self.wait()- self.play(FadeIn(earth))- self.bring_to_back(earth)+ self.play(+ FadeIn(earth),+ FadeIn(background_earth)+ )+ self.add_foreground_mobject(earth)+ self.add_foreground_mobject(self.screen)+# move screen onto Earthscreen_on_earth = self.screen.deepcopy()@@ -1016,6 +1059,7 @@ class EarthScene(Scene):0]))polar_morty = morty.copy().scale(0.5).next_to(screen_on_earth,DOWN,buff = 0.5)+ polar_morty.highlight(BLUE_C)self.play(Transform(self.screen, screen_on_earth),@@ -1027,6 +1071,8 @@ class EarthScene(Scene):tropical_morty = polar_morty.copy()tropical_morty.move_to(np.array([0,0,0]))+ tropical_morty.highlight(RED)+morty.target = tropical_morty# move screen to equatordiff --git a/topics/light.py b/topics/light.pyindex 3bbcd9e55..c24662a5b 100644--- a/topics/light.py+++ b/topics/light.py@@ -29,10 +29,10 @@ NUM_LEVELS = 30NUM_CONES = 7 # in first lighthouse sceneNUM_VISIBLE_CONES = 5 # ibidemARC_TIP_LENGTH = 0.2-AMBIENT_FULL = 0.5-AMBIENT_DIMMED = 0.2-SPOTLIGHT_FULL = 0.9-SPOTLIGHT_DIMMED = 0.2+AMBIENT_FULL = 0.8+AMBIENT_DIMMED = 0.5+SPOTLIGHT_FULL = 0.8+SPOTLIGHT_DIMMED = 0.5LIGHTHOUSE_HEIGHT = 0.8DEGREES = TAU/360@@ -57,7 +57,7 @@ class LightSource(VMobject):"source_point": VectorizedPoint(location = ORIGIN, stroke_width = 0, fill_opacity = 0),"color": LIGHT_COLOR,"num_levels": 10,- "radius": 5,+ "radius": 10.0,"screen": None,"opacity_function": inverse_quadratic(1,2,1),"max_opacity_ambient": AMBIENT_FULL,@@ -143,7 +143,9 @@ class LightSource(VMobject):num_levels = self.num_levels,radius = self.radius,screen = new_screen,- camera_mob = self.camera_mob+ camera_mob = self.camera_mob,+ opacity_function = self.opacity_function,+ max_opacity = self.max_opacity_spotlight,)self.spotlight.move_source_to(self.get_source_point())@@ -371,7 +373,7 @@ class AmbientLight(VMobject):"color" : LIGHT_COLOR,"max_opacity" : 1.0,"num_levels" : 10,- "radius" : 5.0+ "radius" : 10.0}def generate_points(self):@@ -452,7 +454,7 @@ class Spotlight(VMobject):"color" : GREEN, # LIGHT_COLOR,"max_opacity" : 1.0,"num_levels" : 10,- "radius" : 5.0,+ "radius" : 10.0,"screen" : None,"camera_mob": None}