Python 7 Levels, L6, Unit 56, Windows and Basic Graphics

Powered By EmbedPress

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()

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts