How to draw a circle and a hexagon with the turtle module?

14,146

A good way to go about this is to define a circle with parameters and just use what you want. Also since a hexagon is repetitive, you can use a for loop to construct a lot of the sides for it. Here is how I solved it.

from turtle import *
setup()
x = 200
# Use your own value
y = 200
# Use your own value

def circles (radius, colour):
    penup()
    pencolor (colour)
    goto (0,radius)
    pendown ()
    setheading (180)
    circle (radius)
    penup()


circles (100, "red")
circles (50, "yellow")
circles (25, "green")

def hexagon (size_length):
    pendown ()
    forward(size_length)
    right (60)

goto (x, y) 
for _ in range (6):
    hexagon (50)             

exitonclick ()

With this you don't have to keep defining circle and just add your own parameters and the hexigon can be easily done with a for loop.

Share:
14,146
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I want to use the turtle module and I want to do :

    • Draw a red circle, then a yellow circle underneath it and a green circle underneath that.

    • to draw a regular hexagon.

    can anyone tell me how to work on it?