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

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

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

  • to draw a regular hexagon.

Can someone tell me how to work on this?

+4
source share
2 answers

As I said, this can be a homework problem to help you learn programming. Here are some useful resources to get you started: Presentation and slides on the turtles module by Gregor Lingle and turtle . After completing both, you will be able to complete your tasks.

+4
source

A good way to do this is to define a circle with parameters and just use what you want. Also, since the hexagon is repeated, you can use the for loop to build many sides for it. This 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 () 

In this case, you do not need to save the definition of the circle and just add your own parameters, and hexigon can be easily executed using the for loop.

+1
source

Source: https://habr.com/ru/post/1336654/


All Articles