PYTHON TURTLE IS AN AMAZING LIBRARY .
Introduction
turtle is Python’s pre-installed library that enables users to create small games, animations, etc., with easy-to-understand codes.
With minimal and easy-to-understand codes that create beautiful shapes, it is a great way for kids to start their coding journey
Get started with turtle
1. Import the module
turtle is a pre-installed library in Python; therefore, we don’t need to install it explicitly.
The turtle module and its methods can be used in a program once it is imported into your Python environment, which can be done as follows:
```
import turtle
```
2.Create a canvas
Since turtle will perform graphic actions, it requires a canvas or separate workspace area to act on our commands. The turtle canvas or screen can be initialized, as shown below:
```
screen=turtle.Screen()
```
3. Create a turtle
We need a turtle to perform actions on the canvas. turtle object is instantiated by the creation of an object of the Turtle class defined in the turtle module.
The turtle object is created as follows:
```
t=turtle.Turtle()
```
CODE AS FOLLOWS:
import turtle
col=['yellow','red','green','blue','white','orange']
t=turtle.Turtle()
screen=turtle.Screen()
screen.bgcolor('black')
t.speed(30)
for i in range(100):
t.color(col[i%6])
t.forward(i*4)
t.left(150)
t.width(1)
Oldest comments (0)