Building a Piece Step by Step
Start with one simple pattern that looks fine, then add one change at a time and look after each. If a change makes it worse, take it out. The final picture never needs planning.
How it works¶
Each step below is the one before with one thing added: a warp (Domain Warping), colour (Cosine Palette), texture at a low weight (Layering Detail at a Low Weight), a mask (Masks) and time (Animating a Pattern with Time). Each is a small change to a working sketch, so when something goes wrong it is obvious which change did it.
From step 6, try one change at a time: the spiral from Angle around a Point instead of the rings, a mirror from Symmetry and Kaleidoscopes, or sea, acid or ember instead of rainbow. Each gives a new piece.
The C is for the raylib pixels starter.
Step 1: rings¶
Simple, but it already looks like something.
static RGB shade(float x, float y, float t)
{
float d = dist(x, y, 150, 150);
return grey(wave(d * 0.1f));
}
function shade(x, y, t) {
let d = dist(x, y, 150, 150);
return grey(wave(d * 0.1));
}
Step 2: bend them with noise¶
Noise added to the distance, so the rings wobble.
static RGB shade(float x, float y, float t)
{
float n = noise2(x * 0.01f, y * 0.01f);
float d = dist(x, y, 150, 150) + 60 * n;
return grey(wave(d * 0.1f));
}
function shade(x, y, t) {
let n = noise2(x * 0.01, y * 0.01);
let d = dist(x, y, 150, 150) + 60 * n;
return grey(wave(d * 0.1));
}
Step 3: colour¶
The same value through the palette.
static RGB shade(float x, float y, float t)
{
float n = noise2(x * 0.01f, y * 0.01f);
float d = dist(x, y, 150, 150) + 60 * n;
return rainbow(wave(d * 0.1f));
}
function shade(x, y, t) {
let n = noise2(x * 0.01, y * 0.01);
let d = dist(x, y, 150, 150) + 60 * n;
return rainbow(wave(d * 0.1));
}
Step 4: XOR texture at a low weight¶
A little XOR, at 0.15, for texture.
static RGB shade(float x, float y, float t)
{
float n = noise2(x * 0.01f, y * 0.01f);
float d = dist(x, y, 150, 150) + 60 * n;
float v = wave(d * 0.1f);
float tex = ((int)x ^ (int)y) % 256 / 255.0f;
return rainbow(0.85f * v + 0.15f * tex);
}
function shade(x, y, t) {
let n = noise2(x * 0.01, y * 0.01);
let d = dist(x, y, 150, 150) + 60 * n;
let v = wave(d * 0.1);
let tex = (x ^ y) % 256 / 255;
return rainbow(0.85 * v + 0.15 * tex);
}
Step 5: a soft round mask¶
Fade out towards the edge.
static RGB shade(float x, float y, float t)
{
float n = noise2(x * 0.01f, y * 0.01f);
float d = dist(x, y, 150, 150) + 60 * n;
float v = wave(d * 0.1f);
float tex = ((int)x ^ (int)y) % 256 / 255.0f;
float m = 1 - smoothstep(110, 150, dist(x, y, 150, 150));
return scale(rainbow(0.85f * v + 0.15f * tex), m);
}
function shade(x, y, t) {
let n = noise2(x * 0.01, y * 0.01);
let d = dist(x, y, 150, 150) + 60 * n;
let v = wave(d * 0.1);
let tex = (x ^ y) % 256 / 255;
let m = 1 - smoothstep(110, 150, dist(x, y, 150, 150));
return scale(rainbow(0.85 * v + 0.15 * tex), m);
}
Step 6: time¶
Two small changes: t becomes noise's third input, and taking t away inside the wave moves the rings outwards.
static RGB shade(float x, float y, float t)
{
float n = noise3(x * 0.01f, y * 0.01f, t * 0.2f);
float d = dist(x, y, 150, 150) + 60 * n;
float v = wave(d * 0.1f - t);
float tex = ((int)x ^ (int)y) % 256 / 255.0f;
float m = 1 - smoothstep(110, 150, dist(x, y, 150, 150));
return scale(rainbow(0.85f * v + 0.15f * tex), m);
}
function shade(x, y, t) {
let n = noise3(x * 0.01, y * 0.01, t * 0.2);
let d = dist(x, y, 150, 150) + 60 * n;
let v = wave(d * 0.1 - t);
let tex = (x ^ y) % 256 / 255;
let m = 1 - smoothstep(110, 150, dist(x, y, 150, 150));
return scale(rainbow(0.85 * v + 0.15 * tex), m);
}
Related¶
- Combining Two Patterns: why this order keeps the picture clear.