Create a Basketball Ground Using Turtle Library in Python
Last Updated :
21 Mar, 2024
We have the task of how to make basketball ground using Turtle graphics in Python and print the ground. In this article, we will see how to create a basketball ground using Python Turtle Library.
Create a Basketball Ground Using Python Turtle
Below, is the Implementation of Basketball using the Turtle library in Python:
Step 1: Setting up the Environment
In the below code, the turtle module is imported, and a screen is created with a specified background color and size.
Python3
import turtle
screen = turtle.Screen()
screen.bgcolor("#eb8c34")
screen.setup(width=1357, height=760)
Step 2: Drawing the Background Rectangle
Below, code creare a turtle named 't' and hides it, preparing it for drawing. It then moves the turtle backward by 500 units and shifts it 200 units to the left. After setting the pen size to 7 and showing the turtle, it fills a rectangle with a white outline and blue interior.
Python3
t = turtle.Turtle()
t.hideturtle()
t.penup()
t.backward(500)
t.left(90)
t.forward(200)
t.right(90)
t.pensize(7)
t.pendown()
t.pencolor("white")
t.fillcolor("blue")
t.begin_fill()
t.forward(1000)
t.right(90)
t.forward(500)
t.right(90)
t.forward(1000)
t.right(90)
t.forward(500)
t.end_fill()
Step 3: Drawing the Left Half of the Roof
Below, code lifts the pen, moves the turtle backward by 450 units, and turns it to the right by 90 degrees. Then, it places the pen down and draws a semicircle with a radius of 200 units. The turtle then turns left by 90 degrees and draws a red trapezoid.
Python3
t.penup()
t.backward(450)
t.right(90)
t.pendown()
t.circle(200, 180)
t.left(90)
t.forward(150)
t.left(90)
t.fillcolor("#ed2d05")
t.begin_fill()
t.forward(150)
t.circle(-40)
t.right(90)
t.forward(80)
t.right(90)
t.forward(150)
t.end_fill()
Step 4: Drawing the Chimney
Below, code lifts the pen, turns the turtle to the right by 90 degrees, and moves it forward by 70 units. Then, it turns the turtle to the right by 90 degrees again and moves it forward by 30 units. After placing the pen down, it turns the turtle to the right by 90 degrees and finally moves forward by another 30 units.
Python3
t.penup()
t.right(90)
t.forward(70)
t.right(90)
t.forward(30)
t.pendown()
t.right(90)
t.forward(30)
t.circle(10)
t.forward(30)
Step 5: Drawing the Right Half of the Roof
In below code lifts the pen, turns the turtle right by 90 degrees, and moves it 30 units forward. Then, it positions the turtle to draw a rectangle by moving it 271 units forward, then 500 units while turning right 90 degrees each time. After drawing a 500-unit line, it lifts the pen, moves the turtle left 90 degrees and forward 500 units.
Python3
t.penup()
t.right(90)
t.forward(30)
t.right(90)
t.forward(271)
t.right(90)
t.forward(500)
t.right(90)
t.pendown()
t.forward(500)
t.penup()
t.left(90)
t.forward(500)
t.left(90)
t.forward(50)
t.left(90)
t.pendown()
t.circle(-200, 180)
t.right(90)
t.forward(150)
t.right(90)
t.fillcolor("#ed2d05")
t.begin_fill()
t.forward(150)
t.circle(40)
t.left(90)
t.forward(80)
t.left(90)
t.forward(150)
t.end_fill()
Complete Code
Below, are the complete code of basketball ground which we created using Turtle Library in Python.
main.py
Python3
import turtle # importing turtle module
screen = turtle.Screen() # creating screen
screen.bgcolor("#eb8c34")
screen.setup(width=1357, height=760)
t = turtle.Turtle() # creating turtle object
t.hideturtle()
t.penup()
t.backward(500)
t.left(90)
t.forward(200)
t.right(90)
t.pensize(7)
t.pendown()
t.pencolor("white")
t.fillcolor("blue")
t.begin_fill()
t.forward(1000)
t.right(90)
t.forward(500)
t.right(90)
t.forward(1000)
t.right(90)
t.forward(500)
t.end_fill()
t.penup()
t.backward(450)
t.right(90)
t.pendown()
t.circle(200, 180)
t.left(90)
t.forward(150)
t.left(90)
t.fillcolor("#ed2d05")
t.begin_fill()
t.forward(150)
t.circle(-40)
t.right(90)
t.forward(80)
t.right(90)
t.forward(150)
t.end_fill()
t.penup()
t.right(90)
t.forward(70)
t.right(90)
t.forward(30)
t.pendown()
t.right(90)
t.forward(30)
t.circle(10)
t.forward(30)
t.penup()
t.right(90)
t.forward(30)
t.right(90)
t.forward(271)
t.right(90)
t.forward(500)
t.right(90)
t.pendown()
t.forward(500)
t.penup()
t.left(90)
t.forward(500)
t.left(90)
t.forward(50)
t.left(90)
t.pendown()
t.circle(-200, 180)
t.right(90)
t.forward(150)
t.right(90)
t.fillcolor("#ed2d05")
t.begin_fill()
t.forward(150)
t.circle(40)
t.left(90)
t.forward(80)
t.left(90)
t.forward(150)
t.end_fill()
t.penup()
t.left(90)
t.forward(70)
t.left(90)
t.forward(30)
t.pendown()
t.left(90)
t.forward(30)
t.circle(-10)
t.forward(30)
t.penup()
t.left(90)
t.forward(30)
t.left(90)
t.forward(270)
t.left(90)
t.forward(500)
t.left(90)
t.forward(350)
t.pendown()
t.left(90)
t.begin_fill()
t.circle(100, 180)
t.circle(100, 180)
t.end_fill()
t.penup()
t.goto(0, 200)
t.right(90)
t.pensize(10)
t.pendown()
t.forward(500)
turtle.done()
Run the Server
Run the following program by running the below command in your terminal:
python main.py
Output

