Skip to content

Commit 4466cfe

Browse files
authored
Merge branch 'master' into add_warnings
2 parents ed99427 + e9aba0b commit 4466cfe

27 files changed

+635
-148
lines changed

docs/source/development/changelog.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,28 @@ Changelog
44
Unreleased
55
----------
66

7-
No changes
7+
Fixed bugs
8+
^^^^^^^^^^
9+
10+
- `#1592 <https://github.com/3b1b/manim/pull/1592>`__: Fixed ``put_start_and_end_on`` in 3D
11+
- `#1601 <https://github.com/3b1b/manim/pull/1601>`__: Fixed ``DecimalNumber``'s scaling issue
12+
13+
New Features
14+
^^^^^^^^^^^^
15+
16+
- `#1598 <https://github.com/3b1b/manim/pull/1598>`__: Supported the elliptical arc command ``A`` for ``SVGMobject``
17+
- `#1607 <https://github.com/3b1b/manim/pull/1607>`__: Added ``FlashyFadeIn``
18+
- `#1607 <https://github.com/3b1b/manim/pull/1607>`__: Save triangulation
19+
- `#1625 <https://github.com/3b1b/manim/pull/1625>`__: Added new ``Code`` mobject
20+
- `bd356da <https://github.com/3b1b/manim/commit/bd356daa99bfe3134fcb192a5f72e0d76d853801>`__: Added ``VCube``
21+
- `6d72893 <https://github.com/3b1b/manim/commit/6d7289338234acc6658b9377c0f0084aa1fa7119>`__: Supported ``ValueTracker`` to track vectors
22+
23+
Refactor
24+
^^^^^^^^
25+
26+
- `#1601 <https://github.com/3b1b/manim/pull/1601>`__: Change back to simpler ``Mobject.scale`` implementation
27+
- `b667db2 <https://github.com/3b1b/manim/commit/b667db2d311a11cbbca2a6ff511d2c3cf1675486>`__: Simplify ``Square``
28+
- `40290ad <https://github.com/3b1b/manim/commit/40290ada8343f10901fa9151cbdf84689667786d>`__: Removed unused parameter ``triangulation_locked``
829

930
v1.1.0
1031
-------

manimlib/camera/camera.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,6 @@ def resize_frame_shape(self, fixed_dimension=0):
316316
self.frame.set_height(frame_height)
317317
self.frame.set_width(frame_width)
318318

319-
def pixel_coords_to_space_coords(self, px, py, relative=False):
320-
pw, ph = self.fbo.size
321-
fw, fh = self.get_frame_shape()
322-
fc = self.get_frame_center()
323-
if relative:
324-
return 2 * np.array([px / pw, py / ph, 0])
325-
else:
326-
# Only scale wrt one axis
327-
scale = fh / ph
328-
return fc + scale * np.array([(px - pw / 2), (py - ph / 2), 0])
329-
330319
# Rendering
331320
def capture(self, *mobjects, **kwargs):
332321
self.refresh_perspective_uniforms()
@@ -423,6 +412,8 @@ def set_shader_uniforms(self, shader, shader_wrapper):
423412
shader[name].value = tid
424413
for name, value in it.chain(shader_wrapper.uniforms.items(), self.perspective_uniforms.items()):
425414
try:
415+
if isinstance(value, np.ndarray):
416+
value = tuple(value)
426417
shader[name].value = value
427418
except KeyError:
428419
pass
@@ -449,21 +440,28 @@ def refresh_perspective_uniforms(self):
449440
}
450441

451442
def init_textures(self):
452-
self.path_to_texture_id = {}
443+
self.n_textures = 0
444+
self.path_to_texture = {}
453445

454446
def get_texture_id(self, path):
455-
if path not in self.path_to_texture_id:
456-
# A way to increase tid's sequentially
457-
tid = len(self.path_to_texture_id)
447+
if path not in self.path_to_texture:
448+
tid = self.n_textures
449+
self.n_textures += 1
458450
im = Image.open(path).convert("RGBA")
459451
texture = self.ctx.texture(
460452
size=im.size,
461453
components=len(im.getbands()),
462454
data=im.tobytes(),
463455
)
464456
texture.use(location=tid)
465-
self.path_to_texture_id[path] = tid
466-
return self.path_to_texture_id[path]
457+
self.path_to_texture[path] = (tid, texture)
458+
return self.path_to_texture[path][0]
459+
460+
def release_texture(self, path):
461+
tid_and_texture = self.path_to_texture.pop(path, None)
462+
if tid_and_texture:
463+
tid_and_texture[1].release()
464+
return self
467465

