-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavgcolor.py
executable file
·52 lines (42 loc) · 1.28 KB
/
avgcolor.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
# All Pokemon ripped by veekun.com/dex/downloads
# Creates JSON with all Pokemon from folder
from PIL import Image
import os
def getPixelData(file):
img = Image.open(file).convert('RGBA')
pixels = list(img.getdata())
#print(pixels)
rAvg = 0
gAvg = 0
bAvg = 0
count = 0
for pixel in pixels:
if (type(pixel) is int): # Some files with extra chars throw an error
return "error at " + str(file) + str(img.getdata())
if (pixel[3] != 0):
rAvg += pixel[0]
gAvg += pixel[1]
bAvg += pixel[2]
count += 1
rAvg = rAvg / count
gAvg = gAvg / count
bAvg = bAvg / count
return(str(rAvg) +"," + str(gAvg) +"," + str(bAvg))
def main():
pokemon = open("pokemon.data","w")
pokemon.write("const pokemon = {\n")
numberOfPokemon = len(os.listdir("pokemon/"))
pokemonCount = 0
for file in os.listdir("pokemon/"):
if file.endswith(".png"):
pokemon.write("\"" + file + "\" : [" +
getPixelData('pokemon/' + file)
+ "]")
#print i
if (pokemonCount < numberOfPokemon - 1):
pokemon.write(",\n")
pokemonCount += 1
pokemon.write("\n};")
pokemon.close
if __name__== "__main__":
main()