import math
import turtle

# Define constants for the Folium of Descartes equation
A = 16
B = 13
C1 = 5
C2 = 2
C3 = 1

def xt(t):
    return A * math.sin(t) ** 3

def yt(t):
    try:
        return B * math.cos(t) - C1 * math.cos(2 * t) - C2 * math.cos(3 * t) - C3 * math.cos(4 * t)
    except ValueError:
        # Handle invalid values of t
        return float('nan')

# Use a context manager for the turtle
with turtle.Turtle() as t:
    t.speed('fastest')
    turtle.colormode(1)
    turtle.Screen().bgcolor(0, 0, 0)

    for i in range(2550):
        t.goto(xt(i/10) * 20, yt(i/10) * 20)
        t.pencolor((1 - i/255, i/255, (255 - i)/255))
        t.dot()

    turtle.mainloop()