Skip to content

Fix #101 #164

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

Merged
merged 8 commits into from
Jul 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions manim/mobject/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def __init__(self, **kwargs):
self.init_background_lines()

def init_background_lines(self):
"""Will init all the lines of NumberPlanes (faded or not)"""
if self.faded_line_style is None:
style = dict(self.background_line_style)
# For anything numerical, like stroke_width
Expand All @@ -310,6 +311,13 @@ def init_background_lines(self):
)

def get_lines(self):
"""Generate all the lines, faded and not faded. Two sets of lines are generated: one parallel to the X-axis, and parallel to the Y-axis.

Returns
-------
Tuple[:class:`~.VGroup`, :class:`~.VGroup`]
The first (i.e the non faded lines) and second (i.e the faded lines) sets of lines, respectively.
"""
x_axis = self.get_x_axis()
y_axis = self.get_y_axis()
x_freq = self.x_line_frequency
Expand All @@ -327,22 +335,43 @@ def get_lines(self):
lines2 = VGroup(*x_lines2, *y_lines2)
return lines1, lines2

def get_lines_parallel_to_axis(self, axis1, axis2, freq, ratio):
line = Line(axis1.get_start(), axis1.get_end())
dense_freq = (1 + ratio)
def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, freq, ratio_faded_lines):
"""Generate a set of lines parallel to an axis.

Parameters
----------
axis_parallel_to : :class:`~.Line`
The axis with which the lines will be parallel.

axis_perpendicular_to : :class:`~.Line`
The axis with which the lines will be perpendicular.

ratio_faded_lines : :class:`float`
The number of faded lines between each non-faded line.

freq : :class:`float`
Frequency of non-faded lines (number of non-faded lines per graph unit).

Returns
-------
Tuple[:class:`~.VGroup`, :class:`~.VGroup`]
The first (i.e the non-faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively.
"""
line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end())
dense_freq = ratio_faded_lines
step = (1 / dense_freq) * freq

lines1 = VGroup()
lines2 = VGroup()
unit_vector_axis_perp_to = axis_perpendicular_to.get_unit_vector()
ranges = (
np.arange(0, axis2.x_max, step),
np.arange(0, axis2.x_min, -step),
np.arange(0, axis_perpendicular_to.x_max, step),
np.arange(0, axis_perpendicular_to.x_min, -step),
)
for inputs in ranges:
for k, x in enumerate(inputs):
new_line = line.copy()
new_line.move_to(axis2.number_to_point(x))
if k % (1 + ratio) == 0:
new_line.shift(unit_vector_axis_perp_to * x)
if k % ratio_faded_lines == 0:
lines1.add(new_line)
else:
lines2.add(new_line)
Expand Down Expand Up @@ -429,4 +458,4 @@ def get_coordinate_labels(self, *numbers, **kwargs):

def add_coordinates(self, *numbers):
self.add(self.get_coordinate_labels(*numbers))
return self
return self