Draw A Sun In Python Using Turtle
In this tutorial I will show you how to draw a sun in python using the turtle module, turtle is a GUI library which can be used to draw anything from characters, cartoons, shapes and other objects in python.
Python Code To Draw A Sun
# Import the turtle module and all its functions from turtle import * # Set the fill color to orange and the pen color to yellow color('orange', 'yellow') # Begin filling the shape with the current fill color begin_fill() # Loop indefinitely (until the program is stopped manually) while True: # Move the turtle forward 350 pixels forward(350) # Turn the turtle left by 170 degrees left(170) # Turn the turtle right by 280 degrees right(280) # Check if the turtle's position is close to the starting point (within 1 pixel) if abs(pos()) < 1: # If it is, exit the loop break # End the fill operation end_fill() # Stop the turtle graphics window from closing immediately done()
Above is the python program to draw a sun, Now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer or else you can use this online compiler no need to install anything.
This program draws a sun by drawing a geometric pattern repeatedly and after it is done it looks like a sun you will see it when you run it.
Before you can run it you might need to install the turtle library if it is not installed already, use the below command to install
pip install turtle
So now you have everything setup and you are ready to run the program, so to run this program open a command prompt at your program folder location and paste the below command.
The above command will run the program and it will open a new window and it will start drawing a sun and below is the finished drawing of a sun.
As you can see we successfully drew a sun using python turtle. I hope you were able to run this program successfully, I hope you found this tutorial helpful and useful.
Here are some more python drawing tutorials for you:
- Draw Pikachu using python with code.
- Draw doraemon using python turtle.
- Draw shinchan using python turtle.
- Draw I love you using python turtle.
- Draw Batman logo using python turtle.
- Draw Google Logo using python turtle.
- Make a python calculator using turtle.
- Draw christmas tree using python.
- Draw spiderman in python programming.
- Draw Python Logo Using Python.
- Draw Iron Man using python turtle with code.
- Draw A Heart Using python turtle with code.
- Draw car in python turtle with code.
I hope you found what you were looking for from this tutorial, do share this tutorial with your friends who might be interested in this program and if you want more python guides and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