Colorful spiral design using Turtle Python
Hi everyone,
In this blog you would learn how you can create a colorful spiral design
through coding using Turtle module in python programming language. Though their
are many module in python. Each module have its own specialty. One such module
is turtle module through which we can create different types of designs in both
object-oriented and procedure-oriented ways.
If you want to create beautiful design using python follow these steps:
1) Install python3 in your computer(laptop, or any devices).
You can install through website. Click to download python3
2) After python is install in your system. You need to install editor. Python
has inbuilt editor by the name IDLE, but for doing the programming in more
easier and comfortable manner you need to install editor. Their are many
editors available in the internet like Pycharm, sublime, visual studio etc.
Choose Pycharm which is best for python.
For installation of Pycharm editor. Click here to download pycharm
3) After installation of Pycharm editor (any editor). Open a new project and
create an file by the name design.py.
4) Open the file. Now you need to install the turtle module. To install the turtle
module use the command in terminal window:
# install turtle module
pip install turtle
In python3 the turtle is pre-installed. So their is no need to install it again.
If you want more details about turtle module :- Click here
Now You will have he window in this way:-
Let's get into the code:-
1) At first we need to import turtle module
#importing turtle module
import turtle
2) Now we need to add colors:
# defining colors
colors = ['red', 'yellow', 'green', 'purple', 'blue', 'orange']
3) Now you need to setup turtle pen:
#setup turtle pen
t = turtle.Pen()
4) Now for changing the speed of the turtle pen we should use speed command:
# changes the speed of the the turtle
t.speed(10)
5) Now you need to choose your background color.
# background color
turtle.bgcolor("black")
6) Now you need write the main loop:
# make spiral web
for x in range(200):
t.pencolor(colors[x % 6]) #setting color
t.width(x/100 + 1) #setting width
t.forward(x) #moving forward
t.left(59) #moving left
7) end of the programming write:
turtle.done()
8) Now for run the program use ctrl + shift + f10. or click on run button.
9) Full code:
# importing turtle module
import turtle
# defining colors
colors = ['red', 'yellow', 'green', 'purple', 'blue', 'orange']
#setup turtle pen
t = turtle.Pen()
# changes the speed of the the turtle
t.speed(10)
# background color
turtle.bgcolor("black")
# make spiral web
for x in range(200):
t.pencolor(colors[x % 6]) # setting color
t.width(x / 100 + 1) # setting width
t.forward(x) # moving forward
t.left(59) # moving left
turtle.done()
RESULT:-
----------------------------------------------------------------------------------------------------
In The similar manner another design is: (PART-2)
The full code for design PART -2 is:
import turtle
turtle.setup(width= 900, height= 600)
turtle.reset()
turtle.hideturtle()
turtle.speed(0)
turtle.bgcolor('black')
c = 0
x = 0
colors = [
#reddish color
(1.00, 0.00, 0.00),(1.00, 0.03, 0.00),(1.00, 0.05, 0.00),(1.00, 0.07, 0.00),(1.00, 0.10, 0.00),(1.00, 0.12, 0.00),
(1.00, 0.15, 0.00),(1.00, 0.17, 0.00),(1.00, 0.20, 0.00),(1.00, 0.23, 0.00),(1.00, 0.25, 0.00),(1.00, 0.28, 0.00),
(1.00, 0.30, 0.00),(1.00, 0.33, 0.00),(1.00, 0.35, 0.00),(1.00, 0.38, 0.00),(1.00, 0.40, 0.00),(1.00, 0.42, 0.00),
(1.00, 0.45, 0.00),(1.00, 0.47, 0.00),
#orange colors
(1.00, 0.50, 0.00),(1.00, 0.53, 0.00),(1.00, 0.55, 0.00),(1.00, 0.57, 0.00),(1.00, 0.60, 0.00),(1.00, 0.62, 0.00),
(1.00, 0.65, 0.00),(1.00, 0.68, 0.00),(1.00, 0.70, 0.00),(1.00, 0.72, 0.00),(1.00, 0.75, 0.00),(1.00, 0.78, 0.00),
(1.00, 0.80, 0.00),(1.00, 0.82, 0.00),(1.00, 0.85, 0.00),(1.00, 0.88, 0.00),(1.00, 0.90, 0.00),(1.00, 0.93, 0.00),
(1.00, 0.95, 0.00),(1.00, 0.97, 0.00),
#yellow colors
(1.00, 1.00, 0.00),(0.95, 1.00, 0.00),(0.90, 1.00, 0.00),(0.85, 1.00, 0.00),(0.80, 1.00, 0.00),(0.75, 1.00, 0.00),
(0.70, 1.00, 0.00),(0.65, 1.00, 0.00),(0.60, 1.00, 0.00),(0.55, 1.00, 0.00),(0.50, 1.00, 0.00),(0.45, 1.00, 0.00),
(0.40, 1.00, 0.00),(0.35, 1.00, 0.00),(0.30, 1.00, 0.00),(0.25, 1.00, 0.00),(0.20, 1.00, 0.00),(0.15, 1.00, 0.00),
(0.10, 1.00, 0.00),(0.05, 1.00, 0.00),
#greenish colors
(0.00, 1.00, 0.00),(0.00, 0.95, 0.05),(0.00, 0.90, 0.10),(0.00, 0.85, 0.15),(0.00, 0.80, 0.20),(0.00, 0.75, 0.25),
(0.00, 0.70, 0.30),(0.00, 0.65, 0.35),(0.00, 0.60, 0.40),(0.00, 0.55, 0.45),(0.00, 0.50, 0.50),(0.00, 0.45, 0.55),
(0.00, 0.40, 0.60),(0.00, 0.35, 0.65),(0.00, 0.30, 0.70),(0.00, 0.25, 0.75),(0.00, 0.20, 0.80),(0.00, 0.15, 0.85),
(0.00, 0.10, 0.90),(0.00, 0.05, 0.95),
# blueish colors
(0.00, 0.00, 1.00),(0.05, 0.00, 1.00),(0.10, 0.00, 1.00),(0.15, 0.00, 1.00),(0.20, 0.00, 1.00),(0.25, 0.00, 1.00),
(0.30, 0.00, 1.00),(0.35, 0.00, 1.00),(0.40, 0.00, 1.00),(0.45, 0.00, 1.00),(0.50, 0.00, 1.00),(0.55, 0.00, 1.00),
(0.60, 0.00, 1.00),(0.65, 0.00, 1.00),(0.70, 0.00, 1.00),(0.75, 0.00, 1.00),(0.80, 0.00, 1.00),(0.85, 0.00, 1.00),
(0.90, 0.00, 1.00),(0.95, 0.00, 1.00),
]
while x< 1000:
idx = int(c)
color = colors[idx]
turtle.color(color)
turtle.forward(x)
turtle.right(98)
x = x+1
c = c+ 0.1
turtle.exitonclick()
RESULT :-
---------------------------------------------------------------------------------------------------------------
If you have interesting in learning new things then follow our blogs.
Also you can follow us in
youtube :- Youtube
telegram:- Telegram
-----------------------------------------------------------------------------------------------------
Please share and follow our blog:
If you have any quries please comment me below. comment box
0 Comments