Drawing Your Own Pikachu with Python
Do you remember the thrill of collecting and trading Pokémon cards as a child? Or the excitement of watching the anime and summoning your favorite Pokémon with your friends? Recently, the movie “Sherlock Pikachu” has brought back those nostalgic memories, and we’re going to explore how to bring our own Pikachu to life using Python.
The Dream of a Pikachu
In the world of Pokémon, Pikachu is known for its adorable appearance and unique ability to store and discharge electricity. In the cartoon, Pikachu is depicted as a shy and intelligent character, but it’s also shown to be a bit of a troublemaker when it comes to its electrical discharges. As we grow up, we may forget our childhood dreams, but with Python, we can bring them back to life.
Using Turtle Graphics
Turtle graphics is a powerful module in Python that allows us to create simple drawings and animations. It’s based on the Tkinter module and provides a simple and intuitive way to create graphics. Imagine a small turtle crawling on the computer screen, leaving a trail of lines behind it. That’s what turtle graphics is all about.
Basic Idea
To draw our own Pikachu, we need to choose the right size drawing board, set the brush color, thickness, and location. Then, we can start drawing the different parts of the Pikachu, such as the nose, head, ears, eyes, mouth, body, hands, feet, and tail.
Code Example
Here’s a code example that shows how to use turtle graphics to draw a Pikachu:
import turtle as t
def infoPrt():
print('coordinate:' + str(t.pos()))
print('angle:' + str(t.heading()))
t.pensize(3)
t.hideturtle()
t.colormode(255)
t.color("black")
t.setup(700, 650)
t.speed(10)
t.st()
# Draw head
t.seth(85)
t.circle(-100, 50)
# Draw body
t.seth(25)
t.circle(-170, 50)
# Draw right ear
t.seth(40)
t.circle(-250, 30)
# Draw right ear tip
t.seth(227)
t.circle(-270, 15)
# Draw tail
t.pu()
t.setpos(p_tail)
t.pd()
t.begin_fill()
t.seth(50)
t.fd(25)
t.seth(-50)
t.fd(30)
p_tail1 = t.pos()
t.seth(-140)
t.fd(36)
t.end_fill()
t.seth(39)
t.fd(72)
t.seth(125)
t.fd(48)
t.seth(40)
t.fd(53)
t.seth(88)
t.fd(45)
t.seth(35)
t.fd(105)
t.seth(105)
t.circle(850, 8)
t.seth(215)
t.fd(125)
t.circle(850, 11)
t.seth(280)
t.fd(110)
t.seth(220)
t.fd(50)
t.seth(309)
t.fd(56)
This code uses turtle graphics to draw a Pikachu with a head, body, right ear, right ear tip, and tail. Note that this is just a simplified example, and there are many ways to improve and customize the drawing.
Conclusion
Drawing your own Pikachu with Python is a fun and creative project that can help you learn about turtle graphics and Python programming. With this code example, you can start experimenting with different shapes and designs to create your own Pikachu. Remember to keep it simple and have fun!
References
Note: This article was originally published on Big Data Digest, a popular Chinese technical blog.