mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 19:57:44 +00:00
Fixed NumberLine bug
This commit is contained in:
parent
86d3ade0ef
commit
1735f16d68
2 changed files with 33 additions and 28 deletions
|
|
@ -95,6 +95,7 @@ class Axes(VGroup, CoordinateSystem):
|
||||||
"number_line_config": {
|
"number_line_config": {
|
||||||
"color": LIGHT_GREY,
|
"color": LIGHT_GREY,
|
||||||
"include_tip": True,
|
"include_tip": True,
|
||||||
|
"exclude_zero_from_default_numbers": True,
|
||||||
},
|
},
|
||||||
"x_axis_config": {},
|
"x_axis_config": {},
|
||||||
"y_axis_config": {
|
"y_axis_config": {
|
||||||
|
|
@ -143,6 +144,19 @@ class Axes(VGroup, CoordinateSystem):
|
||||||
def get_axes(self):
|
def get_axes(self):
|
||||||
return self.axes
|
return self.axes
|
||||||
|
|
||||||
|
def get_coordinate_labels(self, x_vals=None, y_vals=None):
|
||||||
|
x_vals = x_vals or []
|
||||||
|
y_vals = y_vals or []
|
||||||
|
x_mobs = self.get_x_axis().get_number_mobjects(*x_vals)
|
||||||
|
y_mobs = self.get_y_axis().get_number_mobjects(*y_vals)
|
||||||
|
|
||||||
|
self.coordinate_labels = VGroup(x_mobs, y_mobs)
|
||||||
|
return self.coordinate_labels
|
||||||
|
|
||||||
|
def add_coordinates(self, x_vals=None, y_vals=None):
|
||||||
|
self.add(self.get_coordinate_labels(x_vals, y_vals))
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class ThreeDAxes(Axes):
|
class ThreeDAxes(Axes):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
|
@ -303,15 +317,6 @@ class NumberPlane(Axes):
|
||||||
def get_y_unit_size(self):
|
def get_y_unit_size(self):
|
||||||
return self.get_x_axis().get_unit_size()
|
return self.get_x_axis().get_unit_size()
|
||||||
|
|
||||||
def get_coordinate_labels(self, x_vals=None, y_vals=None):
|
|
||||||
x_vals = x_vals or []
|
|
||||||
y_vals = y_vals or []
|
|
||||||
x_mobs = self.get_x_axis().get_number_mobjects(*x_vals)
|
|
||||||
y_mobs = self.get_y_axis().get_number_mobjects(*y_vals)
|
|
||||||
|
|
||||||
self.coordinate_labels = VGroup(x_mobs, y_mobs)
|
|
||||||
return self.coordinate_labels
|
|
||||||
|
|
||||||
def get_axes(self):
|
def get_axes(self):
|
||||||
return self.axes
|
return self.axes
|
||||||
|
|
||||||
|
|
@ -342,10 +347,6 @@ class NumberPlane(Axes):
|
||||||
)
|
)
|
||||||
return self.axis_labels
|
return self.axis_labels
|
||||||
|
|
||||||
def add_coordinates(self, x_vals=None, y_vals=None):
|
|
||||||
self.add(self.get_coordinate_labels(x_vals, y_vals))
|
|
||||||
return self
|
|
||||||
|
|
||||||
def get_vector(self, coords, **kwargs):
|
def get_vector(self, coords, **kwargs):
|
||||||
kwargs["buff"] = 0
|
kwargs["buff"] = 0
|
||||||
return Arrow(
|
return Arrow(
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ class NumberLine(Line):
|
||||||
"tip_height": 0.25,
|
"tip_height": 0.25,
|
||||||
"decimal_number_config": {
|
"decimal_number_config": {
|
||||||
"num_decimal_places": 0,
|
"num_decimal_places": 0,
|
||||||
}
|
},
|
||||||
|
"exclude_zero_from_default_numbers": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|
@ -49,10 +50,10 @@ class NumberLine(Line):
|
||||||
self.shift(-self.number_to_point(self.number_at_center))
|
self.shift(-self.number_to_point(self.number_at_center))
|
||||||
|
|
||||||
self.init_leftmost_tick()
|
self.init_leftmost_tick()
|
||||||
if self.include_ticks:
|
|
||||||
self.add_tick_marks()
|
|
||||||
if self.include_tip:
|
if self.include_tip:
|
||||||
self.add_tip()
|
self.add_tip()
|
||||||
|
if self.include_ticks:
|
||||||
|
self.add_tick_marks()
|
||||||
if self.include_numbers:
|
if self.include_numbers:
|
||||||
self.add_numbers()
|
self.add_numbers()
|
||||||
|
|
||||||
|
|
@ -97,7 +98,7 @@ class NumberLine(Line):
|
||||||
def get_tick_numbers(self):
|
def get_tick_numbers(self):
|
||||||
return np.arange(
|
return np.arange(
|
||||||
self.leftmost_tick,
|
self.leftmost_tick,
|
||||||
self.x_max + self.tick_frequency / 2,
|
self.x_max - self.tick_frequency / 2,
|
||||||
self.tick_frequency
|
self.tick_frequency
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -127,7 +128,10 @@ class NumberLine(Line):
|
||||||
def default_numbers_to_display(self):
|
def default_numbers_to_display(self):
|
||||||
if self.numbers_to_show is not None:
|
if self.numbers_to_show is not None:
|
||||||
return self.numbers_to_show
|
return self.numbers_to_show
|
||||||
return np.arange(int(self.leftmost_tick), int(self.x_max) + 1)
|
numbers = np.arange(int(self.leftmost_tick), int(self.x_max) + 1)
|
||||||
|
if self.exclude_zero_from_default_numbers:
|
||||||
|
numbers = numbers[numbers != 0]
|
||||||
|
return numbers
|
||||||
|
|
||||||
def get_number_mobject(self, number,
|
def get_number_mobject(self, number,
|
||||||
number_config=None,
|
number_config=None,
|
||||||
|
|
@ -169,16 +173,16 @@ class NumberLine(Line):
|
||||||
self.add(self.numbers)
|
self.add(self.numbers)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_tip(self):
|
# def add_tip(self):
|
||||||
tip = RegularPolygon(3)
|
# tip = RegularPolygon(3)
|
||||||
color = self.color
|
# color = self.color
|
||||||
tip.set_stroke(color, width=self.get_stroke_width())
|
# tip.set_stroke(color, width=self.get_stroke_width())
|
||||||
tip.set_fill(color, opacity=1)
|
# tip.set_fill(color, opacity=1)
|
||||||
tip.set_width(self.tip_width)
|
# tip.set_width(self.tip_width)
|
||||||
tip.set_height(self.tip_height, stretch=True)
|
# tip.set_height(self.tip_height, stretch=True)
|
||||||
tip.move_to(self.get_end(), LEFT)
|
# tip.move_to(self.get_end(), LEFT)
|
||||||
self.tip = tip
|
# self.tip = tip
|
||||||
self.add(tip)
|
# self.add(tip)
|
||||||
|
|
||||||
|
|
||||||
class UnitInterval(NumberLine):
|
class UnitInterval(NumberLine):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue