Drawing Circle with Squares

I am currently going through “Foundations of Python” Course on Udacity and they got an interesting an assignment to draw circles with the Turtle package.

import turtle

def draw_square(myTurtle, length):
    for i in range(1, 5):
        myTurtle.forward(length)
        myTurtle.right(90)

def draw_circle_with_square(myTurtle, radius):
    numSquares = 30
    angleOfRotation = 360/numSquares
    
    for i in range(1, numSquares + 1):
        myTurtle.right(angleOfRotation)
        draw_square(myTurtle, radius)

canvas = turtle.Screen()
pacman = turtle.Turtle()
pacman.shape("turtle")
pacman.shapesize(0.1, 0.1, 0.1)
pacman.color("red")
canvas.bgcolor("yellow")

draw_circle_with_square(pacman, 100)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s