In this article, you will learn how to Drawing Pikachu with the Python turtle library.
What is Turtle?
Turtle is a pre-installed Python library. It enables users to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that you use for drawing is called as turtle.
The turtle has three attributes: a location, an orientation (or direction), and a pen.
Moving the Turtle Head
The turtle can move in four directions:
To know more about it, you can refer to Turtle Documentation. Use this link to navigate to the documentation.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
In order to access the Python library, you need to import it into your Python environment, use the following command to import
turtle it in your python script.
Starting out, let’s create an instance of Screen.
wn = turtle.Screen()
Now, create an instance of Turtle.
self.t = turtle.Turtle()
- Let’s set the speed as
speedmethod, that means the pikachu will not just appear on the screen, the drawing will have some animation.
- If you wish to change the background color, you can use the
bgcolormethod, by default it is white.
- You can adjust the pen’s thickness using
pensizemethod, it will be slightly bold.
- ondrag dragging the Turtle will move it across the screen thereby producing handdrawings (if pen is down).
t.pensize(3) t.speed(9) t.ondrag(getPosition)
Now let’s see some common methods used in this program:
- Turtle(): Used to create and return a new turtle object.
- forward(value): With respect to the value specified, the turtle moves forward.
- backward(value): With respect to the value specified, the turtle moves backwards.
- right(angle): Clockwise turn of the turtle.
- left(angle): Counterclockwise turn of the turtle.
- penup(): Turtle pen is picked up.
- pendown(): Turtle pen put down.
- up(): Same as penup ().
- down(): same as pendown ().
- color(color name): Turtle pen’s color is changed.
- fillcolor(color name): Color used to fill a particular shape is changed.
- heading(): Current heading is returned.
- position(): Current position is returned.
- goto(x, y): Moves position of turtle to coordinates x, y.
- end_fill(): Current fill color is filled after closing the polygon.
- begin_fill(): The starting point is remembered for a filled polygon.
- dot(): Dot is left at the current position.
- stamp(): Impression of turtle shape is left at the current position.
- Shape(): Should be – ‘turtle’, ‘classic‘, ‘arrow‘ or ‘circle‘.
Source Code with Comments- Drawing Pikachu with the Python turtle library
Output of code , When you run the code !
So, Here is our Pikachu with the Python turtle. Simple isn’t it?? This is how we have successfully done with the ‘Drawing Pikachu with the Python turtle library’. I hope the Turtle library is now more clear to you and don’t forget to try this code once!!
You can play around with the library, explore more features and even customize it further.
Check out more python projects
- PYTHON ROCK PAPER SCISSORS GAME
- CURRENCY CONVERTER IN PYTHON
- COVID-19 TRACKER APPLICATION USING PYTHON