From 029d24ce6198fc76eb8197d8d316559b094bd7c3 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Wed, 3 Jul 2024 01:55:11 +0200 Subject: [PATCH] added color calculator --- src/graph/__init__.py | 0 src/utils/color_calculator.py | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/graph/__init__.py create mode 100644 src/utils/color_calculator.py diff --git a/src/graph/__init__.py b/src/graph/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/color_calculator.py b/src/utils/color_calculator.py new file mode 100644 index 0000000..d58fc6d --- /dev/null +++ b/src/utils/color_calculator.py @@ -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()