mirror of
https://github.com/3b1b/manim.git
synced 2025-08-01 17:29:06 +08:00
ScreenScalingScene
This commit is contained in:
@ -1030,11 +1030,14 @@ class ScreenShapingScene(ThreeDScene):
|
|||||||
|
|
||||||
# light source
|
# light source
|
||||||
self.light_source = LightSource(
|
self.light_source = LightSource(
|
||||||
opacity_function = inverse_quadratic(1,2,1),
|
opacity_function = inverse_quadratic(1,5,1),
|
||||||
num_levels = NUM_LEVELS,
|
num_levels = NUM_LEVELS,
|
||||||
radius = 10,
|
radius = 10,
|
||||||
|
max_opacity = 0.2
|
||||||
#screen = self.screen
|
#screen = self.screen
|
||||||
)
|
)
|
||||||
|
self.light_source.set_max_opacity_spotlight(0.2)
|
||||||
|
|
||||||
self.light_source.set_screen(self.screen)
|
self.light_source.set_screen(self.screen)
|
||||||
self.light_source.move_source_to([-5,0,0])
|
self.light_source.move_source_to([-5,0,0])
|
||||||
|
|
||||||
@ -1251,6 +1254,7 @@ class ScreenShapingScene(ThreeDScene):
|
|||||||
|
|
||||||
def morph_into_3d(self):
|
def morph_into_3d(self):
|
||||||
|
|
||||||
|
|
||||||
self.play(FadeOut(self.morty))
|
self.play(FadeOut(self.morty))
|
||||||
|
|
||||||
axes = ThreeDAxes()
|
axes = ThreeDAxes()
|
||||||
@ -1289,11 +1293,13 @@ class ScreenShapingScene(ThreeDScene):
|
|||||||
|
|
||||||
self.add_foreground_mobject(self.ambient_light)
|
self.add_foreground_mobject(self.ambient_light)
|
||||||
self.add_foreground_mobject(self.spotlight)
|
self.add_foreground_mobject(self.spotlight)
|
||||||
|
self.add_foreground_mobject(self.light_source.shadow)
|
||||||
|
|
||||||
self.play(
|
self.play(
|
||||||
ApplyMethod(self.camera.rotation_mobject.move_to, camera_target_point),
|
ApplyMethod(self.camera.rotation_mobject.move_to, camera_target_point),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
self.remove(self.spotlight)
|
||||||
|
|
||||||
self.play(Transform(new_screen0,new_screen))
|
self.play(Transform(new_screen0,new_screen))
|
||||||
|
|
||||||
@ -1303,16 +1309,176 @@ class ScreenShapingScene(ThreeDScene):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def prove_inverse_square_law(self):
|
def prove_inverse_square_law(self):
|
||||||
|
|
||||||
|
def orientate(mob):
|
||||||
|
mob.move_to(self.unit_screen)
|
||||||
|
mob.rotate(TAU/4, axis = LEFT)
|
||||||
|
mob.rotate(TAU/4, axis = OUT)
|
||||||
|
mob.rotate(TAU/2, axis = LEFT)
|
||||||
|
return mob
|
||||||
|
|
||||||
unit_screen_copy = self.unit_screen.copy()
|
unit_screen_copy = self.unit_screen.copy()
|
||||||
fourfold_screen = self.unit_screen.copy()
|
fourfold_screen = self.unit_screen.copy()
|
||||||
fourfold_screen.scale(2,about_point = self.light_source.get_source_point())
|
fourfold_screen.scale(2,about_point = self.light_source.get_source_point())
|
||||||
|
|
||||||
|
self.remove(self.spotlight)
|
||||||
|
|
||||||
|
|
||||||
|
reading1 = TexMobject("1")
|
||||||
|
orientate(reading1)
|
||||||
|
|
||||||
|
self.play(FadeIn(reading1))
|
||||||
|
self.wait()
|
||||||
|
self.play(FadeOut(reading1))
|
||||||
|
|
||||||
|
|
||||||
self.play(
|
self.play(
|
||||||
Transform(self.unit_screen, fourfold_screen)
|
Transform(self.unit_screen, fourfold_screen)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
reading21 = TexMobject("{1\over 4}").scale(0.8)
|
||||||
|
orientate(reading21)
|
||||||
|
reading22 = reading21.deepcopy()
|
||||||
|
reading23 = reading21.deepcopy()
|
||||||
|
reading24 = reading21.deepcopy()
|
||||||
|
reading21.shift(0.5*OUT + 0.5*UP)
|
||||||
|
reading22.shift(0.5*OUT + 0.5*DOWN)
|
||||||
|
reading23.shift(0.5*IN + 0.5*UP)
|
||||||
|
reading24.shift(0.5*IN + 0.5*DOWN)
|
||||||
|
|
||||||
|
|
||||||
|
corners = fourfold_screen.get_anchors()
|
||||||
|
midpoint1 = (corners[0] + corners[1])/2
|
||||||
|
midpoint2 = (corners[1] + corners[2])/2
|
||||||
|
midpoint3 = (corners[2] + corners[3])/2
|
||||||
|
midpoint4 = (corners[3] + corners[0])/2
|
||||||
|
midline1 = Line(midpoint1, midpoint3)
|
||||||
|
midline2 = Line(midpoint2, midpoint4)
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
ShowCreation(midline1),
|
||||||
|
ShowCreation(midline2)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
FadeIn(reading21),
|
||||||
|
FadeIn(reading22),
|
||||||
|
FadeIn(reading23),
|
||||||
|
FadeIn(reading24),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
FadeOut(reading21),
|
||||||
|
FadeOut(reading22),
|
||||||
|
FadeOut(reading23),
|
||||||
|
FadeOut(reading24),
|
||||||
|
FadeOut(midline1),
|
||||||
|
FadeOut(midline2)
|
||||||
|
)
|
||||||
|
|
||||||
|
ninefold_screen = unit_screen_copy.copy()
|
||||||
|
ninefold_screen.scale(3,about_point = self.light_source.get_source_point())
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
Transform(self.unit_screen, ninefold_screen)
|
||||||
|
)
|
||||||
|
|
||||||
|
reading31 = TexMobject("{1\over 9}").scale(0.8)
|
||||||
|
orientate(reading31)
|
||||||
|
reading32 = reading31.deepcopy()
|
||||||
|
reading33 = reading31.deepcopy()
|
||||||
|
reading34 = reading31.deepcopy()
|
||||||
|
reading35 = reading31.deepcopy()
|
||||||
|
reading36 = reading31.deepcopy()
|
||||||
|
reading37 = reading31.deepcopy()
|
||||||
|
reading38 = reading31.deepcopy()
|
||||||
|
reading39 = reading31.deepcopy()
|
||||||
|
reading31.shift(IN + UP)
|
||||||
|
reading32.shift(IN)
|
||||||
|
reading33.shift(IN + DOWN)
|
||||||
|
reading34.shift(UP)
|
||||||
|
reading35.shift(ORIGIN)
|
||||||
|
reading36.shift(DOWN)
|
||||||
|
reading37.shift(OUT + UP)
|
||||||
|
reading38.shift(OUT)
|
||||||
|
reading39.shift(OUT + DOWN)
|
||||||
|
|
||||||
|
corners = ninefold_screen.get_anchors()
|
||||||
|
midpoint11 = (2*corners[0] + corners[1])/3
|
||||||
|
midpoint12 = (corners[0] + 2*corners[1])/3
|
||||||
|
midpoint21 = (2*corners[1] + corners[2])/3
|
||||||
|
midpoint22 = (corners[1] + 2*corners[2])/3
|
||||||
|
midpoint31 = (2*corners[2] + corners[3])/3
|
||||||
|
midpoint32 = (corners[2] + 2*corners[3])/3
|
||||||
|
midpoint41 = (2*corners[3] + corners[0])/3
|
||||||
|
midpoint42 = (corners[3] + 2*corners[0])/3
|
||||||
|
midline11 = Line(midpoint11, midpoint32)
|
||||||
|
midline12 = Line(midpoint12, midpoint31)
|
||||||
|
midline21 = Line(midpoint21, midpoint42)
|
||||||
|
midline22 = Line(midpoint22, midpoint41)
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
ShowCreation(midline11),
|
||||||
|
ShowCreation(midline12),
|
||||||
|
ShowCreation(midline21),
|
||||||
|
ShowCreation(midline22),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
FadeIn(reading31),
|
||||||
|
FadeIn(reading32),
|
||||||
|
FadeIn(reading33),
|
||||||
|
FadeIn(reading34),
|
||||||
|
FadeIn(reading35),
|
||||||
|
FadeIn(reading36),
|
||||||
|
FadeIn(reading37),
|
||||||
|
FadeIn(reading38),
|
||||||
|
FadeIn(reading39),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IndicatorScalingScene(Scene):
|
||||||
|
|
||||||
|
def construct(self):
|
||||||
|
|
||||||
|
unit_intensity = 0.6
|
||||||
|
|
||||||
|
indicator1 = LightIndicator(show_reading = False, color = LIGHT_COLOR)
|
||||||
|
indicator1.set_intensity(unit_intensity)
|
||||||
|
reading1 = TexMobject("1")
|
||||||
|
reading1.move_to(indicator1)
|
||||||
|
|
||||||
|
|
||||||
|
indicator2 = LightIndicator(show_reading = False, color = LIGHT_COLOR)
|
||||||
|
indicator2.shift(2*RIGHT)
|
||||||
|
indicator2.set_intensity(unit_intensity/4)
|
||||||
|
reading2 = TexMobject("{1\over 4}").scale(0.8)
|
||||||
|
reading2.move_to(indicator2)
|
||||||
|
|
||||||
|
indicator3 = LightIndicator(show_reading = False, color = LIGHT_COLOR)
|
||||||
|
indicator3.shift(4*RIGHT)
|
||||||
|
indicator3.set_intensity(unit_intensity/9)
|
||||||
|
reading3 = TexMobject("{1\over 9}").scale(0.8)
|
||||||
|
reading3.move_to(indicator3)
|
||||||
|
|
||||||
|
|
||||||
|
self.play(FadeIn(indicator1))
|
||||||
|
self.play(FadeIn(reading1))
|
||||||
|
self.wait()
|
||||||
|
self.play(FadeOut(reading1))
|
||||||
|
self.play(Transform(indicator1, indicator2))
|
||||||
|
self.play(FadeIn(reading2))
|
||||||
|
self.wait()
|
||||||
|
self.play(FadeOut(reading2))
|
||||||
|
self.play(Transform(indicator1, indicator3))
|
||||||
|
self.play(FadeIn(reading3))
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ from mobject.svg_mobject import *
|
|||||||
from topics.three_dimensions import *
|
from topics.three_dimensions import *
|
||||||
|
|
||||||
from scipy.spatial import ConvexHull
|
from scipy.spatial import ConvexHull
|
||||||
|
from traceback import *
|
||||||
|
|
||||||
|
|
||||||
LIGHT_COLOR = YELLOW
|
LIGHT_COLOR = GREEN
|
||||||
SHADOW_COLOR = BLACK
|
SHADOW_COLOR = BLACK
|
||||||
SWITCH_ON_RUN_TIME = 1.5
|
SWITCH_ON_RUN_TIME = 1.5
|
||||||
FAST_SWITCH_ON_RUN_TIME = 0.1
|
FAST_SWITCH_ON_RUN_TIME = 0.1
|
||||||
@ -34,7 +35,6 @@ SPOTLIGHT_FULL = 0.9
|
|||||||
SPOTLIGHT_DIMMED = 0.2
|
SPOTLIGHT_DIMMED = 0.2
|
||||||
LIGHTHOUSE_HEIGHT = 0.8
|
LIGHTHOUSE_HEIGHT = 0.8
|
||||||
|
|
||||||
LIGHT_COLOR = YELLOW
|
|
||||||
DEGREES = TAU/360
|
DEGREES = TAU/360
|
||||||
|
|
||||||
inverse_power_law = lambda maxint,scale,cutoff,exponent: \
|
inverse_power_law = lambda maxint,scale,cutoff,exponent: \
|
||||||
@ -162,6 +162,7 @@ class LightSource(VMobject):
|
|||||||
|
|
||||||
|
|
||||||
def move_source_to(self,point):
|
def move_source_to(self,point):
|
||||||
|
print_stack()
|
||||||
apoint = np.array(point)
|
apoint = np.array(point)
|
||||||
v = apoint - self.get_source_point()
|
v = apoint - self.get_source_point()
|
||||||
# Note: As discussed, things stand to behave better if source
|
# Note: As discussed, things stand to behave better if source
|
||||||
@ -369,11 +370,13 @@ class AmbientLight(VMobject):
|
|||||||
|
|
||||||
|
|
||||||
def dimming(self,new_alpha):
|
def dimming(self,new_alpha):
|
||||||
|
print "dimming"
|
||||||
old_alpha = self.max_opacity
|
old_alpha = self.max_opacity
|
||||||
self.max_opacity = new_alpha
|
self.max_opacity = new_alpha
|
||||||
for submob in self.submobjects:
|
for submob in self.submobjects:
|
||||||
old_submob_alpha = submob.fill_opacity
|
old_submob_alpha = submob.fill_opacity
|
||||||
new_submob_alpha = old_submob_alpha * new_alpha / old_alpha
|
new_submob_alpha = old_submob_alpha * new_alpha / old_alpha
|
||||||
|
print old_submob_alpha, new_submob_alpha
|
||||||
submob.set_fill(opacity = new_submob_alpha)
|
submob.set_fill(opacity = new_submob_alpha)
|
||||||
|
|
||||||
|
|
||||||
@ -395,7 +398,7 @@ class Spotlight(VMobject):
|
|||||||
CONFIG = {
|
CONFIG = {
|
||||||
"source_point": VectorizedPoint(location = ORIGIN, stroke_width = 0, fill_opacity = 0),
|
"source_point": VectorizedPoint(location = ORIGIN, stroke_width = 0, fill_opacity = 0),
|
||||||
"opacity_function" : lambda r : 1.0/(r/2+1.0)**2,
|
"opacity_function" : lambda r : 1.0/(r/2+1.0)**2,
|
||||||
"color" : LIGHT_COLOR,
|
"color" : GREEN, # LIGHT_COLOR,
|
||||||
"max_opacity" : 1.0,
|
"max_opacity" : 1.0,
|
||||||
"num_levels" : 10,
|
"num_levels" : 10,
|
||||||
"radius" : 5.0,
|
"radius" : 5.0,
|
||||||
|
Reference in New Issue
Block a user