from manim import *
from manim import SurroundingRectangle as sr
class GetHorizontalLineExample(Scene):
def construct(self):
self.camera.background_color=PURE_BLUE
idf=Text("Identity Function",color=RED).scale(0.50)
self.add(idf)
self.play(Write(idf))
self.wait(10)
#self.play(FadeOut(idf))
#idf=Text("Identity Function",color=RED).scale(0.50)
self.play(idf.animate.move_to(5*LEFT+2.85*UP))
dmn1=Tex(r"A function is called Identity Function if its domain and range is set of real numbers R i.e. f : R$\rightarrow{}$R and defined as f(x)=x.").scale(0.60)
dmn1.move_to(2.0*LEFT+1.85*UP)
#self.add(dmn1)
srdmn1=sr(dmn1)
self.play(Write(srdmn1),Write(dmn1))
self.wait(25)
self.play(FadeOut(dmn1),FadeOut(srdmn1),FadeOut(idf),)
idf=Text("Identity Function Graph",color=RED).scale(0.50)
idf.move_to(4.5*LEFT+2.85*UP)
self.play(Write(idf))
self.wait(5)
tx0=Text("x").scale(0.80)
ty0=Text("y=f(x)=x").scale(0.80)
tx1=Text("-3").scale(0.80)
ty1=Text("-3").scale(0.80)
tx2=Text("-2").scale(0.80)
ty2=Text("-2").scale(0.80)
tx3=Text("-1").scale(0.80)
ty3=Text("-1").scale(0.80)
tx4=Text("0").scale(0.80)
ty4=Text("0").scale(0.80)
tx5=Text("1").scale(0.80)
ty5=Text("1").scale(0.80)
tx6=Text("2").scale(0.80)
ty6=Text("2").scale(0.80)
tx7=Text("3").scale(0.80)
ty7=Text("3").scale(0.80)
t= MobjectTable([[tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7],[ty0,ty1,ty2,ty3,ty4,ty5,ty6,ty7]],include_outer_lines=True).scale(0.40)
t.move_to(3.75*LEFT+1.85*UP)
self.play(Write(t))
self.wait(5)
ldot3n= LabeledDot("(-3,-3)",color=RED).scale(0.20)
ldot2n= LabeledDot("(-2,-2)",color=RED).scale(0.20)
ldot1n= LabeledDot("(-1,-1)",color=RED).scale(0.20)
ldoto= LabeledDot("(0,0)",color=RED).scale(0.30)
ldot1= LabeledDot("(1,1)",color=RED).scale(0.30)
ldot2= LabeledDot("(2,2)",color=RED).scale(0.30)
ldot3= LabeledDot("(3,3)",color=RED).scale(0.30)
ax = Axes(x_range=[-5,6,1],y_range=[-5,6,1],x_length=6,y_length=6).add_coordinates().scale(0.85)
labels = ax.get_axis_labels(Tex("x-axis").scale(0.7), Text("y-axis").scale(0.45))
self.play(Write(ax),Write(labels))
self.wait(5)
#np=NumberPlane()
####################################
###################
point3n = ax.c2p(-3, -3)
dot3n =Dot(point3n)
line3xn = ax.get_horizontal_line(point3n, line_func=Line)
line3yn= ax.get_vertical_line(point3n, line_func=Line)
self.play(FadeIn(sr(t.get_columns()[1])))
self.play(Create(line3xn,run_time=3))
self.play(Create(line3yn,run_time=3))
self.play(Transform(sr(t.get_columns()[1].copy()),dot3n),run_time=3)
self.play(Write(ldot3n.move_to(dot3n.get_center()),run_time=3))
self.play(Flash(ldot3n))
self.wait(5)
point2n = ax.c2p(-2, -2)
dot2n=Dot(point2n)
line2xn = ax.get_horizontal_line(point2n, line_func=Line)
line2yn= ax.get_vertical_line(point2n, line_func=Line)
self.play(FadeIn(sr(t.get_columns()[2])))
self.play(Create(line2xn,run_time=3))
self.play(Create(line2yn,run_time=3))
self.play(Transform(t.get_columns()[2].copy(),dot2n),run_time=3)
self.play(Write(ldot2n.move_to(dot2n.get_center()),run_time=3))
self.play(Flash(dot2n))
point1n= ax.c2p(-1, -1)
dot1n=Dot(point1n)
line1xn = ax.get_horizontal_line(point1n, line_func=Line)
line1yn= ax.get_vertical_line(point1n, line_func=Line)
self.add(sr(t.get_columns()[3]))
self.play(Create(line1xn,run_time=0))
self.play(Create(line1yn,run_time=0))
self.play(Transform(t.get_columns()[3].copy(),dot1n),run_time=0)
self.play(Write(ldot1n.move_to(dot1n.get_center()),run_time=0))
self.play(Flash(dot1n))
########################################################
pointo= ax.c2p(0, 0)
doto=Dot(pointo)
self.play(FadeIn(sr(t.get_columns()[4])))
linexo = ax.get_horizontal_line(pointo, line_func=Line)
lineyo= ax.get_vertical_line(pointo, line_func=Line)
self.play(Create(linexo,run_time=0))
self.play(Create(lineyo,run_time=0))
self.play(Transform(t.get_columns()[4].copy(),doto),run_time=0)
self.play(Write(ldoto.move_to(doto.get_center()),run_time=0))
self.play(Flash(doto))
########################################################
point1 = ax.c2p(1, 1)
dot1 =Dot(point1)
self.play(FadeIn(sr(t.get_columns()[5])))
line1x = ax.get_horizontal_line(point1, line_func=Line)
line1y= ax.get_vertical_line(point1, line_func=Line)
self.play(Create(line1x,run_time=0))
self.play(Create(line1y,run_time=0))
self.play(Transform(t.get_columns()[5].copy(),dot1),run_time=0)
self.play(Create(ldot1.move_to(dot1.get_center()),run_time=0))
self.play(Flash(dot1))
point2 = ax.c2p(2, 2)
dot2=Dot(point2)
self.play(FadeIn(sr(t.get_columns()[6])))
line2x = ax.get_horizontal_line(point2, line_func=Line)
line2y= ax.get_vertical_line(point2, line_func=Line)
self.play(Create(line2x,run_time=0))
self.play(Create(line2y,run_time=0))
self.play(Transform(t.get_columns()[6].copy(),dot2),run_time=0)
self.play(Write(ldot2.move_to(dot2.get_center()),run_time=0))
self.play(Flash(dot2))
point3= ax.c2p(3, 3)
dot3=Dot(point3)
self.play(FadeIn(sr(t.get_columns()[7])))
line3x = ax.get_horizontal_line(point3, line_func=Line)
line3y= ax.get_vertical_line(point3, line_func=Line)
self.play(Create(line3x,run_time=0))
self.play(Create(line3y,run_time=0))
self.play(Transform(t.get_columns()[7].copy(),dot3),run_time=0)
self.play(Create(ldot3.move_to(dot3.get_center()),run_time=0))
self.play(Flash(dot3))
line1n = Line(dot3n,dot2n)
self.add(line1n)
line2n = Line(dot2n,dot1n)
self.add(line2n)
line1on = Line(dot1n,doto)
self.add(line1on)
line1o = Line(doto,dot1)
self.add(line1o)
line1 = Line(dot1,dot2)
self.add(line1)
line2 = Line(dot2,dot3)
self.add(line2)
self.wait(5)
self.remove(ldot3,ldot2,ldot1,ldoto,ldot1n,ldot2n,ldot3n)
self.remove( line3xn, line3yn, line2xn, line2yn,line1xn, line1yn,linexo, lineyo,line3x, line3y, line2x, line2y,line1x, line1y)
self.remove(line1,line2,line1n,line2n,line1o,line1on)
self.remove(dot3,dot2,dot1,doto,dot1n,dot2n,dot3n)
l=DoubleArrow(dot3n,dot3,tip_length=0.30,buff=0.0)
self.add(l)
self.wait(5)