What is Turtle in Python
Turtle is like a drawing board in Python, which lets us command a turtle to draw over where we have insisted the direction like forward(), backward(), etc.
How to use Turtle
1. We need to import the "Turtle" package
2. We have to create a turtle where we need to control
3. Give direction to draw around using the turtle methods
4. Finally, run turtle.done()
Note:
You can install these libraries using pip command.
Turtle is pre-installed in mostly all programming software if Turtle is not installed please use this pip command pip install PythonTurtle
Source code
import turtle
def draw_circle(pen):
# outer circle
pen.setposition(0, -280)
pen.pendown()
pen.begin_fill()
pen.color('red')
pen.pencolor('white')
pen.circle(300)
pen.end_fill()
pen.penup()
def draw_circle2(pen):
# inner circle
pen.pensize(2)
pen.setposition(0, -230)
pen.pendown()
pen.begin_fill()
pen.color('black')
pen.circle(250)
pen.end_fill()
pen.penup()
def draw_A(pen):
# drawing ‘A’
pen.setposition(30, -110)
pen.pendown()
pen.begin_fill()
pen.color('red')
pen.pensize(10)
pen.pencolor('white')
pen.forward(23)
pen.backward(123)
pen.left(60)
pen.backward(220)
pen.right(60)
pen.backward(100)
pen.right(117)
pen.backward(710)
pen.right(63)
pen.backward(110)
pen.right(90)
pen.backward(510)
pen.right(90)
pen.backward(100)
pen.right(90)
pen.backward(70)
pen.end_fill()
pen.penup()
def draw_triangle(pen):
# Triangle shape in ‘A’ to make it look like 2d
pen.pensize(10)
pen.setposition(53, -40)
pen.pendown()
pen.begin_fill()
pen.color('black')
pen.pencolor('white')
pen.right(90)
pen.forward(100)
pen.right(115)
pen.forward(250)
pen.right(157)
pen.forward(227)
pen.end_fill()
def draw_arrow(pen):
# arrow
pen.backward(80)
pen.left(42)
pen.forward(147)
pen.right(83)
pen.forward(140)
if __name__ == '__main__':
win = turtle.Screen()
win.bgcolor('black')
avengers = turtle.Turtle()
avengers.speed(10)
avengers.pensize(10)
avengers.penup()
draw_circle(avengers)
draw_circle2(avengers)
draw_A(avengers)
draw_triangle(avengers)
draw_arrow(avengers)
avengers.penup()
avengers.setposition(300,300)
avengers.pencolor("red")
avengers.write("Code by MM4Tech")
avengers.hideturtle()
turtle.done() (code-box)
Output
Video Tutorial