plugins/network/resource-pack/central/generator/soft_items.py
unimatrixgit 86c6142469
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled
Supplied Dune Item Art Build / supplied-item-art (push) Has been cancelled
Integrate supplied Dune item art and preserve live pack variants
2026-12-03 20:51:37 +01:00

269 lines
12 KiB
Python

"""Soft Dune currency, devices, sigils, crests and keepsakes. Same public names as the old items_misc module."""
import math
from PIL import Image, ImageChops
from dunelib import Cv, SS, mix, rgb, hexagon
from dunesoft import *
# ---------------------------------------------------------------- coins
COINS = {
# name: (label, sub, rim_hi, rim_lo, field)
"coin_001": ("1", "CENT", "#d8a273", "#8a5334", "#b9794f"),
"coin_002": ("2", "CENT", "#dcaa7c", "#8d5736", "#bd7d54"),
"coin_005": ("5", "CENT", "#e0b387", "#935c3a", "#c4865c"),
"coin_010": ("10", "CENT", "#d8d6c6", "#7c7b70", "#a9a89b"),
"coin_020": ("20", "CENT", "#dfdccd", "#827f73", "#b0aea0"),
"coin_050": ("50", "CENT", "#e6e3d4", "#898678", "#b8b5a6"),
"coin_1dm": ("1", "DM", "#f0d795", "#9a7633", "#cfa955"),
"coin_1dm_gold": ("1", "DM", "#f6e2a3", "#a67f2f", "#dcb45a"),
"coin_1dm_silver": ("1", "DM", "#eceae0", "#8a897f", "#bdbbae"),
"coin_2dm": ("2", "DM", "#f3dc9b", "#9e7a31", "#d4ad57"),
}
def coin(name):
label, sub, hi, lo, field = COINS[name]
cv = Cv(128)
c = 64
outer = gear(cv, c, c, 52, 28, 0.045, 0)
cv.fill(outer, hi, lo)
cv.bevel(outer, .5, .32, 1.8)
cv.edge(outer, SP["umber"], 1.0, .75)
ring = cv.circle(c, c, 45)
cv.fill(ring, lo, hi)
face = cv.circle(c, c, 41)
cv.fill(face, mix(field, "#ffffff", .18), mix(field, SP["umber"], .22))
cv.bevel(face, .25, .3, 1.4)
# fine milled grooves, hand-struck rather than circuit-drawn
for r in (36, 33.5):
cv.edge(cv.circle(c, c, r), lo, .55, .45)
worm_arc(cv, c, c, 36, mix(hi, "#ffffff", .25), 1.8, .55)
big = 44 if len(label) == 1 else 34
t = cv.text((c, c - 3), label, big)
engrave(cv, t, mix(lo, SP["umber"], .55))
s = cv.text((c, c + 26), sub, 10)
engrave(cv, s, mix(lo, SP["umber"], .45), .5)
cv.solid(cv.circle(38, 33, 9), "#ffffff", .10)
return finish(cv, seed=hash(name) % 997)
# ---------------------------------------------------------------- notes
NOTES = {
"note_5": ("5", "#7f9a6a", "#e7e2c3"),
"note_10": ("10", "#6fa0a4", "#e3e4c9"),
"note_20": ("20", "#6d92bd", "#e3e1cb"),
"note_50": ("50", "#7e83b4", "#e5e0cd"),
"note_100": ("100", "#9b7bb0", "#e8dfcc"),
"note_200": ("200", "#b7799f", "#ebdecd"),
"note_500": ("500", "#c9774f", "#efdfc4"),
"note_1000": ("1000", "#cf9a3c", "#f1e2bb"),
"note_5000": ("5000", "#a8452c", "#f2dfbd"),
"note_0_house": ("", "#a68345", "#e9dfc3"),
"note_0_leto": ("", "#c9803a", "#efdcb6"),
}
def note(name):
label, tint, paper = NOTES[name]
cv = Cv(128)
body = cv.rrect(4, 26, 124, 102, 7)
cv.fill(body, mix(paper, "#ffffff", .25), mix(paper, SP["dune"], .35))
cv.bevel(body, .3, .22, 1.2)
cv.edge(body, SP["umber"], 1.0, .75)
# engraved border band, guilloche-like overlapping rings
band = cv.rrect(8, 30, 120, 98, 5)
cv.edge(band, tint, 1.7, .85)
cv.edge(cv.rrect(11.5, 33.5, 116.5, 94.5, 3.5), tint, .55, .6)
ex, ey = 93, 64
for k in range(7):
a = math.radians(k * 25.7)
cv.edge(cv.circle(ex + 6 * math.cos(a), ey + 6 * math.sin(a), 18), tint, .45, .32)
seal = cv.circle(ex, ey, 21)
cv.fill(seal, mix(paper, tint, .22), mix(paper, tint, .45))
cv.edge(seal, tint, 1.1, .9)
cv.edge(cv.circle(ex, ey, 17), SP["brass3"], .6, .8)
if name == "note_0_house":
pts = [(ex - 10, ey + 5), (ex - 11, ey - 7), (ex - 5, ey - 1), (ex, ey - 9), (ex + 5, ey - 1), (ex + 11, ey - 7), (ex + 10, ey + 5)]
cv.solid(cv.line(pts + [pts[0]], 1.5), SP["brass3"])
cv.solid(cv.line([(ex - 10, ey + 9), (ex + 10, ey + 9)], 1.5), SP["brass3"])
elif name == "note_0_leto":
for r in (13, 9, 5):
worm_arc(cv, ex, ey, r, SP["terracotta"], 1.7)
cv.solid(cv.circle(ex, ey, 2), SP["umber2"])
else:
worm_arc(cv, ex, ey, 11, mix(tint, SP["umber"], .25), 2.3)
cv.solid(cv.circle(ex, ey, 2.6), SP["umber2"])
num = label or "0"
size = {1: 40, 2: 34, 3: 28, 4: 21}[len(num)]
engrave(cv, cv.text((34, 56), num, size), mix(tint, SP["umber"], .45))
engrave(cv, cv.text((34, 82), "DUNEMARK", 8.2), mix(tint, SP["umber"], .4), .4)
cv.solid(cv.line([(14, 90), (60, 90)], .8), tint, .7)
cv.solid(cv.line([(14, 38), (44, 38)], .8), tint, .7)
return finish(cv, seed=hash(name) % 997)
def legacy_note(value):
m = {"1": "note_5", "5": "note_5", "100": "note_100", "1000": "note_1000", "5000": "note_5000", "note": "note_100"}
return note(m[value])
# ---------------------------------------------------------------- spy module
def spy_module():
"""brass-and-glass seeker egg: a thinking-machine-free hunter-seeker shell"""
cv = Cv(128)
pts = []
for i in range(72):
t = i / 72 * 2 * math.pi
x = 64 + 36 * math.sin(t)
y = 66 - 46 * math.cos(t) * (1.0 if math.cos(t) > 0 else .86)
if math.cos(t) > 0:
x = 64 + 36 * math.sin(t) * (1 - .18 * math.cos(t))
pts.append((x, y))
body = cv.poly(pts)
cv.fill(body, SP["brass2"], SP["brass3"])
cv.bevel(body, .5, .35, 2.2)
cv.edge(body, SP["umber"], 1.2, .8)
# riveted plate seams
for yy in (44, 88):
cv.solid(cv.clip(cv.line([(20, yy), (108, yy)], 1.0), body), SP["umber"], .45)
for x, y in ((38, 44), (90, 44), (36, 88), (92, 88), (64, 26)):
rivet(cv, x, y, 1.9)
ring = gear(cv, 64, 66, 25, 12, .12, 0)
cv.fill(ring, SP["bronze"], SP["umber2"])
cv.edge(ring, SP["umber"], .8, .8)
lens_rim = cv.circle(64, 66, 17)
cv.fill(lens_rim, SP["brass2"], SP["brass3"])
lens = cv.circle(64, 66, 13.5)
cv.fill(lens, SP["water"], SP["fremen"])
cv.solid(cv.circle(64, 66, 8), SP["fremen"]) # blue-within-blue
cv.solid(cv.circle(64, 66, 3.8), SP["night"])
cv.solid(cv.circle(59, 61, 3), "#ffffff", .75)
for sx in (-1, 1): # soft fins
fin = cv.poly([(64 + sx * 35, 54), (64 + sx * 50, 44), (64 + sx * 44, 64)])
soft_body(cv, fin, SP["brass2"], SP["bronze"], ew=.8)
return finish(cv, seed=5)
# ---------------------------------------------------------------- planet sigils
PLANET_TINT = {
"nivareth": "#7fa6c6", "orivane": "#c9a05a", "pelareth": "#7fae9d", "serevan": "#a58bb4", "varkesh": "#c9765a",
}
def planet(name, src_img):
tint = PLANET_TINT[name]
cv = Cv(128)
disc = cv.circle(64, 64, 58)
cv.fill(disc, SP["brass2"], SP["brass3"])
cv.bevel(disc, .5, .35, 2)
cv.edge(disc, SP["umber"], 1.1, .8)
inner = cv.circle(64, 64, 49)
cv.fill(inner, mix(tint, "#ffffff", .38), mix(tint, SP["umber"], .38))
cv.edge(inner, SP["umber2"], .8, .7)
for i in range(36): # milled rim ticks
a = math.radians(i * 10)
cv.solid(cv.line([(64 + 52.5 * math.cos(a), 64 + 52.5 * math.sin(a)), (64 + 56 * math.cos(a), 64 + 56 * math.sin(a))], .7), SP["umber2"], .6)
layer = cv.im
s = src_img.convert("RGBA").resize((128 * SS, 128 * SS), Image.LANCZOS)
a = s.getchannel("A").point(lambda v: min(255, int(v * 1.25)))
# glyph rendered as dark engraved ink, clipped to the inner disc
a = ImageChops.multiply(a, cv.circle(64, 64, 49))
ink = Image.new("RGBA", s.size, rgb(SP["umber"]))
ink.putalpha(a.point(lambda v: int(v * .88)))
hi = Image.new("RGBA", s.size, rgb("#fff1cf"))
hi.putalpha(ImageChops.offset(a, int(.8 * SS), int(.9 * SS)).point(lambda v: int(v * .45)))
cv.im = Image.alpha_composite(Image.alpha_composite(layer, hi), ink)
return finish(cv, seed=len(name))
# ---------------------------------------------------------------- office crests
def office(kind):
cv = Cv(64)
sh = cv.poly([(32, 4), (56, 13), (56, 34), (32, 60), (8, 34), (8, 13)])
tint = {"crown": SP["brass"], "spice": SP["amber"], "water": SP["fremen2"]}[kind]
field = {"crown": "#6a4a38", "spice": "#8d5a37", "water": "#415f80"}[kind]
cv.fill(sh, SP["brass2"], SP["brass3"])
cv.bevel(sh, .4, .3, 1)
cv.edge(sh, SP["umber"], 1, .8)
inner = cv.poly([(32, 9), (51, 16), (51, 33), (32, 53), (13, 33), (13, 16)])
cv.fill(inner, mix(field, "#ffffff", .15), mix(field, SP["ink"], .3))
cv.edge(inner, SP["umber"], .6, .6)
if kind == "crown":
pts = [(18, 38), (17, 20), (25, 28), (32, 16), (39, 28), (47, 20), (46, 38)]
cv.solid(cv.line(pts + [pts[0]], 2.2), SP["brass2"])
for x, y in ((17, 20), (32, 16), (47, 20)):
cv.solid(cv.circle(x, y, 1.9), "#fff1c8")
elif kind == "spice":
d = cv.poly([(32, 14), (44, 30), (32, 48), (20, 30)])
warm_glow(cv, d, SP["amber"], 2.5, .5)
cv.fill(d, SP["amber2"], SP["terracotta"])
cv.edge(d, "#ffe9b8", .6, .7)
cv.solid(cv.line([(32, 14), (32, 48)], .7), "#fff1c8", .5)
else:
drop = cv.circle(32, 36, 11)
tri = cv.poly([(32, 12), (42, 31), (22, 31)])
full = ImageChops.lighter(drop, tri)
cv.fill(full, SP["water"], SP["fremen"])
cv.edge(full, "#e6f4f6", .6, .6)
cv.solid(cv.circle(28, 34, 2.4), "#ffffff", .75)
return finish(cv, seed=3)
# ---------------------------------------------------------------- spice, water, codex
def spice_crystal(tint_a, tint_b, glow, smuggled=False, dense=False):
cv = Cv(64)
base = cv.circle(32, 42, 17)
warm_glow(cv, base, glow, 7, .30 if not dense else .5)
shards = [([(32, 8), (42, 30), (32, 52), (22, 30)], 1.0), ([(16, 22), (24, 40), (14, 54), (8, 38)], .75),
([(48, 20), (56, 38), (48, 54), (40, 38)], .8)]
if dense:
shards.append(([(32, 24), (38, 40), (32, 58), (26, 40)], .9))
for pts, k in shards:
m = cv.poly(pts)
cv.fill(m, mix(tint_a, "#fff4d8", .10 * k), tint_b)
cv.bevel(m, .5, .3, 1)
cv.edge(m, SP["umber"], .7, .65)
# one soft inner facet
cx = sum(p[0] for p in pts) / 4
cv.solid(cv.clip(m, cv.poly([(cx, pts[0][1]), (pts[1][0], pts[1][1]), (cx, pts[2][1])])), "#fff1c6", .22)
if smuggled: # twine-bound in a scrap of dark cloth
band = cv.rrect(8, 47, 56, 52, 2)
cv.fill(band, SP["umber2"], SP["umber"])
cv.solid(cv.line([(8, 49.5), (56, 49.5)], .6), SP["fremen2"], .8)
dust(cv, [(38, 15), (46, 24), (19, 30)], "#fff3d2", .9, .85)
return finish(cv, seed=9)
def water_vial(tint="#5f93b8", smuggled=False):
cv = Cv(64)
glass = cv.rrect(22, 14, 42, 56, 8)
cv.fill(glass, "#eef7f6", SP["water"], .62)
liquid = cv.rrect(24, 28, 40, 54, 7)
cv.fill(liquid, SP["water"], mix(tint, SP["fremen"], .35))
cv.edge(glass, "#d9ecee", 1.0, .9)
cv.edge(glass, SP["umber2"], .5, .55)
cap = cv.rrect(24, 7, 40, 17, 2.5)
cv.fill(cap, SP["brass2"], SP["brass3"])
cv.edge(cap, SP["umber"], .6, .8)
cv.solid(cv.line([(26.5, 24), (26.5, 46)], 1.5), "#ffffff", .6)
if smuggled:
cv.solid(cv.rrect(21, 36, 43, 41, 1), SP["leather2"])
cv.solid(cv.line([(21, 38.5), (43, 38.5)], .5), SP["umber"], .7)
return finish(cv, seed=2)
def imperial_codex():
cv = Cv(64)
book = cv.rrect(12, 6, 52, 58, 4)
cv.fill(book, "#7c5438", "#4b3223")
cv.bevel(book, .3, .25, 1)
cv.edge(book, SP["umber"], 1, .85)
cv.solid(cv.rrect(12, 6, 18, 58, 2), "#3c281c")
for y in (14, 28, 42):
cv.solid(cv.line([(12, y), (18, y)], .9), SP["brass"], .9)
for cx, cy in ((46, 12), (46, 52)): # brass corner caps
cv.fill(cv.rrect(cx - 4, cy - 4, cx + 6, cy + 6, 1.5), SP["brass2"], SP["brass3"])
medal = gear(cv, 35, 32, 10, 10, .14, .3)
cv.fill(medal, SP["brass2"], SP["brass3"])
cv.edge(medal, SP["umber"], .5, .8)
cv.solid(cv.circle(35, 32, 2.6), SP["umber"], .8)
return finish(cv, seed=4)