-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (57 loc) · 1.84 KB
/
main.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
from PIL import Image
import numpy as np
import math
import random
from tkinter import colorchooser
import os
def choose_color():
rgb = []
color = colorchooser.askcolor()
for value in color[0]:
rgb.append(math.floor(value))
return rgb
def change_color(data, color):
red, green, blue, alpha = data.T
purple_areas = (red == 190) & (green == 61) & (blue == 237)
data[..., :-1][purple_areas.T] = color
def random_color():
if not os.path.exists("random_skins"):
os.mkdir("random_skins")
save_dir = os.path.curdir + "/random_skins/"
amount = int(input("Enter number of random skins to make: "))
img = Image.open("base.png")
img = img.convert("RGBA")
for i in range(amount):
rgb = [random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255)]
name = rgb2hex(rgb[0], rgb[1], rgb[2])
data = np.array(img)
change_color(data, rgb)
img2 = Image.fromarray(data)
img2.save(save_dir + name + ".png")
print("Saved as {}.png".format(name))
def rgb2hex(r, g, b):
return "#{:02x}{:02x}{:02x}".format(r, g, b)
def custom_color():
print("Choose a color in the dialog")
rgb = choose_color()
print("Got color: {}".format(rgb))
name = input("Enter file name to save (will be saved as png): ")
img = Image.open("base.png")
img = img.convert("RGBA")
data = np.array(img)
change_color(data, rgb)
img2 = Image.fromarray(data)
img2.save(name + ".png")
print("Saved as {}.png".format(name))
def main():
while True:
print("1. Choose your own color")
print("2. Generate random colors")
option = input("Enter selection: ")
if option == "1":
custom_color()
break
elif option == "2":
random_color()
break
main()