-
Notifications
You must be signed in to change notification settings - Fork 5
/
background.py
38 lines (31 loc) · 1.19 KB
/
background.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
from PIL import Image
import random
from config import *
use_background_colors = enable_background
width = size_width
height = size_height
golden = {'r': 255, 'g': 188, 'b': 0, 'rarity': 15, 'name': 'golden'}
silver = {'r': 178, 'g': 189, 'b': 191, 'rarity': 40, 'name': 'silver'}
red = {'r': 236, 'g': 16, 'b': 56, 'rarity': 5, 'name': 'red'}
blue = {'r': 42, 'g': 110, 'b': 227, 'rarity': 30, 'name': 'blue'}
list_background_colors = [golden, silver, red, blue]
def createBackground():
if(use_background_colors):
rand = random.randint(1, 10)
if rand > 8:
background = pond(list_background_colors)
return Image.new("RGBA", (width, height), (background['r'], background['g'], background['b']))
return Image.new("RGBA", (width, height), (0, 0, 0, 0))
else:
return Image.new("RGBA", (width, height), (0, 0, 0, 0))
def pond(list):
total = 0
for i in list:
total += i['rarity']
pond = []
for i in list:
pond.append((i['rarity']*100) / total)
rand = random.randint(1, 100)
#for i in pond:
# print('tem chance real de '+str(i)+'%')
return list[pond.index(min(pond, key=lambda x:abs(x-rand)))]