Skip to content

Commit 618203a

Browse files
committed
提交代码
1 parent 84aa616 commit 618203a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

.DS_Store

2 KB
Binary file not shown.

xianhuan/.DS_Store

4 KB
Binary file not shown.

xianhuan/circlegame/circlegame.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
import pygame, random, sys, time
7+
8+
pygame.init()
9+
screen = pygame.display.set_mode([600, 400])
10+
screen.fill((255, 255, 255))
11+
# 圆的半径
12+
radius = [0] * 10
13+
# 圆的半径增量
14+
circleDelt = [0] * 10
15+
# 圆是否存在,False代表该索引值下的圆不存在,True代表存在
16+
circleExists = [False] * 10
17+
# 圆的坐标x轴
18+
circleX = [0] * 10
19+
# 圆的坐标y轴
20+
circleY = [0] * 10
21+
# 颜色RGB值
22+
RGBx = [0] * 10
23+
RGBy = [0] * 10
24+
RGBz = [0] * 10
25+
26+
while True:
27+
# 停顿0.1秒
28+
time.sleep(0.1)
29+
for event in pygame.event.get():
30+
# 鼠标按下
31+
if event.type == pygame.MOUSEBUTTONDOWN:
32+
# 获取圆不存在的索引值
33+
num = circleExists.index(False)
34+
# 将该索引值的圆设置为存在
35+
circleExists[num] = True
36+
# 圆的半径设置为0
37+
radius[num] = 0
38+
# 获取鼠标坐标
39+
circleX[num], circleY[num] = pygame.mouse.get_pos()
40+
# 随机获取颜色值
41+
RGBx[num] = random.randint(0, 255)
42+
RGBy[num] = random.randint(0, 255)
43+
RGBz[num] = random.randint(0, 255)
44+
# 画圆
45+
pygame.draw.circle(screen, pygame.Color(RGBx[num], RGBy[num], RGBz[num]),
46+
(circleX[num], circleY[num]), radius[num], 1)
47+
if event.type == pygame.QUIT:
48+
pygame.quit()
49+
sys.exit()
50+
for i in range(10):
51+
# 圆不存在则跳过循环
52+
if not circleExists[i]:
53+
pass
54+
else:
55+
# 随机圆的大小
56+
if radius[i] < random.randint(10, 50):
57+
# 圆的随机半径增量
58+
circleDelt[i] = random.randint(0, 5)
59+
radius[i] += circleDelt[i]
60+
# 画圆
61+
pygame.draw.circle(screen, pygame.Color(RGBx[i], RGBy[i], RGBz[i]),
62+
(circleX[i], circleY[i]), radius[i], 1)
63+
else:
64+
# 若圆已达到最大,这将该索引值的圆设置为不存在
65+
circleExists[i] = False
66+
pygame.display.update()

0 commit comments

Comments
 (0)