added color calculator

This commit is contained in:
Louis Heredero 2024-07-03 01:55:11 +02:00
parent ecdf3d30eb
commit 029d24ce61
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 46 additions and 0 deletions

0
src/graph/__init__.py Normal file
View File

View File

@ -0,0 +1,46 @@
import json
import os
import pygame
EXCLUDE = {
"bottom", "side", "front", "cracked", "on", "stem", "tip", "lit", "inner"
}
def main() -> None:
pygame.init()
win = pygame.display.set_mode((1, 1))
path = "/tmp/minecraft/textures/block"
with open("/tmp/overrides.json", "r") as f:
overrides = json.load(f)
colors = {}
paths = os.listdir(path)
total = len(paths)
skipped = 0
for i, filename in enumerate(paths):
print(f"\r{i+1}/{total} ({i/total*100:.2f}%) {filename}", end="")
block, ext = filename.rsplit(".", 1)
if ext != "png":
skipped += 1
continue
parts = set(block.split("_"))
if not parts.isdisjoint(EXCLUDE):
skipped += 1
continue
block = block.replace("_top", "")
img = pygame.image.load(os.path.join(path, filename)).convert_alpha()
color = pygame.transform.average_color(img, consider_alpha=True)
colors[f"minecraft:{block}"] = color[:3]
print(f"\r{total}/{total} (100%) Finished")
print(f"Skipped {skipped} files")
colors.update(overrides)
with open("/tmp/colors.json", "w") as f:
json.dump(colors, f, indent=4)
if __name__ == '__main__':
main()