Skip to content

Creative Coding Helpers

What the creative coding starters' helpers.h and noise.h give a sketch, and what each part of the maths is for.

The starters

Each starter's main.c has a "Your sketch" part that a prompt's sample replaces; everything else (the window, the loop, the keys) stays the same. All three keep time in t, growing by 0.05 a frame. Keys: S saves a PNG, R picks the next seed (noise, cellrand and random numbers change), Space pauses.

Starter Picture The sketch is
raylib pixels 300 × 300, each pixel drawn 2 × 2 static RGB shade(float x, float y, float t), called for every pixel
raylib shapes 600 × 600, kept between frames static void draw(float t) with raylib's Draw... functions, clear(c), fade(c, alpha), PAPER, INK
raylib particles 600 × 600, kept between frames #define N, spawn(Particle *p), frame(Particle *ps, float t); a Particle has pos, last, age, life, k

helpers.h

Numbers are float; colours are RGB, three floats from 0 to 1, so patterns combine before they become a raylib Color.

Helper Gives
wave(v) 0.5 + 0.5 × sin(v): any number to a smooth repeat in 0..1
fract(v) the part after the decimal point: 3.75 gives 0.75
clamp01(v) v kept to 0..1
smoothstep(a, b, v) 0 below a, 1 above b, an S-curve between
mix(a, b, k) part of the way from a to b (lerp)
dist(x, y, cx, cy) the distance between two points
remap(v, a, b, c, d) v moved from the range a..b to c..d
rgb(r, g, b), grey(v), hex(0x0D080D) a colour
scale(c, k), mixc(a, b, k) a colour made darker, or part of the way to another
palette(v, a, b, c, d) the cosine palette: v in 0..1 to a colour
rainbow(v), sea(v), acid(v), ember(v) four ready-made palettes
toColor(c) an RGB as a raylib Color
plasma(x, y, cx, cy) four sine waves added, −1..1
frand(a, b) a random number from a to b (raylib's generator)

noise.h

Helper Gives
noise2(x, y), noise3(x, y, z) smooth noise, about 0..1, four octaves (like p5.js noise())
perlin3(x, y, z) one octave, about −1..1
cellrand(i, j) a random 0..1 for a grid cell, the same every frame
noise_seed(n) which noise and cellrand you get

What each piece of maths is for

Maths Gives Use it for
x ^ y, x & y 0..511 (use % 256) squares inside squares, the Sierpinski triangle
a % n, fmodf(a, n) 0 to n − 1, repeating repeating anything: tiles, stripes
floor(x / s) a cell number grids, checkerboards, posterising
sin(v), cos(v) −1..1, repeating waves, circles, anything that pulses
wave(v) 0..1, repeating the same, ready to use as a value
dist(x, y, cx, cy) 0 and up rings, round gradients, masks
atan2(dy, dx) −π..π rays, spirals, kaleidoscopes
noise3(x, y, t) about 0..1, smooth natural shapes, warping, flow fields, change over time
frand(0, 1) 0..1, unrelated choices in grid cells
mix(a, b, k) between a and b blending, moving, gradients
smoothstep(a, b, v) 0..1 with a soft edge masks, soft thresholds
remap(v, a, b, c, d) v in a new range turning one range into another
abs(x − 150) a mirrored value symmetry
palette(v) a colour turning one value into good colours