Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs):
triangle = RegularPolygon(n=3, start_angle=np.pi / 2)
triangle.set_height(MED_SMALL_BUFF)
triangle.move_to(self.coords_to_point(x_val, 0), UP)
triangle.set_fill(color, 1)
triangle.set_stroke(width=0)
if label is None:
T_label = TexMobject(self.variable_point_label, fill_color=color)
else:
T_label = TexMobject(label, fill_color=color)
T_label.next_to(triangle, DOWN)
v_line = self.get_vertical_line_to_graph(
x_val, self.v_graph,
color=YELLOW
)
if animated:
self.play(
DrawBorderThenFill(triangle),
ShowCreation(v_line),
Write(T_label, run_time=1),
**kwargs
)
if np.all(side == LEFT):
def generate_counter_tex(self, counter):
color = self.get_fill_color()
counter_str = str(counter) if isinstance(counter, int) else counter
counter_tex = TexMobject(counter_str)
counter_tex.set_color(color).next_to(self.rhombus, DOWN)
return counter_tex
def get_vector_label(self, vector, label,
at_tip=False,
direction="left",
rotate=False,
color=None,
label_scale_factor=VECTOR_LABEL_SCALE_FACTOR):
if not isinstance(label, TexMobject):
if len(label) == 1:
label = "\\vec{\\textbf{%s}}" % label
label = TexMobject(label)
if color is None:
color = vector.get_color()
label.set_color(color)
label.scale(label_scale_factor)
label.add_background_rectangle()
if at_tip:
vect = vector.get_vector()
vect /= get_norm(vect)
label.next_to(vector.get_end(), vect, buff=SMALL_BUFF)
else:
angle = vector.get_angle()
if not rotate:
label.rotate(-angle, about_point=ORIGIN)
if direction == "left":
label.shift(-label.get_bottom() + 0.1 * UP)
def generate_points(self):
numer = TexMobject(self.p)
denom = TexMobject(self.q)
line = Rectangle(height = 0.02)
line.set_width(max(numer.get_width(), denom.get_width()) * 1.1, stretch = True)
self.add(numer, line, denom)
self.arrange_submobjects(DOWN, buff = 0.15)
self.numer = numer
self.line = line
self.denom = denom
def fade_all_but(self, index_or_string, opacity=0.5):
arg = index_or_string
if isinstance(arg, str):
part = self.get_part_by_tex(arg)
elif isinstance(arg, int):
part = self.submobjects[arg]
else:
raise Exception("Expected int or string, got {0}".format(arg))
for other_part in self.submobjects:
if other_part is part:
other_part.set_fill(opacity=1)
else:
other_part.set_fill(opacity=opacity)
class TexMobjectFromPresetString(TexMobject):
CONFIG = {
# To be filled by subclasses
"tex": None,
"color": None,
}
def __init__(self, **kwargs):
digest_config(self, kwargs)
TexMobject.__init__(self, self.tex, **kwargs)
self.set_color(self.color)
class Title(TextMobject):
CONFIG = {
"scale_factor": 1,
"include_underline": True,
rhombi = VGroup(*[
RhombusType(rhombus_config = {"fill_opacity" : 1})
for RhombusType in (RRhombus, HRhombus, LRhombus)
])
time_texts = VGroup(*[
TexMobject("\\times", "n^2").scale(1.2).set_color(rhombus.get_fill_color())
for rhombus in rhombi
])
rhombi_and_texts = VGroup(*[
VGroup(rhombus, time_text).arrange_submobjects(RIGHT)
for rhombus, time_text in zip(rhombi, time_texts)
])
rhombi_and_texts.arrange_submobjects(RIGHT, buff = 2)
rhombi_and_texts.to_edge(UP, buff = 1.4)
equation = TexMobject(*["n^2" if k % 2 == 0 else "=" for k in range(5)])
for text, color in zip(equation[::2], RHOMBI_COLOR_SET):
text.set_color(color)
qed = FakeQEDSymbol(jagged_percentage = 0.1)
qed.set_height(equation.get_height())
conclusions = VGroup(equation, qed)
conclusions.arrange_submobjects(RIGHT, buff = 1)
conclusions.to_corner(RIGHT+UP)
self.proof_texts = proof_texts
self.imagine_3d_text = imagine_3d_text
self.rhombi = rhombi
self.time_texts = time_texts
self.rhombi_and_texts = rhombi_and_texts
self.conclusions = conclusions
def generate_points(self):
start_angle = np.pi / 2 + self.arc_angle / 2
end_angle = np.pi / 2 - self.arc_angle / 2
self.add(Arc(
start_angle=start_angle,
angle=-self.arc_angle
))
tick_angle_range = np.linspace(start_angle, end_angle, self.num_ticks)
for index, angle in enumerate(tick_angle_range):
vect = rotate_vector(RIGHT, angle)
tick = Line((1 - self.tick_length) * vect, vect)
label = TexMobject(str(10 * index))
label.set_height(self.tick_length)
label.shift((1 + self.tick_length) * vect)
self.add(tick, label)
needle = Polygon(
LEFT, UP, RIGHT,
stroke_width=0,
fill_opacity=1,
fill_color=self.needle_color
)
needle.stretch_to_fit_width(self.needle_width)
needle.stretch_to_fit_height(self.needle_height)
needle.rotate(start_angle - np.pi / 2, about_point=ORIGIN)
self.add(needle)
self.needle = needle
def get_brace_and_text(self, perspective, direction):
anchors = self.tiling.get_border().get_anchors()
text = TexMobject("n")
self.add_fixed_orientation_mobjects(text)
if perspective == "Up":
if direction == "x":
brace = self.get_basic_brace("downleft")
else:
brace = self.get_basic_brace("upleft")
elif perspective == "Front":
if direction == "x":
brace = self.get_basic_brace("downleft")
brace.rotate(np.pi/2., axis = UP, about_point = anchors[3])
else:
brace = self.get_basic_brace("left")
brace.rotate(-np.pi/2., axis = OUT, about_point = anchors[1])
elif perspective == "Right":
if direction == "x":
brace = self.get_basic_brace("downright")
p1, interim_point,
color=dx_line_color
)
group.df_line = Line(
interim_point, p2,
color=df_line_color
)
group.add(group.dx_line, group.df_line)
labels = VGroup()
if dx_label is not None:
group.dx_label = TexMobject(dx_label)
labels.add(group.dx_label)
group.add(group.dx_label)
if df_label is not None:
group.df_label = TexMobject(df_label)
labels.add(group.df_label)
group.add(group.df_label)
if len(labels) > 0:
max_width = 0.8 * group.dx_line.get_width()
max_height = 0.8 * group.df_line.get_height()
if labels.get_width() > max_width:
labels.set_width(max_width)
if labels.get_height() > max_height:
labels.set_height(max_height)
if dx_label is not None:
group.dx_label.next_to(
group.dx_line,
np.sign(dx) * DOWN,
buff=group.dx_label.get_height() / 2
def get_axis_label(self, label_tex, axis, edge, direction, buff=MED_SMALL_BUFF):
label = TexMobject(label_tex)
label.next_to(
axis.get_edge_center(edge), direction,
buff=buff
)
label.shift_onto_screen(buff=MED_SMALL_BUFF)
return label