103 lines
4.1 KiB
Python
103 lines
4.1 KiB
Python
"""Soft, hand-made Dune palette and drawing helpers for item artwork.
|
|
|
|
Design rule (the Butlerian Jihad): no screens, holograms, circuit lattices or neon. Futurism is carried by
|
|
clean machined geometry, brass, bone, sun-bleached cloth, spice-amber crystal and water-glass, drawn with soft
|
|
light and warm umber shadows instead of black outlines.
|
|
"""
|
|
import math
|
|
import numpy as np
|
|
from PIL import Image, ImageChops, ImageDraw, ImageFilter
|
|
from dunelib import Cv, SS, mix, rgb, FONT_BOLD
|
|
|
|
SP = dict(
|
|
ink="#2f231b", umber="#4a3426", umber2="#6b4b36", leather="#8a5c3b", leather2="#b27c52",
|
|
sand="#f1e4c3", sand2="#dcc594", dune="#c9a46d", dune2="#a98350", ochre="#d6a550",
|
|
amber="#e8a23c", amber2="#f5c872", terracotta="#b5694b", clay="#cc8f70", rose="#d1a090",
|
|
brass="#c39c50", brass2="#e6cb85", brass3="#8c6b33", bronze="#a4723f", copper="#c47f58",
|
|
pewter="#9b9a8f", pewter2="#cfcbb9", bone="#f0e7cf", bone2="#cfc2a2",
|
|
fremen="#41699f", fremen2="#86abd3", water="#a6d4df", water2="#5f93b8",
|
|
sage="#8e9b6c", dusk="#7d5d72", dusk2="#a98ab0", ember="#d8744d", night="#2b2a33",
|
|
)
|
|
# quality tiers, softened: dust, sage, fremen blue, dusk violet, spice gold, ember
|
|
QUAL = ["#d9cdb2", "#9db37d", "#7da7d4", "#aa8cc6", "#e6b45c", "#dc7a50"]
|
|
|
|
|
|
def umber_edge(cv, mask, width=0.9, alpha=0.85, color=None):
|
|
cv.edge(mask, color or SP["umber"], width, alpha)
|
|
|
|
|
|
def soft_body(cv, mask, hi, lo, edge=None, ew=0.9, light=0.38, dark=0.22, d=1.1):
|
|
"""gradient + gentle bevel + warm umber outline, the standard soft material"""
|
|
cv.fill(mask, hi, lo)
|
|
cv.bevel(mask, light, dark, d)
|
|
cv.edge(mask, edge or SP["umber"], ew, 0.8)
|
|
|
|
|
|
def warm_glow(cv, mask, color, radius, strength=0.35):
|
|
cv.glow(mask, color, radius, strength)
|
|
|
|
|
|
def rivet(cv, x, y, r=1.4, color=None):
|
|
cv.solid(cv.circle(x + .3, y + .5, r), SP["umber"], .55)
|
|
cv.fill(cv.circle(x, y, r), SP["brass2"], SP["brass3"])
|
|
cv.solid(cv.circle(x - r * .3, y - r * .3, r * .35), "#fff6d8", .8)
|
|
|
|
|
|
def gear(cv, cx, cy, r, teeth=10, depth=0.16, hole=0.38):
|
|
"""machined cog: the 'old-school futuristic' motif"""
|
|
pts = []
|
|
n = teeth * 4
|
|
for i in range(n):
|
|
a = 2 * math.pi * i / n
|
|
k = i % 4
|
|
rr = r * (1 + depth) if k in (1, 2) else r * (1 - depth * .4)
|
|
pts.append((cx + rr * math.cos(a), cy + rr * math.sin(a)))
|
|
m = cv.poly(pts)
|
|
if hole:
|
|
m = ImageChops.subtract(m, cv.circle(cx, cy, r * hole))
|
|
return m
|
|
|
|
|
|
def worm_arc(cv, cx, cy, r, color, w=2.2, a=1.0, segments=9, start=200):
|
|
"""segmented sandworm crescent"""
|
|
for i in range(segments):
|
|
t0 = math.radians(start + i * 17)
|
|
t1 = t0 + math.radians(13)
|
|
pts = [(cx + r * math.cos(t0), cy + r * math.sin(t0)), (cx + r * math.cos(t1), cy + r * math.sin(t1))]
|
|
cv.solid(cv.line(pts, w * (0.55 + 0.45 * math.sin(i / max(1, segments - 1) * math.pi))), color, a)
|
|
|
|
|
|
def dust(cv, pts, color="#fff3d2", r=0.9, a=0.8):
|
|
for x, y in pts:
|
|
cv.solid(cv.circle(x, y, r), color, a)
|
|
|
|
|
|
def engrave(cv, mask, color=None, off=0.7):
|
|
"""inset lettering: dark body with a light lower lip"""
|
|
lip = ImageChops.offset(mask, int(off * SS), int(off * SS))
|
|
cv.solid(ImageChops.subtract(lip, mask), "#fff3d4", .55)
|
|
cv.solid(mask, color or SP["umber"], .92)
|
|
|
|
|
|
def finish(cv, size=None, shadow=0.26, grain=0.018, seed=1):
|
|
"""soft contact shadow + faint paper grain, then downsample"""
|
|
im = cv.im
|
|
a = im.getchannel("A")
|
|
sh = a.filter(ImageFilter.GaussianBlur(1.3 * SS))
|
|
sh = ImageChops.offset(sh, int(0.9 * SS), int(1.3 * SS))
|
|
sh = sh.point(lambda v: int(v * shadow))
|
|
under = Image.new("RGBA", im.size, rgb(SP["umber"]))
|
|
under.putalpha(sh)
|
|
out = Image.alpha_composite(under, im)
|
|
if grain:
|
|
rng = np.random.default_rng(seed)
|
|
arr = np.asarray(out, dtype=np.float32)
|
|
noise = rng.normal(0, grain * 255, arr.shape[:2])[..., None]
|
|
arr[..., :3] = np.clip(arr[..., :3] + noise * (arr[..., 3:4] / 255.0), 0, 255)
|
|
out = Image.fromarray(arr.astype(np.uint8), "RGBA")
|
|
s = size or (cv.w, cv.h)
|
|
return out.resize(s, Image.LANCZOS)
|
|
|
|
|
|
def tint_of(tier):
|
|
return QUAL[tier]
|

Staff