Skip to content

Commit 586277e

Browse files
committed
m
1 parent 253f7b4 commit 586277e

File tree

9 files changed

+38
-0
lines changed

9 files changed

+38
-0
lines changed

yeke/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
+ [py-tetris](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-tetris) :用 Python 写个俄罗斯方块
1111
+ [py-counter](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-counter) :不到 100 行 Python 代码写个计算器
1212
+ [py-tank](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-tank) :用 Python 写个坦克大战
13+
+ [py-scratch](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-scratch) :不到 50 行 Python 代码,做个刮刮卡
1314

1415
---
1516

yeke/py-scratch/__init__.py

Whitespace-only changes.

yeke/py-scratch/prize/1.jpg

26.1 KB
Loading

yeke/py-scratch/prize/2.jpg

26.4 KB
Loading

yeke/py-scratch/prize/3.jpg

26.4 KB
Loading

yeke/py-scratch/prize/4.jpg

28.6 KB
Loading

yeke/py-scratch/prize/5.jpg

28.6 KB
Loading

yeke/py-scratch/prize/6.jpg

28.6 KB
Loading

yeke/py-scratch/scratch.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
import random
4+
import pygame
5+
6+
path = 'prize'
7+
ptype = ['jpg', 'png', 'bmp', 'JPG', 'PNG', 'BMP']
8+
# 窗口大小
9+
screen_size = (600, 400)
10+
white = (255, 255, 255, 20)
11+
gray = (192, 192, 192)
12+
pygame.init()
13+
pygame.mouse.set_cursor(*pygame.cursors.diamond)
14+
screen = pygame.display.set_mode(screen_size)
15+
pygame.display.set_caption('刮一刮抽奖')
16+
surface = pygame.Surface(screen_size).convert_alpha()
17+
surface.fill(gray)
18+
filenames = os.listdir(path)
19+
filenames = [f for f in filenames if f.split('.')[-1] in ptype]
20+
imgpath = os.path.join(path, random.choice(filenames))
21+
image_used = pygame.transform.scale(pygame.image.load(imgpath), screen_size)
22+
while True:
23+
for event in pygame.event.get():
24+
if event.type == pygame.QUIT:
25+
pygame.quit()
26+
sys.exit(-1)
27+
mouse_event = pygame.mouse.get_pressed()
28+
if mouse_event[0]:
29+
pygame.draw.circle(surface, white, pygame.mouse.get_pos(), 40)
30+
elif mouse_event[-1]:
31+
surface.fill(gray)
32+
image_used = pygame.transform.scale(pygame.image.load(imgpath), screen_size)
33+
screen.blit(image_used, (0, 0))
34+
screen.blit(surface, (0, 0))
35+
pygame.display.update()
36+
37+

0 commit comments

Comments
 (0)