468466

469467
# Mostly just defined so old scenes don't break

manimlib/mobject/changing.py

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
from manimlib.constants import *
1+
import numpy as np
2+
from manimlib.constants import BLUE_D
3+
from manimlib.constants import BLUE_B
4+
from manimlib.constants import BLUE_E
5+
from manimlib.constants import GREY_BROWN
6+
from manimlib.constants import WHITE
7+
from manimlib.mobject.mobject import Mobject
28
from manimlib.mobject.types.vectorized_mobject import VMobject
39
from manimlib.mobject.types.vectorized_mobject import VGroup
410
from manimlib.utils.rate_functions import smooth
5-
from manimlib.utils.space_ops import get_norm
611

712

813
class AnimatedBoundary(VGroup):
@@ -74,25 +79,63 @@ class TracedPath(VMobject):
7479
CONFIG = {
7580
"stroke_width": 2,
7681
"stroke_color": WHITE,
77-
"min_distance_to_new_point": 0.1,
82+
"time_traced": np.inf,
83+
"fill_opacity": 0,
84+
"time_per_anchor": 1 / 15,
7885
}
7986

8087
def __init__(self, traced_point_func, **kwargs):
8188
super().__init__(**kwargs)
8289
self.traced_point_func = traced_point_func
83-
self.add_updater(lambda m: m.update_path())
90+
self.time = 0
91+
self.traced_points = []
92+
self.add_updater(lambda m, dt: m.update_path(dt))
8493

85-
def update_path(self):
86-
new_point = self.traced_point_func()
87-
if not self.has_points():
88-
self.start_new_path(new_point)
89-
self.add_line_to(new_point)
94+
def update_path(self, dt):
95+
if dt == 0:
96+
return self
97+
point = self.traced_point_func().copy()
98+
self.traced_points.append(point)
99+
100+
if self.time_traced < np.inf:
101+
n_relevant_points = int(self.time_traced / dt + 0.5)
102+
# n_anchors = int(self.time_traced / self.time_per_anchor)
103+
n_tps = len(self.traced_points)
104+
if n_tps < n_relevant_points:
105+
points = self.traced_points + [point] * (n_relevant_points - n_tps)
106+
else:
107+
points = self.traced_points[n_tps - n_relevant_points:]
108+
# points = [
109+
# self.traced_points[max(n_tps - int(alpha * n_relevant_points) - 1, 0)]
110+
# for alpha in np.linspace(1, 0, n_anchors)
111+
# ]
112+
# Every now and then refresh the list
113+
if n_tps > 10 * n_relevant_points:
114+
self.traced_points = self.traced_points[-n_relevant_points:]
115+
else:
116+
# sparseness = max(int(self.time_per_anchor / dt), 1)
117+
# points = self.traced_points[::sparseness]
118+
# points[-1] = self.traced_points[-1]
119+
points = self.traced_points
120+
121+
if points:
122+
self.set_points_smoothly(points)
123+
124+
self.time += dt
125+
return self
126+
127+
128+
class TracingTail(TracedPath):
129+
CONFIG = {
130+
"stroke_width": (0, 3),
131+
"stroke_opacity": (0, 1),
132+
"stroke_color": WHITE,
133+
"time_traced": 1.0,
134+
}
135+
136+
def __init__(self, mobject_or_func, **kwargs):
137+
if isinstance(mobject_or_func, Mobject):
138+
func = mobject_or_func.get_center
90139
else:
91-
# Set the end to be the new point
92-
self.get_points()[-1] = new_point
93-
94-
# Second to last point
95-
nppcc = self.n_points_per_curve
96-
dist = get_norm(new_point - self.get_points()[-nppcc])
97-
if dist >= self.min_distance_to_new_point:
98-
self.add_line_to(new_point)
140+
func = mobject_or_func
141+
super().__init__(func, **kwargs)

