"""Moonwater textures (run with local/hear-venv python): pale sand (seamless), palm frond (alpha), grass tuft (alpha), palm bark (seamless vertically). Writes PNGs beside this file.""" import numpy as np, pathlib from PIL import Image, ImageDraw, ImageFilter HERE = pathlib.Path(__file__).parent rng = np.random.default_rng(7) def fft_noise(n, beta, seed): r = np.random.default_rng(seed) f = np.fft.fftfreq(n) k = np.sqrt(f[:, None] ** 2 + f[None, :] ** 2) k[0, 0] = 1 spec = (r.normal(size=(n, n)) + 1j * r.normal(size=(n, n))) / k ** beta spec[0, 0] = 0 a = np.real(np.fft.ifft2(spec)) return (a - a.min()) / (a.max() - a.min()) def sand(): n = 512 y, x = np.mgrid[0:n, 0:n] / n warp = fft_noise(n, 1.6, 1) # small wind ripples, 6 per tile, wavy (integer frequency keeps it seamless) ripple = 0.5 + 0.5 * np.sin(2 * np.pi * (6 * y + 0.9 * (warp - 0.5))) ripple = ripple ** 3 grain = rng.random((n, n)) blot = fft_noise(n, 1.2, 2) v = 0.80 + 0.07 * ripple + 0.06 * (grain - 0.5) + 0.08 * (blot - 0.5) base = np.array([238, 226, 200]) / 255.0 img = np.clip(v[..., None] * base[None, None, :] * 1.08, 0, 1) # sparse darker and lighter specks (shell bits, dark grains) specks = rng.random((n, n)) img[specks > 0.997] *= 0.6 img[specks < 0.002] = np.minimum(1, img[specks < 0.002] * 1.15) Image.fromarray((img * 255).astype(np.uint8)).save(HERE / "sand_pale.png") def frond(): w, h = 512, 256 im = Image.new("RGBA", (w, h), (0, 0, 0, 0)) d = ImageDraw.Draw(im) cy = h // 2 n = 44 for i in range(n): t = (i + 0.5) / n x0 = 10 + t * (w - 30) L = (h * 0.46) * (1 - t) ** 0.45 * min(1, 0.25 + t * 5) for side in (-1, 1): ang = np.radians(38 + 10 * t) * 1 x1 = x0 + L * np.cos(ang) * 0.9 y1 = cy + side * L * np.sin(ang) g = 0.75 + 0.25 * rng.random() col = (int(70 * g), int(122 * g + 20 * t), int(48 * g), 255) # leaflet as a thin tapered polygon wd = 4.5 * (1 - 0.4 * t) nx, ny = -(y1 - cy), (x1 - x0) nl = np.hypot(nx, ny) + 1e-6 nx, ny = nx / nl * wd, ny / nl * wd d.polygon([(x0 - nx * 0.3, cy - ny * 0.3), (x0 + (x1 - x0) * 0.45 + nx, cy + (y1 - cy) * 0.45 + ny), (x1, y1), (x0 + (x1 - x0) * 0.45 - nx, cy + (y1 - cy) * 0.45 - ny)], fill=col) d.line([(x0, cy), (x1, y1)], fill=(int(60 * g), int(100 * g), int(40 * g), 255), width=1) d.line([(4, cy), (w - 12, cy)], fill=(120, 110, 60, 255), width=5) d.line([(w * 0.6, cy), (w - 6, cy)], fill=(110, 120, 60, 255), width=3) im = im.filter(ImageFilter.SMOOTH) a = np.array(im) a[..., 3] = np.where(a[..., 3] > 110, 255, 0) Image.fromarray(a).save(HERE / "frond.png") def grass(): w, h = 256, 256 im = Image.new("RGBA", (w, h), (0, 0, 0, 0)) d = ImageDraw.Draw(im) for i in range(70): bx = w / 2 + rng.normal(0, 16) lean = float(np.clip(rng.normal(0, 0.45), -0.9, 0.9)) L = h * (0.45 + 0.5 * rng.random()) tipx, tipy = bx + lean * L * 0.6, h - L midx = bx + lean * L * 0.2 g = 0.6 + 0.4 * rng.random() dry = rng.random() < 0.3 col = (int((150 if dry else 95) * g), int((150 if dry else 140) * g), int((80 if dry else 60) * g), 255) d.polygon([(bx - 2.5, h), (midx, h - L * 0.5), (tipx, tipy), (bx + 2.5, h)], fill=col) a = np.array(im.filter(ImageFilter.SMOOTH)) a[..., 3] = np.where(a[..., 3] > 100, 255, 0) Image.fromarray(a).save(HERE / "grass.png") def bark(): w, h = 256, 512 y, x = np.mgrid[0:h, 0:w] n = fft_noise(512, 1.4, 3)[:h, :w] rings = 0.5 + 0.5 * np.cos(2 * np.pi * 14 * y / h + 0.6 * np.sin(2 * np.pi * x / w)) rings = rings ** 6 v = 0.62 + 0.18 * (n - 0.5) - 0.2 * rings + 0.05 * (rng.random((h, w)) - 0.5) base = np.array([150, 128, 100]) / 255.0 img = np.clip(v[..., None] * base[None, None, :] * 1.3, 0, 1) Image.fromarray((img * 255).astype(np.uint8)).save(HERE / "bark.png") sand(); frond(); grass(); bark() print("ok")