Project 29: Noise Texture Studio 🌫️¶
Difficulty: 🟡 Intermediate
Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/noise_texture_studio/.
Description¶
Synthesize Perlin-ish value noise and export abstract texture PNGs for wallpapers or game art.
Libraries & Modules¶
numpymatplotlib.pyplot/PIL
Python Concepts You'll Practice¶
Array broadcasting, interpolation, colormap styling
🎛️ Parameter Variations¶
SIZE,SCALE,SEEDCMAP— matplotlib colormap name
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline
from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame
OUTPUT_DIR = Path("outputs") / "noise_texture_studio"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\noise_texture_studio
Step 1 — Build smooth noise¶
In [3]:
import numpy as np
# 🎛️ TWEAK THESE
SIZE = 256
SCALE = 8
SEED = 9
rng = np.random.default_rng(SEED)
grid = rng.random((SCALE + 1, SCALE + 1))
ys = np.linspace(0, SCALE, SIZE)
xs = np.linspace(0, SCALE, SIZE)
y0 = np.floor(ys).astype(int)
x0 = np.floor(xs).astype(int)
yf = ys - y0
xf = xs - x0
y1 = np.clip(y0 + 1, 0, SCALE)
x1 = np.clip(x0 + 1, 0, SCALE)
# bilinear sample
n = np.zeros((SIZE, SIZE))
for i in range(SIZE):
for j in range(SIZE):
g00 = grid[y0[i], x0[j]]
g01 = grid[y0[i], x1[j]]
g10 = grid[y1[i], x0[j]]
g11 = grid[y1[i], x1[j]]
top = g00 * (1 - xf[j]) + g01 * xf[j]
bot = g10 * (1 - xf[j]) + g11 * xf[j]
n[i, j] = top * (1 - yf[i]) + bot * yf[i]
print("Noise range:", float(n.min()), "→", float(n.max()))
Noise range: 0.00880132062901735 → 0.9861444522474868
Step 2 — Colorize + save¶
In [4]:
import matplotlib.pyplot as plt
# 🎛️ TWEAK THESE
CMAP = "magma"
fig, ax = plt.subplots(figsize=(6, 6))
ax.imshow(n, cmap=CMAP, origin="upper")
ax.axis("off")
ax.set_title("Noise Texture Studio")
fig.tight_layout(pad=0.2)
out = OUTPUT_DIR / "noise_texture.png"
fig.savefig(out, dpi=160, bbox_inches="tight", pad_inches=0.05)
plt.show()
np.save(OUTPUT_DIR / "noise.npy", n)
print(f"Saved {out}")
Saved outputs\noise_texture_studio\noise_texture.png