added color calculator
This commit is contained in:
		
							
								
								
									
										0
									
								
								src/graph/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/graph/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										46
									
								
								src/utils/color_calculator.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/utils/color_calculator.py
									
									
									
									
									
										Normal 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()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user