import numpy as np
import matplotlib.pyplot as plt

def descartes(ax, ran_x, ran_y, ax_title,x_label = "x", y_label = "y"):
    ax.set_xlabel(x_label, fontsize = 12)
    ax.set_ylabel(y_label, fontsize = 12)
    ax.set_xlim(ran_x[0], ran_x[1])
    ax.set_ylim(ran_y[0], ran_y[1])
    ax.set_title(ax_title, fontsize = 14)
    ax.grid()
    ax.axhline(0, color = "black")
    ax.axvline(0, color = "black")

fig = plt.figure(figsize = (6, 6))
ax = fig.add_subplot(111)

title1 = "Tokyo University 2024 Math qu.4 NO1"
descartes(ax, [-10,10], [-10, 10],title1)

cmap = plt.get_cmap('jet')
cr=0/30
x=np.linspace(-10,10,1000)
y=-1*np.sqrt(2)/4*(x**2)+4*np.sqrt(2)
ax.plot(x ,y , color = cmap(cr))

for t in range(1,4):
#for t in np.linspace(1,4,75):
    cr=(8+2*t)/50
    x1=t
    y1=-1*np.sqrt(2)/4*(t**2)+4*np.sqrt(2)
    m=np.sqrt(2)/t
    x=np.linspace(-10,10,1000)
    y=m*(x-x1)+y1
    ax.plot(x,y,color=cmap(cr))

    cr=(20+2*t)/50
    m=t/(-1*np.sqrt(2))
    x=np.linspace(-10,10,1000)
    y=m*(x-x1)+y1
    ax.plot(x,y,color=cmap(cr))

    cr=(42+2*t)/50
    theta=np.linspace(0,2*np.pi,100)
    r=1/4*np.sqrt(t**2+2)*(t**2-16)
    x2=1/4*(t**3)-3*t
    y2=0
    x=r*np.cos(theta)+x2
    y=r*np.sin(theta)+y2
    ax.plot(x ,y , color = cmap(cr))

    x=x1
    y=y1
    ax.scatter(x,y,color="red")

plt.show()