-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.py
138 lines (104 loc) · 3.83 KB
/
graphics.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import os
import pygame
from const import WINDOW_SIZE, INDENT_SIZE, CELL_VALUES, STEP_COUNTER_HEIGHT, BASE_PATH
pygame.init()
icon = pygame.image.load(os.path.join(BASE_PATH, 'images/croc_left.png'))
pygame.display.set_icon(icon)
pygame.font.init()
WINDOW = pygame.display.set_mode(
(WINDOW_SIZE + 2 * INDENT_SIZE, WINDOW_SIZE + 2 * INDENT_SIZE + STEP_COUNTER_HEIGHT),
)
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BACKGROUND = (0, 33, 36)
# Images
def get_pygame_image(path, width, height):
return pygame.transform.scale(pygame.image.load(os.path.join(BASE_PATH, path)), (width, height))
class WIN_LABEL:
width = 600
height = 600
image = get_pygame_image('images/labels/true_crocodile.png', width, height)
image = image.convert_alpha()
label_height = 51
class STEP_COUNTER:
width = 84
height = STEP_COUNTER_HEIGHT
image = get_pygame_image('images/labels/steps.png', width, height)
class DIGIT_IMAGE:
width = 18
height = STEP_COUNTER_HEIGHT
DIGIT_IMAGE_DICT = {
0: 'images/digits/0.png',
1: 'images/digits/1.png',
2: 'images/digits/2.png',
3: 'images/digits/3.png',
4: 'images/digits/4.png',
5: 'images/digits/5.png',
6: 'images/digits/6.png',
7: 'images/digits/7.png',
8: 'images/digits/8.png',
9: 'images/digits/9.png',
}
images = {}
for key, value in DIGIT_IMAGE_DICT.items():
images[key] = get_pygame_image(value, width, height)
class MINUS_BUTTON:
width = STEP_COUNTER_HEIGHT
height = STEP_COUNTER_HEIGHT
image = get_pygame_image('images/labels/minus.png', width, height)
class PLUS_BUTTON:
width = STEP_COUNTER_HEIGHT
height = STEP_COUNTER_HEIGHT
image = get_pygame_image('images/labels/plus.png', width, height)
class SOUND_ICON:
width = int(STEP_COUNTER_HEIGHT / 1.6)
height = STEP_COUNTER_HEIGHT
image = get_pygame_image('images/labels/sound.png', width, height)
class MUSIC_ICON:
width = STEP_COUNTER_HEIGHT
height = STEP_COUNTER_HEIGHT
image = get_pygame_image('images/labels/music.png', width, height)
CELL_VALUE_IMAGE_DICT = {
CELL_VALUES.HORIZONTAL: 'images/croc_left.png',
CELL_VALUES.VERTICAL: 'images/croc_up.png',
}
def get_cell_values_images(cell_size):
return {
key: get_pygame_image(value, cell_size, cell_size)
for key, value in CELL_VALUE_IMAGE_DICT.items()
}
BACKGROUND_IMAGE = get_pygame_image(
'images/background.png',
WINDOW_SIZE + 2 * INDENT_SIZE + STEP_COUNTER.height,
WINDOW_SIZE + 2 * INDENT_SIZE + STEP_COUNTER.height,
)
def fade_out(window, duration):
clock = pygame.time.Clock()
alpha_surface = pygame.Surface(window.get_size()) # fullscreen surface
alpha = 0
while alpha <= 60:
alpha_surface.set_alpha(alpha)
window.blit(alpha_surface, (0, 0)) # cover the entire screen with the surface
pygame.display.update()
alpha += 255 / (duration * 60) # increase alpha slowly over 'duration' seconds
clock.tick(60) # limit the while loop to 60 iterations per second (60FPS)
def grow_image(window, image, pos, duration):
clock = pygame.time.Clock()
original_image = image.copy() # copy of the original image
width, height = image.get_size()
start_time = pygame.time.get_ticks()
while True:
elapsed_time = (pygame.time.get_ticks() - start_time) / 1000
if elapsed_time > duration:
break
# Calculate the scale factor
scale_factor = elapsed_time / duration
new_size = (int(width * scale_factor), int(height * scale_factor))
# Clear the window
window.fill((0, 0, 0))
# Scale the image and draw it
scaled_image = pygame.transform.scale(original_image, new_size)
window.blit(scaled_image, pos)
pygame.display.update()
clock.tick(60)