Created
April 13, 2024 12:47
-
-
Save CodeDrome/40ddee5f2215bd220f74ad660be7db13 to your computer and use it in GitHub Desktop.
polarplots.py part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
import math | |
def main(): | |
print("--------------------") | |
print("| codedrome.com |") | |
print("| Polar Plots with |") | |
print("| Turtle Graphics |") | |
print("--------------------\n") | |
# Uncomment this line to make drawing | |
# a lot faster or change the argument | |
# to any value. Default is 10ms. | |
#turtle.delay(0) | |
draw_axes(200) | |
#plot("circle", 120, 0, 360, circle_function) | |
#plot("cardioid", 100, 0, 360, cardioid_function) | |
#plot("spiral", 100, 0, 3600, spiral_function) | |
#plot("rose", 200, 0, 360, rose_function) | |
turtle.hideturtle() | |
# This stops the window closing after drawing is finished | |
turtle.exitonclick() | |
def draw_axes(radius): | |
""" | |
Draw lines from the origin every | |
15 degrees with the angles labelled. | |
""" | |
FONT_SIZE = 8 | |
FONT = ("Arial", FONT_SIZE, "bold") | |
width = radius * 2 + 100 | |
height = radius * 2 + 100 | |
turtle.title("Polar Plot") | |
turtle.screensize(canvwidth=width, canvheight=height) | |
turtle.setup(width=width + 40, height=height + 40) | |
turtle.shape("turtle") | |
degree_label_radius = radius + 16 | |
turtle.pencolor(0.0, 0.0, 1.0) | |
for degrees in range(0, 360, 15): | |
radians = math.radians(degrees) | |
turtle.penup() | |
turtle.home() | |
turtle.pendown() | |
turtle.goto(math.cos(radians) * radius, math.sin(radians) * radius) | |
turtle.penup() | |
turtle.goto(math.cos(radians) * degree_label_radius, | |
math.sin(radians) * degree_label_radius) | |
turtle.goto(turtle.position()[0], turtle.position()[1] - FONT_SIZE) | |
turtle.pendown() | |
turtle.write(str(degrees) + u'\u00B0', align='center', font=FONT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment