Exercise 1:
import pygame#importpygamemodule
pygame.init()#pygameModule initialization
#Create[640,480]size window
screen= pygame.display.set_mode([640,480])
pygame.display.set_caption("Test")#Set window title
'''The following is to start an event loop, which will run all the time
until the user clicks "Close" the window'''
running= True
while running:
for event in pygame.event.get():
if event.type== pygame.QUIT:
running= False
pygame.quit()#quitpygame
Exercise 2:
import pygame
pygame.init()
screen = pygame.display.set_mode([640,480])
pygame.display.set_caption("Test")
screen.fill([255,255,255])
'''----------------Drawing object color circle center coordinate radius line width'''
pygame.draw.circle(screen,[255,0,0],[320,240],30,1 )
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Exercise 3:
import pygame
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
pygame.draw.rect(screen,[255,0,0],[220,140,200,200],0)
pygame.draw.circle(screen,[255,255,255],[320,240],100,0)
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Homework:
import pygame
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])#fill screen with white background
pygame.draw.circle(screen,[255,0,0],[300,140],40,20)
pygame.draw.line(screen,[255,0,0],[350,100],[350,180],10)
pygame.draw.circle(screen,[255,0,0],[400,140],40,20)
pygame.display.update()#Re-draw the changed area of the screen
'''pygame.display.flip():Update all screen'''
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
[…] (Part 2)| |____Unit 54 Object Oriented Advanced| |____Unit 55 Modules|____Python Level 6| |____Unit 56 Windows and Basic Graphics| |____Unit 57 Graphics and Basic Animation| |____Unit 58 Animation Design| |____Unit 59 Animated […]