Files
grass-cutters/ArtSource/Textures/proc_grass.py
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

70 lines
2.9 KiB
Python

"""Procedural tiling textures for GRASS CUTTER (used when gpt-image is rate limited):
T_Hay (criss-cross straw), T_Burlap (jute weave), T_Brick (pressed green fibre). 512², seamless by construction."""
import os
import numpy as np
from PIL import Image, ImageFilter
HERE = os.path.dirname(os.path.abspath(__file__))
TEX = os.path.join(HERE, "..", "..", "Assets", "Art", "Textures")
N = 512
rng = np.random.default_rng(7)
def strands(count, length, width, palette, angle_jitter, base, blur=0.6):
img = np.zeros((N, N, 3), np.float32) + np.array(base, np.float32)
yy, xx = np.mgrid[0:N, 0:N]
for _ in range(count):
cx, cy = rng.uniform(0, N, 2)
a = rng.uniform(-angle_jitter, angle_jitter) + (0 if rng.random() < 0.5 else np.pi / 2) * (angle_jitter < 1)
dx, dy = np.cos(a), np.sin(a)
col = np.array(palette[rng.integers(len(palette))], np.float32) * rng.uniform(0.85, 1.1)
L = length * rng.uniform(0.6, 1.3)
w = width * rng.uniform(0.6, 1.4)
# wrap-around distance so the texture tiles
px = (xx - cx + N / 2) % N - N / 2
py = (yy - cy + N / 2) % N - N / 2
t = px * dx + py * dy
d = np.abs(-px * dy + py * dx)
m = (np.abs(t) < L / 2) & (d < w)
shade = 1.0 - (d / w) * 0.35
img[m] = col * shade[m, None]
im = Image.fromarray(np.clip(img, 0, 255).astype(np.uint8))
return im.filter(ImageFilter.GaussianBlur(blur))
def hay():
pal = [(232, 196, 92), (214, 176, 74), (240, 214, 130), (196, 170, 70), (170, 168, 72), (226, 186, 100)]
im = strands(2600, 120, 2.2, pal, 0.5, (150, 120, 50))
im.save(os.path.join(TEX, "T_Hay.png"))
def burlap():
yy, xx = np.mgrid[0:N, 0:N].astype(np.float32)
k = 2 * np.pi * 32 / N
warp = np.sin(xx * k) * 0.5 + 0.5
weft = np.sin(yy * k) * 0.5 + 0.5
check = (np.sin(xx * k / 2) * np.sin(yy * k / 2) > 0)
v = np.where(check, warp ** 0.6, weft ** 0.6)
noise = np.asarray(Image.fromarray((rng.random((N // 8, N // 8)) * 255).astype(np.uint8)).resize((N, N), Image.BICUBIC), np.float32) / 255
base = np.array([196, 160, 108], np.float32)
col = base[None, None] * (0.62 + 0.42 * v[..., None]) * (0.9 + 0.2 * noise[..., None])
Image.fromarray(np.clip(col, 0, 255).astype(np.uint8)).filter(ImageFilter.GaussianBlur(0.5)).save(os.path.join(TEX, "T_Burlap.png"))
def brick():
pal = [(64, 110, 38), (82, 128, 46), (52, 88, 34), (104, 136, 54), (74, 96, 40), (120, 150, 70)]
im = strands(3600, 40, 2.6, pal, 3.2, (46, 72, 28), blur=0.7)
im.save(os.path.join(TEX, "T_Brick.png"))
def clippings():
pal = [(118, 186, 58), (140, 204, 70), (96, 160, 44), (168, 214, 92), (124, 176, 52), (196, 210, 110)]
im = strands(3000, 46, 2.2, pal, 3.2, (78, 128, 36), blur=0.6)
im.save(os.path.join(TEX, "T_Clippings.png"))
if __name__ == "__main__":
hay(); burlap(); brick(); clippings()
print("procedural textures written")