Draw the spiral with hexagon shape using Turtle module of Python. In each loop, increases the forward length.
In this tutorial, we will learn that how to draw hexagon spirals using Turtle Graphics in Python.
Turtle is a python feature like a drawing board. We can use many turtle functions which can move the turtle around. Turtle comes in the turtle library. The Turtle module can be used in both object-oriented and procedure-oriented.
let's start the code:
First, you have to import the turtle module.
from turtle import *
Then you decide which colors you want in that spiral. So, assign that six specific colors to the variable color.
colors = ['pink', 'green', 'orange', 'yellow', 'blue', 'brown', 'white']
After that you have set the speed.
speed(0)
Then assign the background color using bgcolor().
bgcolor('black')
Now, we are defining one for loop here.
for x in range(200): pencolor(colors[x % 6]) width(2) forward(x*1.2) left(59)
for loop for hexagon executes 200 times.
After every move of the turtle, it changes the color.
In every iteration, the turtle moves 90 units forward and 59 degrees in left.
Let's see the whole source code.
from turtle import * colors = ['pink', 'green', 'orange', 'yellow', 'blue', 'brown', 'white'] speed(0) bgcolor('black') for x in range(200): pencolor(colors[x % 7]) width(2) forward(x*1.2) left(59)
Output:
Submitted by Anita Suresh Lawate (Anitacodespeedy)
Download packets of source code on Coders Packet
Comments