We create a basic window in Python and draw the basic geometrical shapes like Rectangle, Circle, Line, ellipse or polygon etc. You should have pygame installed else the code will not execute and throw an ImportError.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Created on 16-Nov-2014 | |
Modified on 19-July-2015 | |
@author: Psycho_Coder | |
""" | |
import pygame | |
import sys | |
from pygame.locals import QUIT | |
pygame.init() | |
DISPSURF = pygame.display.set_mode((320, 250), 0, 32) | |
pygame.display.set_caption("Basic Shapes using PyGame") | |
BLACK = (0, 0, 0) | |
WHITE = (255, 255, 255) | |
RED = (227, 27, 27) | |
GREEN = (0, 255, 0) | |
BLUE = (0, 0, 255) | |
RCB = (27, 27, 27) | |
# Fill the background with a color | |
DISPSURF.fill(RCB) | |
pygame.draw.polygon(DISPSURF, RED, ((20, 20), (52, 60), (171, 60), (200, 20))) | |
pygame.draw.line(DISPSURF, BLUE, (50, 60), (50, 160), 2) | |
pygame.draw.line(DISPSURF, BLUE, (170, 60), (170, 160), 2) | |
pygame.draw.line(DISPSURF, RED, (110, 60), (110, 160), 2) | |
pygame.draw.circle(DISPSURF, WHITE, (110, 110), 40, 1) | |
pygame.draw.rect(DISPSURF, GREEN, (52, 160, 120, 40)) | |
pygame.draw.ellipse(DISPSURF, RED, (220, 100, 80, 40)) | |
pygame.draw.ellipse(DISPSURF, BLUE, (240, 80, 40, 80)) | |
while True: | |
for evt in pygame.event.get(): | |
if evt.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
pygame.display.update() |