Files
lab_turtle/drawing.py
tgaeta ab15c33de7 I made a cardioid by making use of the goto func.
I had a lot of fun with this lab. Because I have experience with math and writing code, I was able to make a fun drawing without much stress.
2025-09-03 09:55:19 -04:00

29 lines
652 B
Python

from turtle import (
right,
color,
goto,
pensize
)
from math import sin, cos, tau, pi
def cardioid(theta, size=100):
return size * (1 - sin(theta))
def polar_to_cartesian(coord: tuple[float, float]):
r, theta = coord
return (r * cos(theta), r * sin(theta))
def get_segmented_cardioid(segments = 16):
angles = [pi / 2 + i * (tau/ segments) for i in range(segments + 1)]
radii = map(cardioid, angles)
return list(map(polar_to_cartesian, zip(radii, angles)))
segments = 50
coords = get_segmented_cardioid(segments)
color(1, 0, 0)
pensize(5)
for i in range(segments + 1):
goto(coords[i])
right(90)
input()