def setup(): size(900, 450) def draw(): t = 0.01*frameCount xsun = 0.5*width ysun = 0.5*height # clear screen before each new frame background(128) # draw sun ellipse(xsun, ysun, 20, 20) rplanet = 200 xplanet = xsun + rplanet*cos(t) yplanet = ysun + rplanet*sin(t) # draw planet ellipse(xplanet, yplanet, 10, 10) rmoon = 30 xmoon = xplanet + rmoon*cos(t*365/27.3) ymoon = yplanet + rmoon*sin(t*365/27.3) # draw moon ellipse(xmoon, ymoon, 5, 5) # add second planet year_mercury_days = 115.88 # from Wikipedia T_ratio = year_mercury_days/365.25 R_ratio = T_ratio**(2.0/3) xplanet = xsun + R_ratio*rplanet*cos(t/T_ratio) yplanet = ysun + R_ratio*rplanet*sin(t/T_ratio) ellipse(xplanet, yplanet, 7, 7)