manimlib/mobject/coordinate_systems.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from manimlib.mobject.number_line import NumberLine
1111
from manimlib.mobject.svg.tex_mobject import Tex
1212
from manimlib.mobject.types.vectorized_mobject import VGroup
13+
from manimlib.utils.config_ops import digest_config
1314
from manimlib.utils.config_ops import merge_dicts_recursively
1415
from manimlib.utils.simple_functions import binary_search
1516
from manimlib.utils.space_ops import angle_of_vector
@@ -25,13 +26,18 @@ class CoordinateSystem():
2526
"""
2627
CONFIG = {
2728
"dimension": 2,
28-
"x_range": np.array([-8.0, 8.0, 1.0]),
29-
"y_range": np.array([-4.0, 4.0, 1.0]),
30-
"width": None,
31-
"height": None,
29+
"default_x_range": [-8.0, 8.0, 1.0],
30+
"default_y_range": [-4.0, 4.0, 1.0],
31+
"width": FRAME_WIDTH,
32+
"height": FRAME_HEIGHT,
3233
"num_sampled_graph_points_per_tick": 20,
3334
}
3435

36+
def __init__(self, **kwargs):
37+
digest_config(self, kwargs)
38+
self.x_range = np.array(self.default_x_range)
39+
self.y_range = np.array(self.default_y_range)
40+
3541
def coords_to_point(self, *coords):
3642
raise Exception("Not implemented")
3743

@@ -127,6 +133,7 @@ def get_graph(self, function, x_range=None, **kwargs):
127133
**kwargs
128134
)
129135
graph.underlying_function = function
136+
graph.x_range = x_range
130137
return graph
131138

132139
def get_parametric_curve(self, function, **kwargs):
@@ -282,7 +289,9 @@ def __init__(self,
282289
x_range=None,
283290
y_range=None,
284291
**kwargs):
285-
super().__init__(**kwargs)
292+
CoordinateSystem.__init__(self, **kwargs)
293+
VGroup.__init__(self, **kwargs)
294+
286295
if x_range is not None:
287296
self.x_range[:len(x_range)] = x_range
288297
if y_range is not None:
@@ -441,7 +450,7 @@ def get_lines(self):
441450
return lines1, lines2
442451

443452
def get_lines_parallel_to_axis(self, axis1, axis2):
444-
freq = axis1.x_step
453+
freq = axis2.x_step
445454
ratio = self.faded_line_ratio
446455
line = Line(axis1.get_start(), axis1.get_end())
447456
dense_freq = (1 + ratio)
@@ -501,15 +510,15 @@ def point_to_number(self, point):
501510
def p2n(self, point):
502511
return self.point_to_number(point)
503512

504-
def get_default_coordinate_values(self):
513+
def get_default_coordinate_values(self, skip_first=True):
505514
x_numbers = self.get_x_axis().get_tick_range()[1:]
506515
y_numbers = self.get_y_axis().get_tick_range()[1:]
507516
y_numbers = [complex(0, y) for y in y_numbers if y != 0]
508517
return [*x_numbers, *y_numbers]
509518

510-
def add_coordinate_labels(self, numbers=None, **kwargs):
519+
def add_coordinate_labels(self, numbers=None, skip_first=True, **kwargs):
511520
if numbers is None:
512-
numbers = self.get_default_coordinate_values()
521+
numbers = self.get_default_coordinate_values(skip_first)
513522

514523
self.coordinate_labels = VGroup()
515524
for number in numbers:
@@ -522,6 +531,15 @@ def add_coordinate_labels(self, numbers=None, **kwargs):
522531
axis = self.get_x_axis()
523532
value = z.real
524533
number_mob = axis.get_number_mobject(value, **kwargs)
534+
# For i and -i, remove the "1"
535+
if z.imag == 1:
536+
number_mob.remove(number_mob[0])
537+
if z.imag == -1:
538+
number_mob.remove(number_mob[1])
539+
number_mob[0].next_to(
540+
number_mob[1], LEFT,
541+
buff=number_mob[0].get_width() / 4
542+
)
525543
self.coordinate_labels.add(number_mob)
526544
self.add(self.coordinate_labels)
527545
return self

0 commit comments

Comments
 (0)