I wrote a double pendulum simulation based on one from The Coding Train
One display shows the pendulum and is cleared every iteration, the other display shows the trail of the pendulum and isn't cleared.
There are a few different variables to play around with at the start of the file, setting a1 and a2 to random numbers is a good start so you get a different image each run.
clear
r1 = 200
r2 = 200
m1 = 40
m2 = 40
a1 = pi/2
a2 = pi/2
//a1 = rnd*pi
//a2 = rnd*pi
a1_v = 0
a2_v = 0
g = 2
prex2= 1000
prey2= 1000
display(0).mode = displayMode.pixel
dots = display(0)
dots.clear
dots.color = color.rgba(255,255,255,0)
red = 0; green = 255; blue = 125
while true
gfx.clear
num1 = -g * (2 * m1 + m2) * sin(a1)
num2 = -m2 * g * sin(a1-2*a2)
num3 = -2 * sin(a1-a2)*m2
num4 = a2_v*a2_v*r2+a1_v*a1_v*r1*cos(a1-a2)
den = r1 * (2*m1+m2-(m2*cos(2*a1-2*a2)))
a1_a = (num1 + num2 + num3 * num4) / den
num1 = 2*sin(a1-a2)
num2 = a1_v*a1_v*r1*(m1+m2)
num3 = g * (m1 + m2) * cos(a1)
num4 = a2_v*a2_v*r2*m2*cos(a1-a2)
den = r2 * (2*m1+m2-m2*cos(2*a1-2*a2))
a2_a = (num1*(num2+num3+num4))/den
x1 = (r1 * sin(a1))+(gfx.width/2)
y1 = gfx.height - (r1 * cos(a1))
x2 = x1+r1 * sin(a2)
y2 = y1-r1 * cos(a2)
// Draw a line at the end of the pendulum
red = red + 1
green = green - 1
blue = blue + 2
dots.line prex2,prey2,x2,y2,color.rgb(red%220,green%220,blue%220),3
// draw the pendulum
gfx.line(gfx.width/2,gfx.height,x1,y1)
gfx.line(x1,y1,x2,y2)
prex2 = x2
prey2 = y2
a1_v = a1_a + a1_v
a2_v = a2_a + a2_v
a1 = a1_v + a1
a2 = a2_v + a2
// as momentum increases, slowly pendulum comes to rest
//a1_v = 0.999 * a1_v; // for drag
//a2_v = 0.999* a2_v; // for drag
wait 0.02
yield
end while