Library Turtle allows you to quickly draw a variety of shapes with uncomplicated methods. In the course of the article we will build the main character of the game Among Us.
To talk about the game Among Us, we will not, but instead tell you a bit regarding the library Turtle.
Graphics with a turtle (Turtle from English. turtle) – a popular way to introduce children to programming. Imagine a robotic turtle starting from the point (0, 0) in the x-y plane. Such a turtle is in this library. You can move it and depending on its movement to create objects of any shape.
The library has a set of very simple methods that you can use to create different patterns.
To install Turtle you’ll need a package Manager PIP that is provided along with the Python language. Create a project in any IDE, e.g. PyCharm, and then through the terminal, execute the installation of the library PythonTurtle.
For those who are on Linux, you will need to register additional commands that are presented on the page with PythonTurtle.
Below is the code in the finished application on the Turtle. If you need more information, watch our video at the end of this article.
Program code:
import turtle # Main colors for the character BODY_COLOR = ‘red’ GLASS_COLOR = ‘skyblue’ # Main object t = turtle.Turtle() # Method to draw a body def body(): t.pensize(30) # the size of the brush t.fillcolor(BODY_COLOR) # Color fill t.begin_fill() # on right t.right(90) t.forward(50) t.right(180) t.circle(40, -180) t.right(180) t.forward(200) # t Head.right(180) t.circle(100, -180) # on left t.backward(20) t.left(15) t.circle(500, -20) t.backward(20) t.circle(40, -180) t.left(7) t.backward(50) t.up() t.left(90) t.forward(10) t.right(90) t.down() t.right(240) t.circle(50, -70) t.end_fill() # Draw glass def points(): # Move the turtle t.up() t.right(230) t.forward(100) t.left(90) t.forward(20) t.right(90) t.down() # Set the color of t.fillcolor(GLASS_COLOR) t.begin_fill() t.right(150) t.circle(90, -55) t.right(180) t.forward(1) t.right(180) t.circle(10, -65) t.right(180) t.forward(110) t.right(180) t.circle(50, -190) t.right(170) t.forward(80) t.right(180) t.circle(45, -30) t.end_fill() # def Draw backpack backpack(): t.up() t.right(60) t.forward(100) t.right(90) t.forward(75) t.fillcolor(GLASS_COLOR) t.begin_fill() t.down() t.forward(30) t.right(255) t.circle(300, -30) t.right(260) t.forward(30) t.end_fill() # Calling all necessary methods body() glass() backpack() turtle.done()
A detailed analysis of Turtle you can see in the video below. In video tutorial shows the complete analysis of the library and its facilities.
Video tutorial:
On our website there is also an advanced course in the study of language Python. In the course of a huge program, you will learn not only the language Python, but also learn how to create web sites through web technologies and framework Django. During the course you will learn a lot of new and by the end of the program will be able to work with the language Python, to create a full PC-based application, Kivy library, and create websites based on the Django library.
1A Sportyvna sq, Kyiv, Ukraine 01023
2187 SW 1st St, Miami, FL 33135, USA
info@servreality.com
info@servreality.com