mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 02:35:22 +08:00
Modernize Python 2 for Python 3
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import copy
|
||||
import itertools as it
|
||||
@ -21,6 +22,7 @@ from utils.paths import straight_path
|
||||
from utils.space_ops import angle_of_vector
|
||||
from utils.space_ops import complex_to_R3
|
||||
from utils.space_ops import rotation_matrix
|
||||
from functools import reduce
|
||||
|
||||
|
||||
# TODO: Explain array_attrs
|
||||
@ -224,7 +226,7 @@ class Mobject(Container):
|
||||
|
||||
def apply_complex_function(self, function, **kwargs):
|
||||
return self.apply_function(
|
||||
lambda (x, y, z): complex_to_R3(function(complex(x, y))),
|
||||
lambda x_y_z: complex_to_R3(function(complex(x_y_z[0], x_y_z[1]))),
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@ -807,7 +809,7 @@ class Mobject(Container):
|
||||
|
||||
def print_submobject_family(self, n_tabs=0):
|
||||
"""For debugging purposes"""
|
||||
print "\t" * n_tabs, self, id(self)
|
||||
print("\t" * n_tabs, self, id(self))
|
||||
for submob in self.submobjects:
|
||||
submob.print_submobject_family(n_tabs + 1)
|
||||
|
||||
@ -843,7 +845,7 @@ class Mobject(Container):
|
||||
# push it into its submobject list
|
||||
self_has_points, mob_has_points = [
|
||||
mob.get_num_points() > 0
|
||||
for mob in self, mobject
|
||||
for mob in (self, mobject)
|
||||
]
|
||||
if self_has_points and not mob_has_points:
|
||||
mobject.null_point_align(self)
|
||||
|
@ -5,6 +5,7 @@ import operator as op
|
||||
|
||||
from mobject.svg.tex_mobject import SingleStringTexMobject
|
||||
from mobject.types.vectorized_mobject import VMobject
|
||||
from functools import reduce
|
||||
|
||||
|
||||
class DecimalNumber(VMobject):
|
||||
|
@ -143,7 +143,7 @@ class SVGMobject(VMobject):
|
||||
float(circle_element.getAttribute(key))
|
||||
if circle_element.hasAttribute(key)
|
||||
else 0.0
|
||||
for key in "cx", "cy", "r"
|
||||
for key in ("cx", "cy", "r")
|
||||
]
|
||||
return Circle(radius=r).shift(x * RIGHT + y * DOWN)
|
||||
|
||||
@ -152,7 +152,7 @@ class SVGMobject(VMobject):
|
||||
float(circle_element.getAttribute(key))
|
||||
if circle_element.hasAttribute(key)
|
||||
else 0.0
|
||||
for key in "cx", "cy", "rx", "ry"
|
||||
for key in ("cx", "cy", "rx", "ry")
|
||||
]
|
||||
return Circle().scale(rx * RIGHT + ry * UP).shift(x * RIGHT + y * DOWN)
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
from __future__ import absolute_import
|
||||
from constants import *
|
||||
|
||||
from svg_mobject import SVGMobject
|
||||
from svg_mobject import VMobjectFromSVGPathstring
|
||||
from .svg_mobject import SVGMobject
|
||||
from .svg_mobject import VMobjectFromSVGPathstring
|
||||
from utils.config_ops import digest_config
|
||||
from utils.strings import split_string_list_to_isolate_substring
|
||||
from utils.tex_file_writing import tex_to_svg_file
|
||||
@ -10,6 +11,7 @@ from mobject.types.vectorized_mobject import VGroup
|
||||
from mobject.types.vectorized_mobject import VectorizedPoint
|
||||
|
||||
import operator as op
|
||||
from functools import reduce
|
||||
|
||||
TEX_MOB_SCALE_FACTOR = 0.05
|
||||
|
||||
@ -92,7 +94,7 @@ class SingleStringTexMobject(SVGMobject):
|
||||
lambda s: s[0] in "(){}[]|.\\",
|
||||
tex.split(substr)[1:]
|
||||
))
|
||||
for substr in "\\left", "\\right"
|
||||
for substr in ("\\left", "\\right")
|
||||
]
|
||||
if num_lefts != num_rights:
|
||||
tex = tex.replace("\\left", "\\big")
|
||||
|
@ -164,7 +164,7 @@ class PMobject(Mobject):
|
||||
def pointwise_become_partial(self, mobject, a, b):
|
||||
lower_index, upper_index = [
|
||||
int(x * mobject.get_num_points())
|
||||
for x in a, b
|
||||
for x in (a, b)
|
||||
]
|
||||
for attr in self.get_array_attrs():
|
||||
full_array = getattr(mobject, attr)
|
||||
|
@ -209,7 +209,7 @@ class VMobject(Mobject):
|
||||
points = np.array(points)
|
||||
self.set_anchors_and_handles(points, *[
|
||||
interpolate(points[:-1], points[1:], alpha)
|
||||
for alpha in 1. / 3, 2. / 3
|
||||
for alpha in (1. / 3, 2. / 3)
|
||||
])
|
||||
return self
|
||||
|
||||
|
Reference in New Issue
Block a user