-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (37 loc) · 1020 Bytes
/
app.py
File metadata and controls
48 lines (37 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 引入pygame和sys模块
import pygame, sys
import math
from pygame.locals import *
import time
import people
WIDTH = 500
HEIGHT = 500
RADIUS = 25
POINT_RADIUS = 5
BLACK = (0,0,0)
WHITE = (255,255,255)
PINK = (255,192,203)
RED = (255,0,0)
# 初始化pygame
pygame.init()
# 设置窗口与窗口标题
windowSurface = pygame.display.set_mode((WIDTH,HEIGHT),0,8)
pygame.display.set_caption('疫情模拟')
# 初始化人群
p = people.People(600, 1)
COLORS = [BLACK, PINK, RED]
# 事件循环
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
windowSurface.fill(WHITE) # 设置画布背景 起到擦除的作用
for i in range(len(p._status)): # 健康
x_point = p._people[i][0]
y_point = p._people[i][1]
pygame.draw.circle(windowSurface,COLORS[p._status[i]],(int(x_point), int(y_point)), POINT_RADIUS)
# 绘制窗口到屏幕上
pygame.display.update()
time.sleep(0.1)
p.update()