TwoLightSourcesScene: Hooked up indicator so it updates as replacement light moves around

This commit is contained in:
Ben Hambrecht 2018-02-08 13:27:23 +01:00
parent 3ef4b8a32a
commit 0e85da2939

View file

@ -1432,9 +1432,9 @@ class TwoLightSourcesScene(PiCreatureScene):
INDICATOR_RADIUS = 0.6 INDICATOR_RADIUS = 0.6
OPACITY_FOR_UNIT_INTENSITY = 0.5 OPACITY_FOR_UNIT_INTENSITY = 0.5
A = np.array([5,-3,0]) A = np.array([5.,-3.,0.])
B = np.array([-5,3,0]) B = np.array([-5.,3.,0.])
C = np.array([-5,-3,0]) C = np.array([-5.,-3.,0.])
morty = self.get_primary_pi_creature() morty = self.get_primary_pi_creature()
morty.scale(0.3).flip().move_to(C) morty.scale(0.3).flip().move_to(C)
@ -1462,24 +1462,42 @@ class TwoLightSourcesScene(PiCreatureScene):
Write(indicator) Write(indicator)
) )
ambient_light1 = AmbientLight(max_opacity = MAX_OPACITY) def intensity_for_location(loc,light_source = None):
ambient_light1.move_source_to(A) intensity = 0.0
ambient_light2 = AmbientLight(max_opacity = MAX_OPACITY) distance = np.linalg.norm(C - loc)
ambient_light2.move_source_to(B) print "source:", light_source.get_source_point(), "loc:", loc
lighthouse1 = Lighthouse() print "distance:", distance
lighthouse1.next_to(A,DOWN,buff = 0) intensity = light_source.opacity_function(distance) / OPACITY_FOR_UNIT_INTENSITY
lighthouse2 = Lighthouse() print "intensity:", intensity
lighthouse2.next_to(B,DOWN,buff = 0) return intensity
def intensity_for_light_source(ls):
return intensity_for_location(ls.get_source_point(), light_source = ls)
ls1 = LightSource()
ls2 = LightSource().deepcopy()
#print "==="
#print ls1.get_source_point()
ls1.move_source_to(A)
#print ls1.get_source_point()
#print "==="
#print ls2.get_source_point()
ls2.move_source_to(B)
#print ls2.get_source_point()
self.play( self.play(
FadeIn(lighthouse1), FadeIn(ls1.lighthouse),
FadeIn(lighthouse2), FadeIn(ls2.lighthouse),
SwitchOn(ambient_light1), SwitchOn(ls1.ambient_light),
SwitchOn(ambient_light2) SwitchOn(ls2.ambient_light)
) )
intensity = intensity_for_light_source(ls1)
intensity += intensity_for_light_source(ls2)
self.play( self.play(
UpdateLightIndicator(indicator,1.5) UpdateLightIndicator(indicator,intensity)
) )
self.wait() self.wait()
@ -1490,25 +1508,30 @@ class TwoLightSourcesScene(PiCreatureScene):
indicator.shift, 2 * UP indicator.shift, 2 * UP
) )
ambient_light3 = AmbientLight(max_opacity = MAX_OPACITY) ls3 = LightSource().deepcopy()
lighthouse3 = Lighthouse() ls3.move_to(np.array([6,3.5,0]))
lighthouse3.next_to(ambient_light3,DOWN,buff = 0)
ambient_light3.add(lighthouse3) intensity = intensity_for_light_source(ls3)
#moving_light.move_to(np.array([6,3.5,0]))
self.play( self.play(
FadeOut(ambient_light1), SwitchOff(ls1.ambient_light),
FadeOut(lighthouse1), FadeOut(ls1.lighthouse),
FadeOut(ambient_light2), SwitchOff(ls2.ambient_light),
FadeOut(lighthouse2), FadeOut(ls2.lighthouse),
FadeIn(ambient_light3), SwitchOn(ls3.ambient_light),
UpdateLightIndicator(new_indicator,0.0) FadeIn(ls3.lighthouse),
UpdateLightIndicator(new_indicator,intensity)
) )
self.wait() self.wait()
new_location = np.array([-3,-2.,0.])
intensity = intensity_for_location(new_location, light_source = ls3)
self.play( self.play(
ambient_light3.shift,UP+RIGHT ls3.move_source_to,new_location,
UpdateLightIndicator(new_indicator,intensity)
) )