Draw Cube and Cuboid in Python using Turtle

Prerequisite: Turtle Programming Basics

Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move the turtle, there are some functions i.e forward(), backward(), etc.

Drawing Cube

Following steps are used:

  • First draw the front square
  • Move to back square through one bottom left side
  • Draw the back square
  • Draw the remaining side as shown in code.

Below is the implementation.

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

#import the turtle modules 
import turtle 
  
# Forming the window screen
tut = turtle.Screen()
  
# background color green
tut.bgcolor("green")
  
# window title Turtle
tut.title("Turtle")
my_pen = turtle.Turtle()
  
# object color
my_pen.color("orange")
tut = turtle.Screen()           
  
# forming front square face
for i in range(4):
    my_pen.forward(100)
    my_pen.left(90)
  
# bottom left side
my_pen.goto(50,50)
  
# forming back square face
for i in range(4):
    my_pen.forward(100)
    my_pen.left(90)
  
# bottom right side
my_pen.goto(150,50)
my_pen.goto(100,0)
  
# top right side
my_pen.goto(100,100)
my_pen.goto(150,150)
  
# top left side
my_pen.goto(50,150)
my_pen.goto(0,100)

chevron_right


Output :

Drawing Cuboid

Following steps are used:

  • First draw the front rectangle
  • Move to back rectangle through one bottom left side
  • Draw the back rectangle
  • Draw the remaining side as shown in code.

Below is the implementation.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

#import the turtle modules 
import turtle 
  
# Forming the window screen
tut = turtle.Screen()
  
# background color green
tut.bgcolor("green")
  
# window title Turtle
tut.title("Turtle")
my_pen = turtle.Turtle()
  
# object color
my_pen.color("orange")
tut=turtle.Screen()           
  
# forming front rectangle face
for i in range(2):
    my_pen.forward(100)
    my_pen.left(90)
    my_pen.forward(150)
    my_pen.left(90)
  
# bottom left side
my_pen.goto(50,50)
  
# forming back rectangle face
for i in range(2):
    my_pen.forward(100)
    my_pen.left(90)
    my_pen.forward(150)
    my_pen.left(90)
  
# bottom right side
my_pen.goto(150,50)
my_pen.goto(100,0)
  
# top right side
my_pen.goto(100,150)
my_pen.goto(150,200)
  
# top left side
my_pen.goto(50,200)
my_pen.goto(0,150)

chevron_right


Output :




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.