开发者

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

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 4 years ago.

Improve this question

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 cir开发者_如何学Pythoncle underneath that.

  • to draw a regular hexagon.

can anyone tell me how to work on it?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