-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding docs for VectorScene and LinearTransformationScene and reimplementing method #3681
Changes from 1 commit
0639a49
f262661
cffac8d
390aa3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||||||||||||||
|
||||||||||||||||||
__all__ = ["VectorScene", "LinearTransformationScene"] | ||||||||||||||||||
|
||||||||||||||||||
from typing import Callable | ||||||||||||||||||
from typing import Callable, Any | ||||||||||||||||||
|
||||||||||||||||||
import numpy as np | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -14,7 +14,7 @@ | |||||||||||||||||
from manim.mobject.graphing.coordinate_systems import Axes, NumberPlane | ||||||||||||||||||
from manim.mobject.opengl.opengl_mobject import OpenGLMobject | ||||||||||||||||||
from manim.mobject.text.tex_mobject import MathTex, Tex | ||||||||||||||||||
from manim.utils.config_ops import update_dict_recursively | ||||||||||||||||||
from manim.utils.config_ops import merge_dicts_recursively | ||||||||||||||||||
|
||||||||||||||||||
from .. import config | ||||||||||||||||||
from ..animation.animation import Animation | ||||||||||||||||||
|
@@ -79,20 +79,90 @@ def add_plane(self, animate: bool = False, **kwargs): | |||||||||||||||||
self.add(plane) | ||||||||||||||||||
return plane | ||||||||||||||||||
|
||||||||||||||||||
def add_axes(self, animate: bool = False, color: bool = WHITE, **kwargs): | ||||||||||||||||||
def add_axes( | ||||||||||||||||||
self, | ||||||||||||||||||
animate: bool = False, | ||||||||||||||||||
animation: Animation = Create, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. animation, animation_kwargs and play_kwargsWhy must a user be limited to the |
||||||||||||||||||
animation_kwargs: dict[str, Any] | None = {}, | ||||||||||||||||||
play_kwargs: dict[str, Any] | None = {}, | ||||||||||||||||||
axis_config: dict[str, Any] | None = {}, | ||||||||||||||||||
**axis_kwargs: dict[str, Any] | None, | ||||||||||||||||||
Comment on lines
+86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
These are the correct typehints, as your code does not deal with the case of each parameter being There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I should identify the method of depreciation, remove them, and add examples for that, which will not be deprecated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove the following:
If I understand, please let me know if I am wrong. Does the depreciation method mean deleting them from the source code? Right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After taking a look at the source code again, I will say that it's my mistake. These methods shouldn't be deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean I should create as many code examples as possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means the implementation of the methods should be the same. >>> from manim import LinearTransformationScene
>>> scene = LinearTransformationScene()
>>> scene.add_axes()
Axes(NumberLine, NumberLine) |
||||||||||||||||||
): | ||||||||||||||||||
""" | ||||||||||||||||||
Adds a pair of Axes to the Scene. | ||||||||||||||||||
|
||||||||||||||||||
Parameters | ||||||||||||||||||
---------- | ||||||||||||||||||
animate | ||||||||||||||||||
Whether or not to animate the addition of the axes through Create. | ||||||||||||||||||
color | ||||||||||||||||||
The color of the axes. Defaults to WHITE. | ||||||||||||||||||
""" | ||||||||||||||||||
axes = Axes(color=color, axis_config={"unit_size": 1}) | ||||||||||||||||||
|
||||||||||||||||||
animation | ||||||||||||||||||
The animation used to add the axes. | ||||||||||||||||||
|
||||||||||||||||||
animation_kwargs | ||||||||||||||||||
Any valid keyword arguments of animation. | ||||||||||||||||||
|
||||||||||||||||||
play_kwargs | ||||||||||||||||||
Any valid keyword arguments of play. | ||||||||||||||||||
|
||||||||||||||||||
axis_config | ||||||||||||||||||
Any valid keyword arguments of Axes. | ||||||||||||||||||
|
||||||||||||||||||
axis_kwargs | ||||||||||||||||||
Any valid keyword arguments of Axes. | ||||||||||||||||||
|
||||||||||||||||||
Returns | ||||||||||||||||||
------- | ||||||||||||||||||
Axes | ||||||||||||||||||
The Axes object. | ||||||||||||||||||
|
||||||||||||||||||
Examples | ||||||||||||||||||
-------- | ||||||||||||||||||
.. manim:: AddingAxes | ||||||||||||||||||
class AddingAxes(VectorScene): | ||||||||||||||||||
def construct(self): | ||||||||||||||||||
axis_config = {"include_tip": True, "unit_size": 2, "include_numbers": True} | ||||||||||||||||||
animation = FadeIn | ||||||||||||||||||
animation_kwargs = {"shift": LEFT} | ||||||||||||||||||
play_kwargs = {"run_time": 1, "rate_func": linear} | ||||||||||||||||||
|
||||||||||||||||||
axes = self.add_axes( | ||||||||||||||||||
animate=True, | ||||||||||||||||||
animation=animation, | ||||||||||||||||||
animation_kwargs=animation_kwargs, | ||||||||||||||||||
play_kwargs=play_kwargs, | ||||||||||||||||||
axis_config=axis_config, | ||||||||||||||||||
x_range=[0, 10, 1], | ||||||||||||||||||
y_range=[-2, 6, 1], | ||||||||||||||||||
x_length=5, | ||||||||||||||||||
y_length=5, | ||||||||||||||||||
) | ||||||||||||||||||
self.play(axes.animate.shift(LEFT)) | ||||||||||||||||||
self.wait() | ||||||||||||||||||
|
||||||||||||||||||
.. manim:: AddingAxes2 | ||||||||||||||||||
class AddingAxes2(VectorScene): | ||||||||||||||||||
def construct(self): | ||||||||||||||||||
axis_config = {"include_tip": True, "unit_size": 2, "include_numbers": True} | ||||||||||||||||||
axes = self.add_axes(animate=True, axis_config=axis_config) | ||||||||||||||||||
self.play(axes.animate.shift(LEFT)) | ||||||||||||||||||
self.wait() | ||||||||||||||||||
|
||||||||||||||||||
""" | ||||||||||||||||||
axis_kwargs = merge_dicts_recursively( | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be marked in docs that there are default parameters for axis settings, and to change it the user have to pass it explicitly |
||||||||||||||||||
{ | ||||||||||||||||||
"x_range": [-5, 5, 1], | ||||||||||||||||||
"y_range": [-5, 5, 1], | ||||||||||||||||||
"x_length": 5, | ||||||||||||||||||
"y_length": 5, | ||||||||||||||||||
}, | ||||||||||||||||||
axis_kwargs, | ||||||||||||||||||
) | ||||||||||||||||||
axis_config = merge_dicts_recursively({"unit_size": 1}, axis_config) | ||||||||||||||||||
|
||||||||||||||||||
axes = Axes(**axis_kwargs, axis_config=axis_config) | ||||||||||||||||||
if animate: | ||||||||||||||||||
self.play(Create(axes)) | ||||||||||||||||||
self.play(animation(axes, **animation_kwargs), **play_kwargs) | ||||||||||||||||||
self.add(axes) | ||||||||||||||||||
return axes | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -1003,8 +1073,11 @@ def get_piece_movement(self, pieces: list | tuple | np.ndarray): | |||||||||||||||||
Animation | ||||||||||||||||||
The animation of the movement. | ||||||||||||||||||
""" | ||||||||||||||||||
start = VGroup(*pieces) | ||||||||||||||||||
target = VGroup(*(mob.target for mob in pieces)) | ||||||||||||||||||
|
||||||||||||||||||
v_pieces = [piece for piece in pieces if isinstance(piece, VMobject)] | ||||||||||||||||||
start = VGroup(*v_pieces) | ||||||||||||||||||
target = VGroup(*(mob.target for mob in v_pieces)) | ||||||||||||||||||
|
||||||||||||||||||
# don't add empty VGroups | ||||||||||||||||||
if self.leave_ghost_vectors and start.submobjects: | ||||||||||||||||||
# start.copy() gives a VGroup of Vectors | ||||||||||||||||||
|
@@ -1091,6 +1164,7 @@ def apply_matrix(self, matrix: np.ndarray | list | tuple, **kwargs): | |||||||||||||||||
**kwargs | ||||||||||||||||||
Any valid keyword argument of self.apply_transposed_matrix() | ||||||||||||||||||
""" | ||||||||||||||||||
|
||||||||||||||||||
self.apply_transposed_matrix(np.array(matrix).T, **kwargs) | ||||||||||||||||||
|
||||||||||||||||||
def apply_inverse(self, matrix: np.ndarray | list | tuple, **kwargs): | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did I remove the color argument?
Because it is not working.
self.add_axes(color=RED)
will not work, because the color of the VGroup is set before the axes creation.I could add these lines:
but I don't see the reason, the much more powerful would be the new solution when a user could use dictionaries to specify the exact all parameters in axes