mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Merge branch 'master' into lighthouse
# Conflicts: # topics/numerals.py
This commit is contained in:
parent
ea18d984ce
commit
a4a146a54e
5 changed files with 75 additions and 35 deletions
|
@ -316,14 +316,29 @@ class Mobject(object):
|
||||||
self.shift(target_point - point_to_align + buff*direction)
|
self.shift(target_point - point_to_align + buff*direction)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def align_to(self, mobject_or_point, direction = UP):
|
def align_to(self, mobject_or_point, direction = ORIGIN, alignment_vect = UP):
|
||||||
|
"""
|
||||||
|
Examples:
|
||||||
|
mob1.align_to(mob2, UP) moves mob1 vertically so that its
|
||||||
|
top edge lines ups with mob2's top edge.
|
||||||
|
|
||||||
|
mob1.align_to(mob2, alignment_vector = RIGHT) moves mob1
|
||||||
|
horizontally so that it's center is directly above/below
|
||||||
|
the center of mob2
|
||||||
|
"""
|
||||||
if isinstance(mobject_or_point, Mobject):
|
if isinstance(mobject_or_point, Mobject):
|
||||||
mob = mobject_or_point
|
mob = mobject_or_point
|
||||||
point = mob.get_edge_center(direction)
|
target_point = mob.get_critical_point(direction)
|
||||||
else:
|
else:
|
||||||
point = mobject_or_point
|
target_point = mobject_or_point
|
||||||
diff = point - self.get_edge_center(direction)
|
direction_norm = np.linalg.norm(direction)
|
||||||
self.shift(direction*np.dot(diff, direction))
|
if direction_norm > 0:
|
||||||
|
alignment_vect = np.array(direction)/direction_norm
|
||||||
|
reference_point = self.get_critical_point(direction)
|
||||||
|
else:
|
||||||
|
reference_point = self.get_center()
|
||||||
|
diff = target_point - reference_point
|
||||||
|
self.shift(alignment_vect*np.dot(diff, alignment_vect))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def shift_onto_screen(self, **kwargs):
|
def shift_onto_screen(self, **kwargs):
|
||||||
|
|
|
@ -92,9 +92,15 @@ class VMobject(Mobject):
|
||||||
fill_opacity = vmobject.get_fill_opacity(),
|
fill_opacity = vmobject.get_fill_opacity(),
|
||||||
family = False
|
family = False
|
||||||
)
|
)
|
||||||
#TODO: This behaviro may not be optimal when submobject
|
|
||||||
#lists dont' have the same length
|
#Does its best to match up submobject lists, and
|
||||||
for sm1, sm2 in zip(self.submobjects, vmobject.submobjects):
|
#match styles accordingly
|
||||||
|
submobs1, submobs2 = self.submobjects, vmobject.submobjects
|
||||||
|
if len(submobs1) == 0:
|
||||||
|
return
|
||||||
|
elif len(submobs2) == 0:
|
||||||
|
submobs2 = [vmobject]
|
||||||
|
for sm1, sm2 in zip(*make_even(submobs1, submobs2)):
|
||||||
sm1.match_style(sm2)
|
sm1.match_style(sm2)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -482,7 +482,7 @@ class Scene(object):
|
||||||
|
|
||||||
def preview(self):
|
def preview(self):
|
||||||
TkSceneRoot(self)
|
TkSceneRoot(self)
|
||||||
|
|
||||||
def get_image_file_path(self, name = None, dont_update = False):
|
def get_image_file_path(self, name = None, dont_update = False):
|
||||||
folder = "images"
|
folder = "images"
|
||||||
if dont_update:
|
if dont_update:
|
||||||
|
@ -540,7 +540,6 @@ class Scene(object):
|
||||||
'-loglevel', 'error',
|
'-loglevel', 'error',
|
||||||
temp_file_path,
|
temp_file_path,
|
||||||
]
|
]
|
||||||
|
|
||||||
# self.writing_process = sp.Popen(command, stdin=sp.PIPE, shell=True)
|
# self.writing_process = sp.Popen(command, stdin=sp.PIPE, shell=True)
|
||||||
self.writing_process = sp.Popen(command, stdin=sp.PIPE)
|
self.writing_process = sp.Popen(command, stdin=sp.PIPE)
|
||||||
|
|
||||||
|
|
|
@ -172,18 +172,12 @@ class AnnularSector(VMobject):
|
||||||
arc_center = first_point - self.inner_radius * radial_unit_vector
|
arc_center = first_point - self.inner_radius * radial_unit_vector
|
||||||
return arc_center
|
return arc_center
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
def move_arc_center_to(self,point):
|
def move_arc_center_to(self,point):
|
||||||
v = point - self.get_arc_center()
|
v = point - self.get_arc_center()
|
||||||
self.shift(v)
|
self.shift(v)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> master
|
|
||||||
class Sector(AnnularSector):
|
class Sector(AnnularSector):
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"outer_radius" : 1,
|
"outer_radius" : 1,
|
||||||
"inner_radius" : 0
|
"inner_radius" : 0
|
||||||
|
|
|
@ -3,6 +3,7 @@ from mobject.vectorized_mobject import VMobject, VGroup, VectorizedPoint
|
||||||
from mobject.tex_mobject import TexMobject
|
from mobject.tex_mobject import TexMobject
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
from animation.continual_animation import ContinualAnimation
|
from animation.continual_animation import ContinualAnimation
|
||||||
|
from topics.geometry import BackgroundRectangle
|
||||||
from scene import Scene
|
from scene import Scene
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
|
@ -12,18 +13,31 @@ class DecimalNumber(VMobject):
|
||||||
"digit_to_digit_buff" : 0.05,
|
"digit_to_digit_buff" : 0.05,
|
||||||
"show_ellipsis" : False,
|
"show_ellipsis" : False,
|
||||||
"unit" : None,
|
"unit" : None,
|
||||||
|
"include_background_rectangle" : False,
|
||||||
}
|
}
|
||||||
def __init__(self, number, **kwargs):
|
def __init__(self, number, **kwargs):
|
||||||
digest_config(self, kwargs, locals())
|
VMobject.__init__(self, **kwargs)
|
||||||
num_string = '%.*f'%(self.num_decimal_points, number)
|
self.number = number
|
||||||
negative_zero_string = "-%.*f"%(self.num_decimal_points, 0.)
|
ndp = self.num_decimal_points
|
||||||
if num_string == negative_zero_string:
|
|
||||||
num_string = num_string[1:]
|
|
||||||
VMobject.__init__(self, *[
|
|
||||||
TexMobject(char)
|
|
||||||
for char in num_string
|
|
||||||
], **kwargs)
|
|
||||||
|
|
||||||
|
#Build number string
|
||||||
|
if isinstance(number, complex):
|
||||||
|
num_string = '%.*f%s%.*fi'%(
|
||||||
|
ndp, number.real,
|
||||||
|
"-" if number.imag < 0 else "+",
|
||||||
|
ndp, abs(number.imag)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
num_string = '%.*f'%(ndp, number)
|
||||||
|
negative_zero_string = "-%.*f"%(ndp, 0.)
|
||||||
|
if num_string == negative_zero_string:
|
||||||
|
num_string = num_string[1:]
|
||||||
|
self.add(*[
|
||||||
|
TexMobject(char, **kwargs)
|
||||||
|
for char in num_string
|
||||||
|
])
|
||||||
|
|
||||||
|
#Add non-numerical bits
|
||||||
if self.show_ellipsis:
|
if self.show_ellipsis:
|
||||||
self.add(TexMobject("\\dots"))
|
self.add(TexMobject("\\dots"))
|
||||||
|
|
||||||
|
@ -35,6 +49,7 @@ class DecimalNumber(VMobject):
|
||||||
aligned_edge = DOWN
|
aligned_edge = DOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if num_string.startswith("-"):
|
if num_string.startswith("-"):
|
||||||
minus = self.submobjects[0]
|
minus = self.submobjects[0]
|
||||||
minus.next_to(
|
minus.next_to(
|
||||||
|
@ -55,18 +70,29 @@ class DecimalNumber(VMobject):
|
||||||
|
|
||||||
|
|
||||||
class Integer(VGroup):
|
class Integer(VGroup):
|
||||||
|
=======
|
||||||
|
#Handle alignment of parts that should be aligned
|
||||||
|
#to the bottom
|
||||||
|
for i, c in enumerate(num_string):
|
||||||
|
if c == "-" and len(num_string) > i+1:
|
||||||
|
self[i].align_to(self[i+1], alignment_vect = UP)
|
||||||
|
if self.unit == "\\circ":
|
||||||
|
self[-1].align_to(self, UP)
|
||||||
|
#
|
||||||
|
if self.include_background_rectangle:
|
||||||
|
#TODO, is this the best way to handle
|
||||||
|
#background rectangles?
|
||||||
|
self.background_rectangle = BackgroundRectangle(self)
|
||||||
|
self.submobjects = [
|
||||||
|
self.background_rectangle,
|
||||||
|
VGroup(*self.submobjects)
|
||||||
|
]
|
||||||
|
|
||||||
|
class Integer(DecimalNumber):
|
||||||
|
>>>>>>> master
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"digit_buff" : 0.8*SMALL_BUFF
|
"num_decimal_points" : 0,
|
||||||
}
|
}
|
||||||
def __init__(self, integer, **kwargs):
|
|
||||||
self.number = integer
|
|
||||||
num_str = str(integer)
|
|
||||||
VGroup.__init__(self, *map(TexMobject, num_str), **kwargs)
|
|
||||||
self.arrange_submobjects(
|
|
||||||
RIGHT, buff = self.digit_buff, aligned_edge = DOWN
|
|
||||||
)
|
|
||||||
if num_str[0] == "-":
|
|
||||||
self[0].next_to(self[1], LEFT, buff = SMALL_BUFF)
|
|
||||||
|
|
||||||
class ChangingDecimal(Animation):
|
class ChangingDecimal(Animation):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue