Skip to content

Instantly share code, notes, and snippets.

@edward70
Created December 31, 2022 05:25
Show Gist options
  • Save edward70/2a3997c3c8fe8ec5c98e5277f5503760 to your computer and use it in GitHub Desktop.
Save edward70/2a3997c3c8fe8ec5c98e5277f5503760 to your computer and use it in GitHub Desktop.
Working implementation of limacon rendering using turtle
from turtle import *
from math import pi,cos
color('blue', 'green')
#speedup
speed(0)
delay(0)
tracer(0,0)
penup()
def get_pos(i, t): # get position for each line draw step
b = 1/30 * i
a = 1 - (1/30 * i)
r = b - a * cos(t*pi/180)
r *= 200
penup()
left(t-90) # rotate 90 deg clockwise
forward(r)
pos_save = pos()
home()
return pos_save
for i in range(1,31): # 30 curves
oldpos = get_pos(i,0)
for t in range(91): # 90 steps per curve (t varies from 0 to 2pi)
t*=4 # convert to 360deg
newpos = get_pos(i,t)
goto(oldpos)
pendown()
goto(newpos)
penup()
oldpos = newpos
home()
hideturtle()
update() # draw all at once
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment