0% found this document useful (0 votes)
467 views7 pages

Turtle Graphics

The document discusses Turtle Graphics, which uses a relative cursor on a cartesian plane to create vector graphics, and provides code examples to draw basic shapes like a square, star, and polygon using the Turtle Graphics features in Python. Code snippets are included to import Turtle, define variables, and use loops and functions to draw the shapes by moving the turtle cursor and turning specified angles or distances.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
467 views7 pages

Turtle Graphics

The document discusses Turtle Graphics, which uses a relative cursor on a cartesian plane to create vector graphics, and provides code examples to draw basic shapes like a square, star, and polygon using the Turtle Graphics features in Python. Code snippets are included to import Turtle, define variables, and use loops and functions to draw the shapes by moving the turtle cursor and turning specified angles or distances.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

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