Draw Spiral Hexagon In Python Using Turtle
In this tutorial I will show you how to draw Spiral Hexagon using python, we will use the turtle module to create this program in python, turtle is a GUI library with the help of this library you can draw anything in python.
Python Code To Draw Spiral Hexagon
import turtle colors = ["cyan","yellow","blue","green","white","red"] p = turtle.Pen() turtle.bgcolor("black") for i in range(300): p.pencolor(colors[i%6]) p.width(i/100+2) p.forward(i) p.left(59)
Above is the code for drawing Spiral Hexagon, this program is entirely created using turtle functions so let’s see how they work:
- The code begins by importing the turtle module.
- A list named ‘colors’ is created, containing six different colors.
- A turtle object named ‘p’ is created.
- The background color of the turtle screen is set to black using
- A loop is initiated, which will iterate 300 times.
- Inside the loop, the pen color of the turtle is set based on the current iteration using
p.pencolor()and the modulo operator (%).
- The width of the pen is adjusted based on the current iteration using
- The turtle moves forward by a distance equal to the current iteration using
- The turtle turns left by an angle of 59 degrees using
- The loop continues, and the turtle creates a spiral pattern by repeating steps 6-9.
Above was a short explaination of the code so now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer or else you can use this online python compiler.
When you run the program and it will open a new window and it will start drawing Spiral Hexagon and below is the finished drawing of beautiful spiral hexagon.
As you can see, we successfully drew a colourful Spiral Hexagon in python, I hope you were able to run this program successfully.
Here are some more python drawing tutorials for you:
- Draw Pikachu using python with code.
- Draw doraemon using python turtle.
- Draw shinchan using python turtle.
- Draw I love you using python turtle.
- Draw Batman logo using python turtle.
- Draw Google Logo using python turtle.
- Make a python calculator using turtle.
- Draw christmas tree using python.
- Draw spiderman in python programming.
- Draw Python Logo Using Python.
- Draw Iron Man using python turtle with code.
- Draw A Heart Using python turtle with code.
- Draw car in python turtle with code.
- Draw a Cat In Python Turtle With Code.
- Draw Panda In Python Turtle With Code.
- Draw Netflix Logo Using Python Turtle.
- Draw Whatsapp Logo Using Python Turtle.
- Draw Windows Logo Using Python.
- Draw Apple Logo Using Python Turtle.
- Draw YouTube Logo Using Python Turtle.
- Draw India Map In Python Turtle.
- Draw Snapchat Logo Using Python Turtle.
- Draw TikTok Logo Using Python.
- Draw Instagram Logo Using Python Turtle.
I hope you found what you were looking for from this tutorial, and if you want more python guides and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