DRAWING A CIRCLE USING PYGAME PYTHON
In this tutorial, you will learn how to draw a circle using pygame python. This is implemented using VSC editor with python SDK.
TESTED TOOL DETAILS
- VSC Editor
- Python 3.6.4 (X64 Bit)
- Pygame 1.9.1
NOTE
- Before to start the programming, pygame software should be installed
SOURCE CODE
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((500, 400))
# set blue color as a tuple object
color=(0,128,255)
# set x & y position as a tuple object
pos=(250,200)
# run infinite loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
# set background windows as white
screen.fill((255, 255, 255))
# draw circle on screen
pygame.draw.circle(screen, color, pos, 90)
# update game
pygame.display.update()
RESULT
Used Functions
1. init()
- This function initializes all the modules required for PyGame.
2. set_mode((width, height))
- This function will launch a window of the desired size.
- The return value is a surface object that is used to perform graphical operations in the pygame environment
3. get()
- This empties the event queue (returns the list of events)
- If you don’t call this function, the game screen will become unresponsive in the opinion of the operating system.
4. QUIT
- This is the one of the type of event, that is fired when user click on the close button in the corner of the window
- This is available in pygame module
5. update()
- This function is used to update the portion of screen after everything is drawn
- This is available in display sub module
Color Name = (r,g,b)
- Specify the name the color
- (r,g,b) is a tuple with values for red, green, and blue
- All three should be integers between 0 and 255, with 255 being brightest, and 0 being darkest.
Sample RGB Based Color Codes
red = (255,0,0) green = (0,255,0) blue = (0,0,255) dark blue = (0,0,128) white = (255,255,255) black = (0,0,0) pink = (255,200,200) |