forked from madboy482/Black-Lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.py
51 lines (46 loc) · 1.63 KB
/
utility.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
from PIL import Image, ImageDraw
# Returns an image describing the user's pokedex
# Input:
# dex_obj: Array (?) of number_obtained[Pokedex_number - 1]
def user_pokedex(dex_obj):
images = [Image.open('icons/{}.png'.format(i)) for i in range(1,152)]
# Fixed width for background; length should be dependent on Pokedex entries
# Each icon is 30x30, use padding of 2px on all sides, rows of 5
height_stop = True
curr = 151
while(height_stop and curr > -1):
try:
if dex_obj[curr] > 0:
height_stop = False
else:
curr -= 1
except:
curr -= 1
bg_w = 2 + (30+2) * 5
bg_h = 2 + (30+2) * ((curr // 5) + 1)
background = Image.new('RGBA', (bg_w, bg_h), (255, 255, 255, 255))
# Print out the first 150 Pokemon (Mew separately)
x, y = [2, 2]
for i in range(0, min(len(dex_obj), 150)):
if dex_obj[i] > 0:
# Also return number obtained
draw = ImageDraw.Draw(images[i-1])
draw.text((1, 20), str(dex_obj[i]), fill=(0,0,0,255))
# Then paste the image onto the pokedex background
background.paste(images[i-1], (x, y))
# when to /r/n
if i%5 != 4:
x = x+30+2
else:
x = 2
y = y+30+2
try:
if dex_obj[150] > 0:
x = 2 + (30+2) + (30+2)
# Also return number obtained
draw = ImageDraw.Draw(images[150])
draw.text((1, 20), str(dex_obj[150]), fill=(0,0,0,255))
background.paste(images[150], (x, y))
except:
pass
background.save('user_dex.png')