Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created November 15, 2026 19:27
Show Gist options
  • Select an option

  • Save unitycoder/deac7de96b749675ce133c87e1f95474 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/deac7de96b749675ce133c87e1f95474 to your computer and use it in GitHub Desktop.
Suopursu generator python
import math, random, sys
from PIL import Image, ImageDraw, ImageFilter
import numpy as np
SEED = int(sys.argv[1]) if len(sys.argv) > 1 else 7
OUT = sys.argv[2] if len(sys.argv) > 2 else "suopursu_billboard.png"
random.seed(SEED)
SIZE = 1024
SS = 3
W = H = SIZE * SS
img = Image.new("RGBA", (W, H), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
def S(v):
return v * SS
def jitter(c, a=12):
return tuple(max(0, min(255, int(x + random.uniform(-a, a)))) for x in c)
def shade(c, f):
return tuple(max(0, min(255, int(x * f))) for x in c)
def leaf(x, y, ang, L, Wd, depth):
"""Narrow lanceolate leaf with rolled edges; depth 0..1 (0 = back)."""
underside = random.random() < 0.16
if underside:
base = jitter((150, 92, 48), 14) # rusty felt underside
else:
base = jitter((52, 92, 44), 10) # dark leathery green
base = shade(base, 0.62 + 0.5 * depth)
ca, sa = math.cos(ang), math.sin(ang)
droop = random.uniform(-0.25, 0.25)
pts_l, pts_r, mid = [], [], []
n = 10
for i in range(n + 1):
t = i / n
# curved centreline
cx = x + ca * L * t - sa * droop * L * t * t
cy = y + sa * L * t + ca * droop * L * t * t
w = Wd * (math.sin(math.pi * t ** 0.8) ** 0.9) * (1 - 0.25 * t)
nx, ny = -sa, ca
pts_l.append((cx + nx * w, cy + ny * w))
pts_r.append((cx - nx * w, cy - ny * w))
mid.append((cx, cy))
poly = pts_l + pts_r[::-1]
d.polygon(poly, fill=base + (255,))
# darker rolled edge on one side, lighter midrib
d.line(pts_r, fill=shade(base, 0.72) + (255,), width=max(1, int(S(0.9))))
rib = (198, 150, 90) if underside else shade(base, 1.45)
d.line(mid[:-1], fill=rib + (255,), width=max(1, int(S(0.8))))
def flower(x, y, r, depth):
rot = random.uniform(0, math.tau)
white = shade(jitter((246, 246, 236), 5), 0.86 + 0.14 * depth)
for k in range(5):
a = rot + k * math.tau / 5
px, py = x + math.cos(a) * r * 0.62, y + math.sin(a) * r * 0.62
pet = Image.new("RGBA", (int(r * 2.2), int(r * 1.3)), (0, 0, 0, 0))
pd = ImageDraw.Draw(pet)
pd.ellipse((0, 0, pet.width - 1, pet.height - 1), fill=white + (255,))
pet = pet.rotate(-math.degrees(a), expand=True, resample=Image.BICUBIC)
img.alpha_composite(pet, (int(px - pet.width / 2), int(py - pet.height / 2)))
# long stamens
for k in range(8):
a = rot + k * math.tau / 8 + random.uniform(-0.2, 0.2)
ex, ey = x + math.cos(a) * r * 1.25, y + math.sin(a) * r * 1.25
d.line((x, y, ex, ey), fill=(236, 238, 222, 255), width=max(1, int(S(0.6))))
d.ellipse((ex - S(0.9), ey - S(0.9), ex + S(0.9), ey + S(0.9)), fill=(214, 196, 120, 255))
d.ellipse((x - r * 0.3, y - r * 0.3, x + r * 0.3, y + r * 0.3), fill=(176, 196, 96, 255))
def umbel(x, y, R, depth):
"""Dome-shaped cluster of small white flowers on thin pedicels."""
n = random.randint(16, 24)
spots = []
for i in range(n):
a = random.uniform(math.pi * 1.02, math.pi * 1.98) # upper half
rr = R * math.sqrt(random.uniform(0.05, 1))
fx = x + math.cos(a) * rr * 1.15
fy = y + math.sin(a) * rr * 0.85 - R * 0.15
spots.append((fx, fy))
for fx, fy in spots:
d.line((x, y, fx, fy), fill=shade((150, 160, 84), 0.8 + 0.2 * depth) + (255,),
width=max(1, int(S(1.0))))
spots.sort(key=lambda p: -p[1] if False else p[1])
for fx, fy in spots:
flower(fx, fy, S(random.uniform(6.5, 8.5)), depth)
def leaf_whorl(x, y, heading, depth, count, Lmin, Lmax):
for _ in range(count):
side = random.choice((-1, 1))
a = heading + side * random.uniform(0.5, 1.5) + random.uniform(-0.15, 0.15)
L = S(random.uniform(Lmin, Lmax))
leaf(x, y, a, L, L * random.uniform(0.10, 0.14), depth)
def stem(x, y, ang, length, thick, depth, level=0):
"""Grow a woody stem upward; returns nothing, draws as it goes."""
steps = max(6, int(length / S(9)))
seg = length / steps
pts = [(x, y)]
bend = random.uniform(-0.012, 0.012)
for i in range(steps):
t = i / steps
ang += bend + random.uniform(-0.035, 0.035)
# tend back toward vertical
ang += (-math.pi / 2 - ang) * 0.03
x += math.cos(ang) * seg
y += math.sin(ang) * seg
pts.append((x, y))
# side branch
if level < 2 and 0.3 < t < 0.8 and random.random() < 0.10:
ba = ang + random.choice((-1, 1)) * random.uniform(0.35, 0.75)
branches.append((x, y, ba, length * (1 - t) * random.uniform(0.7, 1.0),
thick * (1 - t * 0.5) * 0.7, depth, level + 1))
# draw wood: old wood grey-brown at base, rusty hairy shoots at tips
for i in range(len(pts) - 1):
t = i / (len(pts) - 1)
old = (96, 74, 58)
young = (158, 96, 52)
c = tuple(int(old[k] + (young[k] - old[k]) * t ** 1.5) for k in range(3))
c = shade(c, 0.65 + 0.45 * depth)
w = max(S(1.6), thick * (1 - 0.6 * t))
d.line((pts[i], pts[i + 1]), fill=c + (255,), width=int(w))
d.ellipse((pts[i + 1][0] - w / 2, pts[i + 1][1] - w / 2,
pts[i + 1][0] + w / 2, pts[i + 1][1] + w / 2), fill=c + (255,))
# leaves: sparse low, dense toward tip
for i in range(2, len(pts)):
t = i / (len(pts) - 1)
if t < 0.22:
continue
if random.random() < 0.25 + 0.75 * t:
heading = math.atan2(pts[i][1] - pts[i - 1][1], pts[i][0] - pts[i - 1][0])
leaf_whorl(pts[i][0], pts[i][1], heading, depth,
random.randint(1, 2 + int(2 * t)), 26, 44)
# terminal rosette + flowers
heading = math.atan2(pts[-1][1] - pts[-2][1], pts[-1][0] - pts[-2][0])
tips.append((pts[-1][0], pts[-1][1], heading, depth, level))
branches, tips = [], []
ground = H - S(6)
# main stems, back to front
main = []
N = 11
for i in range(N):
depth = i / (N - 1)
bx = W / 2 + random.uniform(-0.17, 0.17) * W
lean = (bx - W / 2) / (0.17 * W)
ang = -math.pi / 2 + lean * random.uniform(0.10, 0.34) + random.uniform(-0.08, 0.08)
length = S(random.uniform(560, 800)) * (0.85 + 0.15 * (1 - abs(lean)))
main.append((bx, ground, ang, length, S(random.uniform(7, 10)), depth, 0))
for m in main:
branches.clear(); tips.clear()
stem(*m)
while branches:
b = branches.pop(0)
stem(*b)
for (tx, ty, heading, depth, level) in tips:
# rosette of leaves under the flower head
for k in range(random.randint(9, 13)):
a = heading + random.uniform(-2.0, 2.0)
L = S(random.uniform(30, 46))
leaf(tx, ty, a, L, L * random.uniform(0.10, 0.14), depth)
if random.random() < 0.78:
umbel(tx, ty - S(4), S(random.uniform(30, 40)), depth)
else: # unopened bud / new shoot
d.ellipse((tx - S(5), ty - S(9), tx + S(5), ty + S(3)),
fill=shade((170, 120, 70), 0.7 + 0.3 * depth) + (255,))
# small tuft of leaves at the base to hide stem feet
for _ in range(34):
bx = W / 2 + random.gauss(0, 0.11) * W
a = -math.pi / 2 + random.uniform(-1.1, 1.1)
L = S(random.uniform(30, 52))
leaf(bx, ground - S(random.uniform(0, 26)), a, L, L * 0.12, random.uniform(0.5, 1))
# crop to content (bottom-anchored square) so the plant fills the texture
l, t, r, b = img.getbbox()
side = max(r - l, H - t) + S(16)
cx = (l + r) // 2
sq = Image.new("RGBA", (side, side), (0, 0, 0, 0))
sq.alpha_composite(img.crop((max(0, cx - side // 2), H - side if side <= H else 0,
min(W, cx + side // 2), H)),
(max(0, side // 2 - cx), max(0, side - H)))
img = sq
# downsample
img = img.resize((SIZE, SIZE), Image.LANCZOS)
# subtle top-lit gradient (brighter at top, darker near ground)
arr = np.asarray(img).astype(np.float32)
grad = np.linspace(1.08, 0.78, SIZE)[:, None, None]
arr[..., :3] = np.clip(arr[..., :3] * grad, 0, 255)
# colour bleed into transparent pixels so cutout edges / mips don't get dark halos
rgb = arr[..., :3].copy()
a = arr[..., 3]
known = a > 8
rgb[~known] = 0
for _ in range(48):
if known.all():
break
acc = np.zeros_like(rgb); cnt = np.zeros(a.shape, np.float32)
for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)):
sk = np.roll(known, (dy, dx), (0, 1)); sr = np.roll(rgb, (dy, dx), (0, 1))
acc += sr * sk[..., None]; cnt += sk
new = (~known) & (cnt > 0)
rgb[new] = acc[new] / cnt[new][:, None]
known = known | new
rgb[~known] = (60, 95, 50)
out = np.dstack([rgb, a]).clip(0, 255).astype(np.uint8)
Image.fromarray(out, "RGBA").save(OUT)
# preview on grey
prev = Image.new("RGBA", (SIZE, SIZE), (120, 130, 120, 255))
prev.alpha_composite(Image.fromarray(out, "RGBA"))
prev.convert("RGB").save(OUT.replace(".png", "_preview.jpg"), quality=88)
print("ok", OUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment