The resize badge's arrow ran from the small square to the big one and read as growing. Four arrows closing in on a small square read as shrinking.
54 lines
2.9 KiB
Python
54 lines
2.9 KiB
Python
"""Paint the two sizing hammers' icons from the vanilla hammer's, so neither can pass for it in a
|
|
hotbar: Trol's Hammer gets a blue-steel head and a troll trophy, the Shrink Hammer a brass head and a
|
|
shrink badge (four arrows pointing in at a small square, the usual sign for making smaller).
|
|
Usage: py -3.14 -I paint_hammer_icons.py <pylib> <icons dir>
|
|
<icons dir> holds hammer.png and TrophyForestTroll.png (Sprites "hammer" and "TrophyForestTroll"
|
|
from bundle 6a33a62). Writes TrolsHammer_icon.png and ShrinkHammer_icon.png there; copy them to
|
|
JotunnModStub/Assets/Hammers/."""
|
|
import sys, os, math
|
|
sys.path.insert(0, sys.argv[1])
|
|
import numpy as np
|
|
from PIL import Image, ImageDraw, ImageFilter
|
|
d = sys.argv[2]
|
|
S = 128 # twice the vanilla icon, for sharper badges
|
|
|
|
def hammer_with_head(tint, lift):
|
|
hammer = Image.open(os.path.join(d, "hammer.png")).convert("RGBA").resize((S, S), Image.LANCZOS)
|
|
a = np.asarray(hammer, dtype=np.float32)/255
|
|
# the head: a rotated block in the upper part, its corners read off the 64 px sprite
|
|
head = Image.new("L", (S, S), 0)
|
|
ImageDraw.Draw(head).polygon([(x*2, y*2) for x, y in [(21,1), (57,13), (52,31), (16,19)]], fill=255)
|
|
head = np.asarray(head.filter(ImageFilter.GaussianBlur(1)), dtype=np.float32)/255
|
|
lum = a[...,:3] @ np.array([0.3, 0.55, 0.15])
|
|
metal = np.clip(lum[...,None]*np.array(tint) + np.array(lift), 0, 1)
|
|
a[...,:3] = a[...,:3]*(1 - head[...,None]) + metal*head[...,None]
|
|
return Image.fromarray((a*255).astype(np.uint8), "RGBA")
|
|
|
|
def with_rim(badge):
|
|
"""A dark rim around a badge, so it reads on any slot colour."""
|
|
rim = Image.new("RGBA", badge.size, (10, 10, 10, 0))
|
|
rim.putalpha(badge.split()[3].filter(ImageFilter.MaxFilter(5)).point(lambda v: min(v, 200)))
|
|
rim.alpha_composite(badge)
|
|
return rim
|
|
|
|
# Trol's Hammer
|
|
icon = hammer_with_head((1.05, 1.35, 1.9), (0.02, 0.05, 0.1))
|
|
trophy = Image.open(os.path.join(d, "TrophyForestTroll.png")).convert("RGBA").resize((60, 60), Image.LANCZOS)
|
|
icon.alpha_composite(with_rim(trophy), (S - 62, S - 62))
|
|
icon.save(os.path.join(d, "TrolsHammer_icon.png"))
|
|
|
|
# the Shrink Hammer
|
|
icon = hammer_with_head((1.9, 1.5, 0.75), (0.06, 0.04, 0.0))
|
|
B = 56
|
|
badge = Image.new("RGBA", (B, B), (0, 0, 0, 0))
|
|
g = ImageDraw.Draw(badge)
|
|
white = (240, 240, 235, 255)
|
|
c = B // 2
|
|
g.rectangle([c - 7, c - 7, c + 7, c + 7], fill=white) # the piece, made small
|
|
for dx, dy in ((-1, -1), (1, -1), (-1, 1), (1, 1)): # and the arrows closing in on it
|
|
start, tip = (c + dx*25, c + dy*25), (c + dx*11, c + dy*11)
|
|
g.line([start, tip], fill=white, width=3)
|
|
a = math.atan2(tip[1] - start[1], tip[0] - start[0])
|
|
g.polygon([tip] + [(tip[0] - 10*math.cos(a + s), tip[1] - 10*math.sin(a + s)) for s in (-0.5, 0.5)], fill=white)
|
|
icon.alpha_composite(with_rim(badge), (S - B - 4, S - B - 4))
|
|
icon.save(os.path.join(d, "ShrinkHammer_icon.png"))
|