Similar Reads
Create a Basketball Ground Using Turtle Library in Python
We have the task of how to make basketball ground using Turtle graphics in Python and print the ground. In this article, we will see how to create a basketball ground using Python Turtle Library. Create a Basketball Ground Using Python TurtleBelow, is the Implementation of Basketball using the Turtl
4 min read
Create a simple Animation using Turtle in Python
Turtle is a Python feature like a drawing board, which lets us command a turtle to draw all over it! We can use functions like turtle.forward(â¦) and turtle.right(â¦) which can move the turtle around. Let's create a basic animation where different little turtles race around a track created for them. P
4 min read
Python program to draw a bar chart using turtle
Prerequisite: Turtle Programming Basics Turtle is a Python feature like a drawing board, which lets us command a turtle to draw all over it! We can use functions like a turtle.forward(â¦) and turtle.right(â¦) which can move the turtle around. Turtle is a beginner-friendly way to learn Python by runnin
3 min read
Python - Draw Hexagon Using Turtle Graphics
In this article, we will learn how to make a Hexagon using Turtle Graphics in Python. For that lets first know what is Turtle Graphics. Turtle graphics Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move
2 min read
Draw Black Spiral Pattern Using Turtle in Python
Prerequisite: Turtle Programming in Python âTurtleâ is a Python feature like a drawing board, which lets us command a turtle to draw all over it. This module comes packed with the standard Python package and need not be installed externally. Functions used:forward(value): It moves the turtle in forw
1 min read
Draw a circle using Turtlesim in ROS-Python
In this article, we are going to see how to draw a circle using Turtlesim in ROS-Python. ROS stands for Robot Operating System. ROS is a set of libraries and tools that help build robot applications. It's extensively used in robotics projects. ROS is an open-source, meta-operating system for robots.
3 min read
Star fractal printing using Turtle in Python
Prerequisite: Turtle Programming Basics Fractals are objects that tend to have self-similar structures repeated a finite number of times. The objective of this article is to draw a star fractal where a star structure is drawn on each corner of the star and this process is repeated until the input si
2 min read
Python - Draw Octagonal shape Using Turtle Graphics
In this article, we will learn how to Make an Octagon using Turtle Graphics in Python. For that lets first know what is Turtle Graphics. Turtle graphicsbackward(length): moves the pen in the backward direction by x unit.right(angle): rotate the pen in the clockwise direction by an angle x.left(angle
2 min read
How to make Triangle in Python Turtle using onscreenclick?
âTurtleâ is a Python feature like a drawing board, which lets us command a turtle to draw all over it! We can use functions like turtle.forward(â¦) and turtle.right(â¦) which can move the turtle around. Turtle is also Known as Logo Programming language which commands for movement and drawing produced
2 min read
Balloon Archer game in Python using the Pygame module
Balloon Archer is a 2D game where the player uses a bow and arrow to pop balloons that float across the screen. The main theme of this game is to shoot down the balloons using arrows and on each successful attempt, the player earns a point and on each unsuccessful attempt, the player loses a life. I
15+ min read