-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Finish issue 3804 and pass all the tests of number_line #3962
Open
liuyiheng0113
wants to merge
5
commits into
ManimCommunity:main
Choose a base branch
from
liuyiheng0113:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b82f527
finish issue 3804
liuyiheng0113 5c968a9
finish issue 3804 for manim
liuyiheng0113 bed2fe7
finish issue 3804, change number_line.py and add animatable_coordinat…
liuyiheng0113 2cba119
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 42000da
Merge branch 'main' into main
liuyiheng0113 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
manim/mobject/graphing/animatable_coordinate_systems.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from __future__ import annotations | ||
|
||
from manim import * | ||
|
||
|
||
class AnimatableNumberLine(NumberLine): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.x_range_tracker = ValueTracker(self.x_range) | ||
Check warning Code scanning / CodeQL Overwriting attribute in super-class or sub-class Warning
Assignment overwrites attribute x_range_tracker, which was previously defined in superclass
NumberLine Error loading related location Loading |
||
|
||
def get_x_range(self): | ||
return self.x_range_tracker.get_value() | ||
|
||
def set_x_range(self, new_range): | ||
self.x_range_tracker.set_value(new_range) | ||
self.x_range = new_range | ||
self.x_min, self.x_max, self.x_step = new_range | ||
self.rebuild() | ||
|
||
def rebuild(self): | ||
self.clear() | ||
self.__init__( | ||
x_range=self.get_x_range(), | ||
length=self.length, | ||
include_ticks=self.include_ticks, | ||
include_numbers=self.include_numbers, | ||
**{ | ||
k: v | ||
for k, v in self.__dict__.items() | ||
if k not in ["x_range", "length", "include_ticks", "include_numbers"] | ||
}, | ||
) | ||
|
||
|
||
class ChangeNumberLineRange(Animation): | ||
def __init__(self, number_line, new_range, **kwargs): | ||
self.new_range = new_range | ||
super().__init__(number_line, **kwargs) | ||
|
||
def interpolate_mobject(self, alpha): | ||
current_range = [ | ||
interpolate(start, end, alpha) | ||
for start, end in zip(self.mobject.get_x_range(), self.new_range) | ||
] | ||
self.mobject.set_x_range(current_range) | ||
|
||
|
||
class AnimatableNumberPlane(NumberPlane): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.x_range_tracker = ValueTracker(self.x_range) | ||
self.y_range_tracker = ValueTracker(self.y_range) | ||
|
||
def get_x_range(self): | ||
return self.x_range_tracker.get_value() | ||
|
||
def get_y_range(self): | ||
return self.y_range_tracker.get_value() | ||
|
||
def set_x_range(self, new_range): | ||
self.x_range_tracker.set_value(new_range) | ||
self.x_range = new_range | ||
self.rebuild() | ||
|
||
def set_y_range(self, new_range): | ||
self.y_range_tracker.set_value(new_range) | ||
self.y_range = new_range | ||
self.rebuild() | ||
|
||
def rebuild(self): | ||
self.clear() | ||
self.__init__( | ||
x_range=self.get_x_range(), | ||
y_range=self.get_y_range(), | ||
**{ | ||
k: v | ||
for k, v in self.__dict__.items() | ||
if k not in ["x_range", "y_range"] | ||
}, | ||
) | ||
|
||
def get_lines(self): | ||
x_lines = VGroup() | ||
y_lines = VGroup() | ||
x_min, x_max = self.x_range[:2] | ||
y_min, y_max = self.y_range[:2] | ||
for x in self.get_x_axis().get_tick_range(): | ||
if x_min <= x <= x_max: | ||
x_lines.add(self.get_vertical_line(self.c2p(x, 0))) | ||
for y in self.get_y_axis().get_tick_range(): | ||
if y_min <= y <= y_max: | ||
y_lines.add(self.get_horizontal_line(self.c2p(0, y))) | ||
return VGroup(x_lines, y_lines) | ||
|
||
|
||
class ChangeNumberPlaneRange(Animation): | ||
def __init__(self, number_plane, new_x_range=None, new_y_range=None, **kwargs): | ||
self.new_x_range = new_x_range | ||
self.new_y_range = new_y_range | ||
super().__init__(number_plane, **kwargs) | ||
|
||
def interpolate_mobject(self, alpha): | ||
if self.new_x_range: | ||
current_x_range = [ | ||
interpolate(start, end, alpha) | ||
for start, end in zip(self.mobject.get_x_range(), self.new_x_range) | ||
] | ||
self.mobject.set_x_range(current_x_range) | ||
if self.new_y_range: | ||
current_y_range = [ | ||
interpolate(start, end, alpha) | ||
for start, end in zip(self.mobject.get_y_range(), self.new_y_range) | ||
] | ||
self.mobject.set_y_range(current_y_range) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
'import *' may pollute namespace Note