Drawing Olympics and Audi logo with Python Turtle Module

Introduction

The Logo programming language is frequently linked to turtle graphics. In the late 1960s, Seymour Papert added turtle graphics support to Logo to support his version of the turtle robot, which is a simple robot controlled from the user’s workstation and designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot’s body.

The standard library of the Python programming language now contains a Turtle graphics module. Turtle in Python, like its Logo ancestor, allows programmers to manipulate one or more turtles in a two-dimensional space.

Overview of the syntax

A location, an orientation (or direction), and a pen are the three qualities of the turtle. Color, width, and on/off state are all properties of the pen (also called down and up).

“Move ahead 10 spaces” and “turn left 90 degrees” are orders that the turtle responds to based on its current location. The turtle’s pen can also be managed by enabling it, changing its color, and adjusting its breadth. By visualizing what they would do if they were the turtle, a pupil may comprehend (and forecast and reason about) the turtle’s motion. This is referred to as “body syntonic” reasoning by Seymour Papert.

Basic syntax:

import turtle // start of the program
     //body
    //of the main
   //code
turtle.done() //end of the program

Inorder to understand the codes to draw various shapes given below, Getting Started with Powerful yet Easy Python Graphics Module, Turtle.

Methods

A Python method is a label that can be applied to an object and is a piece of code that may be run on that object.

The most frequently, used turtle methods are:

MethodParameterDescription
Turtle()NoneCreates and returns a new turtle object
forward()amountMoves the turtle forward by the specified amount
backward()amountMoves the turtle backward by the specified amount
right()angleTurns the turtle clockwise
left()angleTurns the turtle counterclockwise
penup()NonePicks up the turtle’s Pen
pendown()NonePuts down the turtle’s Pen
up()NonePicks up the turtle’s Pen
down()NonePuts down the turtle’s Pen
color()Color nameChanges the color of the turtle’s pen
fillcolor()Color nameChanges the color of the turtle will use to fill a polygon
heading()NoneReturns the current heading
position()NoneReturns the current position
goto()x, yMove the turtle to position x,y
begin_fill()NoneRemember the starting point for a filled polygon
end_fill()NoneClose the polygon and fill with the current fill color
dot()NoneLeave the dot at the current position
stamp()NoneLeaves an impression of a turtle shape at the current location
shape()shapenameShould be ‘arrow’, ‘classic’, ‘turtle’ or ‘circle’

Five interlaced rings in the colors blue, black, red, yellow, and green make up the Olympic logo. The core concept of drawing it is to use the goto() and circle() functions in the correct order.

Method 1

import turtle
  
tom = turtle.Turtle()
  
tom.pensize(5)

tom.color("blue")
tom.penup()
tom.goto(-110, -25)
tom.pendown()
tom.circle(45)

tom.color("black")
tom.penup()
tom.goto(0, -25)
tom.pendown()
tom.circle(45)

tom.color("red")
tom.penup()
tom.goto(110, -25)
tom.pendown()
tom.circle(45)

tom.color("yellow")
tom.penup()
tom.goto(-55, -75)
tom.pendown()
tom.circle(45)

tom.color("green")
tom.penup()
tom.goto(55, -75)
tom.pendown()
tom.circle(45)

turtle.done()

Method 2

import turtle
 
tom= turtle.Turtle()
tom.pensize(6)
firstRowColors = ["blue", "black", "red"]
for i in range(3):
  tom.penup()
  tom.pencolor(firstRowColors[i])
  tom.goto(i*110, 0)
  tom.pendown()
  tom.circle(50)
 
secondRowColors = ["", "yellow", "", "green"]
for i in range(1, 4, 2):
  tom.penup()
  tom.pencolor(secondRowColors[i])
  tom.goto(i*55, -50)
  tom.pendown()
  tom.circle(50)

turtle.done()

Output

Just like the Olympics Logo the Audi Logo has interlaced rings. But it only has one row consisting of four rings. All the four rings being black in color.

import turtle
 
tom = turtle.Turtle()
tom.pensize(4)
 
for i in range(4):
  tom.penup()
  tom.goto(i*70, 0)
  tom.pendown()
  tom.circle(50)

turtle.done()

Output

SHARE Drawing Olympics and Audi logo with Python Turtle Module

You may also like...

Leave a Reply

Your email address will not be published.

Share