home/ modules/ color-layers-and-pixel-processing

Colour, layers, and pixel-level image processing

  • learner can control colour with HSB mode, gradients, and blend modes across stacked layers
  • learner can draw into off-screen PGraphics/framebuffer layers and cross-dissolve them
  • learner can read and rewrite the pixels[] array to build image filters, palette extraction, and pixel-mapped renders

Take a source photo and produce a layered, recoloured piece: extract its palette, remap its pixels into drawn tiles or a convolution filter, and composite the result across blend-moded PGraphics layers.

This module builds the image-transformation half of a live-visuals practice: taking found imagery and reprocessing it into something that reads as yours on a projector. In a VJ or audiovisual set, raw photos and camera feeds rarely work as-is — they need recolouring to match the set’s palette, restructuring into tiles or filtered textures that move with the music, and compositing so multiple visual voices coexist on one screen. That whole pipeline — source image in, layered recoloured artwork out — is the capstone task.

The arc starts supported and on-canvas: switch to HSB so hue becomes a single controllable axis, then build gradients by lerping colours in a loop, then stack simple shapes under different blend modes and watch LIGHTEST and DIFFERENCE change the composite. Next the work moves off-screen — “PGraphics is an independent off-screen drawing layer” is the JIT pointer when your first layered sketch needs elements composed separately, and “cross-dissolving two layers per pixel with lerpColor()” shows how two buffers become one animated transition. Finally you drop to the pixel level: loadPixels() and the row-major index formula unlock palette extraction by sampling and sorting, pixel-mapping into drawn substitutes, brightness-driven tile rasterization, and convolution kernels for blur and sharpen.

Every required atom is load-bearing for the capstone: you cannot extract a palette without pixels[] access and 2D grid iteration, cannot remap into tiles without the brightness-to-size move, and cannot composite the final piece without PGraphics layers and blend modes. The supporting atoms enrich rather than gate — alpha-accumulation traces, continuous cellular automata, and frame differencing point at where this pixel toolkit goes next: generative textures and live camera input. Drill the gradient loop, pixels[] indexing, and nested grid iteration until they are automatic; everything else in the module rides on them.

Runnable examples

Generated from the context/ instrument corpus by concept (redistributable idioms only). Do not edit — regenerate with gen-module-examples.mjs.

feedback-trail

osc(4).modulate(src(o0), 0.6).out(o0)

hydra-0022 · CC0-1.0

function draw(){ fill(0, 20); rect(0, 0, width, height); circle(mouseX, mouseY, 40) }

p5live-0003 · CC0-1.0

palette-cycle

osc(30, 0.1, 1).colorama(0.1).out()

hydra-0015 · CC0-1.0

hsvrgb [fract (ft/6.28 + 0.1*time), 1, 1] >> rgb

punctual-0024 · CC0-1.0

hue-shift

osc(30).hue(() => time * 0.1).out()

hydra-0016 · CC0-1.0

hsvrgb [fract (ft/6.28 + 0.1*time), 1, 1] >> rgb

punctual-0024 · CC0-1.0

gradient-ramp

gradient(0.3).out()

hydra-0170 · MIT

[fr, fr*0.5, 1-fr] >> rgb

punctual-0033 · CC0-1.0

grain-glitch

col += (h21(st + fract(u_time)) - 0.5) * 0.15;

glsl-0026 · public-domain

blur-soften

filter(BLUR, 4)

p5live-0073 · CC0-1.0

pixel-manipulation

loadPixels(); for(let i=0;i<pixels.length;i+=4) pixels[i]=255; updatePixels()

p5live-0030 · CC0-1.0

Atoms in this module

Required — these gate the capstone

colorMode(HSB) makes hue, saturation, and brightness independently controllable axes
Concept L2 First instrument H
lerpColor() over a for-loop of stacked lines builds a smooth gradient in p5.js
Procedure L2 First instrument H
blendMode() controls how overlapping layers combine in p5.js (e.g. LIGHTEST keeps the brighter pixel)
Concept L2 First instrument H
Processing's PGraphics is an independent off-screen drawing layer with its own coordinate system and settings
Concept L2 First instrument HL
p5.Framebuffer is an off-screen GPU surface you can draw to and then reuse as a texture
Concept L3 Craft HG
Cross-dissolving two layers per pixel with lerpColor() and a coordinate-dependent wave makes non-uniform wave transitions
Procedure L3 Craft H
Processing's pixels[] array gives direct read-write access to every pixel of the display window
Concept L3 Craft H
Sampling an image's pixels and sorting the resulting colours by hue, saturation, or brightness extracts its palette
Procedure L2 First instrument H
Pixel mapping replaces each pixel of a source image with a drawn element sized or coloured by that pixel's value
Procedure L2 First instrument H
Mapping source brightness to tile size rasterizes an image into a halftone-like grid where dark areas make smaller tiles
Procedure L3 Craft H
Image convolution applies a kernel matrix to each pixel's neighbourhood to produce blur and sharpen filters
Concept L3 Craft H
Processing's blend() and filter() apply compositing modes and pixel filters to images
Concept L3 Craft H
Two-dimensional arrays in Processing store grid data as arrays of arrays
Concept L2 First instrument H

Supporting — enrichment, not gating

Drawing with semi-transparent fill and no background clear lets shapes accumulate as a trace
Concept L1 Foundations H
Semi-transparent marks accumulate in visual density where shapes overlap most
Principle L2 First instrument H
Arrays in Processing store multiple values under one name, accessed by zero-based index
Concept L2 First instrument H
Cellular automata with continuous state values (0–255) produce fluid wave-like patterns
Concept L3 Craft H
Frame differencing detects motion by comparing pixel values between consecutive video frames
Concept L3 Craft H
A light grain pass over the final composite is the most reliable 'make it look intentional' move — it unifies layers and hides banding
Principle L2 First instrument HGL
A blurred copy of the image added back via screen or add blend is a cheap bloom/glow effect
Concept L2 First instrument HG
CPU pixel manipulation reads and writes the raw RGBA array directly, unlike a per-pixel GPU shader
Concept L2 First instrument LH
Psychedelic palettes are highly saturated complementary/triadic hues always in motion via palette-cycle — color must never settle
Concept L2 First instrument HL