Turtle Graphics

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

Turtle Graphics

By Abdullah Kashif
What is python?
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics developed by Guido
van Rossum. It was originally released in 1991. Designed to be easy as well as fun, the name "Python" is a nod to the
British comedy group Monty Python.
What are “Turtle Graphics”?
• In computer graphics, turtle
graphics are vector graphics using a
relative cursor (the “turtle") upon a
cartesian plane (x and y axis). Turtle
graphics is a key feature of the Logo
programming language.
Square
Turtle Graphics can be used to make significant numbers of shapes or designs,
Though we can start off simple with a square
The code to a “Square”
• The first text “import turtle” commands the system to
import the “turtle graphics” system
• “skk” is a variable and can be changed into anything, it
defines that the variable “skk” means “turtle.Turtle()”
which is an easier shortcut
• For eg: “skk.right(90)” makes turtle (the cursor) move
90 degrees to the right and “skk.forward(50)”
commands the turtle to move 50 pixels ahead
• “for i in range” means ‘for each item in the list’ (the
skk.right and skk.forward) and the number 4 means to
repeat the the items in the list 4 times
• “Turtle.done()” is used at the end to execute one
command, and code Infront of it wouldn’t affect the
square
The code to a “Star”
• We start by the code import turtle to add “turtle graphics” to
the system
• The name for the variable is ‘star’
• We first indicate the star to go right by an angle of ’75’ and
then forward by ‘100’, this makes the base of the star
• After that we use the “for i in range(4)” command for the star
to go right on an angle of ‘144’ and forward at ‘100’ for ’4’
times in a row
• Then we execute the command after writing “turtle.done()”
The code to a “Polygon”
• We yet again start with importing the turtle graphics
system and set the variable as “polygon”
• We then create three different variables for the number
of sides (num_sides = 6), length of sides (side_length =
70) and the angle, which will be divided by the number of
sides because it’s a polygon (angle = 360.0 / num_sides)
• We then run the command “for i in range”, we can either
use the variable for the number of sides or the number of
sides itself (6). We use the “side_length” to go forward
and “angle” (divided by sides) for each turn taken
• We then execute the command

You might also like