Python Turtle Graphics Tutorial: How to Draw a Filled Hexagon

Опубликовано: 29 Май 2023
на канале: 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:


На этой странице сайта вы можете посмотреть видео онлайн Python Turtle Graphics Tutorial: How to Draw a Filled Hexagon длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Komaravolu Ratanvir 29 Май 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 11 раз и оно понравилось 0 зрителям. Приятного просмотра!