Python Turtle Graphics Tutorial: How to Draw a Filled Hexagon

Publicado em: 29 Maio 2023
no canal de: Komaravolu Ratanvir
11
0

This Python code uses the Turtle graphics library to draw a hexagon of a given size, filled with the color violet. Here is a brief explanation of the code:

First, the Turtle graphics library is imported.

A new screen is created with a title of 'Hexagon' and a size of 500x500 pixels.

A function called draw_hexagon is defined, which takes two parameters: a turtle object and a size value. The function uses a for loop to draw a hexagon with six sides of the given size.

The background color of the window is set to light grey.

A new turtle object is created.

The fill color of the turtle is set to violet.

The turtle is moved to the starting position (-50, -50) using the penup() and goto() methods.

The turtle begins filling in the hexagon using the begin_fill() method.

The draw_hexagon() function is called with the turtle object and a size of 100.

The turtle ends filling in the hexagon using the end_fill() method.

The Turtle window stays open until the user closes it by calling the turtle.done() function.

When you run this code, a new window will open with a hexagon of size 100 pixels, filled with violet color. The turtle object will move in a clockwise direction to draw the six sides of the hexagon, with each side being of equal length.

.py file:


Nesta página do site você pode assistir ao vídeo on-line Python Turtle Graphics Tutorial: How to Draw a Filled Hexagon duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Komaravolu Ratanvir 29 Maio 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 11 vezes e gostou 0 espectadores. Boa visualização!