9-сынып.
Информатикадан PyGame бөліміне арналған тапсырмалардың кодтары
№1. Қарша
анимациясымен
import pygame;
import random; pygame.init()
BLACK = [0, 0,
0]; WHITE = [255, 255, 255]
SIZE = [800,
800]
okno =
pygame.display.set_mode(SIZE)
pygame.display.set_caption("Snow Animation")
snejinka =
[]
for i in
range(600):
x =
random.randrange(0, 800)
y =
random.randrange(0, 800)
snejinka.append([x, y])
clock =
pygame.time.Clock()
flag =
True
while
flag:
for event in
pygame.event.get():
if event.type
== pygame.QUIT:
flag =
False
okno.fill(BLACK)
for i in
range(len(snejinka)):
pygame.draw.circle(okno, WHITE, snejinka[i], 2)
snejinka[i][1]
+= 2
if
snejinka[i][1] > 800:
y =
random.randrange(-50,-10)
snejinka[i][1]
= y
x =
random.randrange(0, 800)
snejinka[i][0]
= x
pygame.display.flip()
clock.tick(50)
pygame.quit()
№2. Дөңгелекті
бағыттауыш-стрелкалардыың көмегімен жылжыту
import
pygame
import
sys
FPS =
60
W =
700
H =
300
WHITE = (255,
255, 255)
BLUE = (0, 70,
225)
sc =
pygame.display.set_mode((W, H))
clock =
pygame.time.Clock()
x = W //
2
y = H //
2
r =
50
while
1:
for i in
pygame.event.get():
if i.type ==
pygame.QUIT:
sys.exit()
elif i.type ==
pygame.KEYDOWN:
if i.key ==
pygame.K_LEFT:
x -=
3
elif i.key ==
pygame.K_RIGHT:
x +=
3
sc.fill(WHITE)
pygame.draw.circle(sc, BLUE, (x, y), r)
pygame.display.update()
clock.tick(FPS)
№3. Ракета суреті
import
pygame
pygame.init()
display=pygame.display.set_mode((400,400))
pygame.display.set_caption("raketa")
yellow=(255,255,0)
blue=(50,100,250)
x=170
y=170
while
True:
for i in
pygame.event.get():
if
i.type==pygame.QUIT:exit()
keys=pygame.key.get_pressed()
if
keys[pygame.K_UP]:
y=y-1
elif
keys[pygame.K_DOWN]:
y=y+1
elif
keys[pygame.K_LEFT]:
x=x-1
elif
keys[pygame.K_RIGHT]:
x=x+1
display.fill((255,255,255))
pygame.draw.rect(display,yellow,(x,y,70,200))
pygame.draw.circle(display,blue,(x+35,y+50),25)
pygame.draw.circle(display,blue,(x+35,y+110),25)
pygame.draw.circle(display,blue,(x+35,y+170),25)
puntos=[(x,y),(x+35,y-35),(x+70,y)]
pygame.draw.polygon(display,(64,128,255),puntos)
puntos=[(x+70,y+200),((x+70)+35,y+200),(x+70,y+150)]
pygame.draw.polygon(display,(64,128,255),puntos)
pygame.display.update()
pygame.time.Clock().tick(60)