Project 35: Wallpaper Gradient Weave 🖼️¶

Difficulty: 🟡 Intermediate

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/wallpaper_gradient_weave/.

← Back to index

Description¶

Weave multi-stop color gradients into phone wallpaper PNGs with optional noise speckles.

Libraries & Modules¶

  • PIL.Image
  • numpy

Python Concepts You'll Practice¶

Vectorized color interpolation, image pipelines

🎛️ Parameter Variations¶

  • STOPS colors
  • PORTRAIT size
  • SPECKLES density
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") / "wallpaper_gradient_weave"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\wallpaper_gradient_weave

Step 1 — Multi-stop gradient¶

In [3]:
import numpy as np
from PIL import Image

# 🎛️ TWEAK THESE
WIDTH, HEIGHT = 720, 1280
STOPS = [(20, 20, 30), (139, 30, 30), (240, 220, 200)]
SPECKLES = 800
SEED = 4

def expand_stops(stops, n):
    arr = np.zeros((n, 3))
    segs = len(stops) - 1
    for i in range(n):
        t = i / (n - 1) * segs
        k = min(int(t), segs - 1)
        local = t - k
        arr[i] = (1 - local) * np.array(stops[k]) + local * np.array(stops[k + 1])
    return arr

cols = expand_stops(STOPS, HEIGHT)
img_arr = np.tile(cols[:, None, :], (1, WIDTH, 1)).astype(np.uint8)
rng = np.random.default_rng(SEED)
for _ in range(SPECKLES):
    y, x = rng.integers(0, HEIGHT), rng.integers(0, WIDTH)
    img_arr[y, x] = np.clip(img_arr[y, x] + rng.integers(20, 60), 0, 255)
img = Image.fromarray(img_arr, mode="RGB")
print("Wallpaper canvas:", img.size)
display(img)
Wallpaper canvas: (720, 1280)
No description has been provided for this image

Step 2 — Export wallpaper¶

In [4]:
out = OUTPUT_DIR / "wallpaper_gradient.png"
img.save(out)
print(f"Saved → {out.resolve()}")
display(img)
Saved → C:\Users\Hansel Yan\Projects\CodeItAll\outputs\wallpaper_gradient_weave\wallpaper_gradient.png
No description has been provided for this image

✅ Project complete¶

Check your output folder: outputs/wallpaper_gradient_weave/

Next: Project 36: Typing Speed Lab · Index