Beat kaleidoscope
glint · Examples · Tutorials · Gallery
A kaleidoscope of tiles that clicks round a notch on every beat and changes its shapes and colours every bar, locked to the tempo.
Audio-reactive: it moves with music from a microphone, line-in or a file.

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
One pass, in GLSL.
fragment shader
#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;
uniform vec3 spectrum;
uniform float beat;
uniform float beatTime;
uniform int beatCount;
uniform sampler2D fft;
uniform float beatPhase;
uniform int beatIndex;
in vec2 v_texcoord;
out vec4 fragColor;
// 1 on each kick, fading; without audio, a steady pulse twice a second.
float kick() { return beatCount > 0 ? beat : pow(1.0 - fract(time * 2.0), 4.0); }
// Seconds since the last kick, and which kick it was (the same fallback).
float sinceKick() { return beatCount > 0 ? beatTime : fract(time * 2.0) / 2.0; }
float kickId() { return beatCount > 0 ? float(beatCount) : floor(time * 2.0); }
// One FFT bin, 0..1 across the spectrum (bass on the left).
float bin(float x) { return texture(fft, vec2(x, 0.25)).r; }
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float shape(vec2 p, float kind) {
if (kind < 0.33) return length(p) - 0.32; // circle
if (kind < 0.66) return abs(p.x) + abs(p.y) - 0.38; // diamond
return min(max(abs(p.x) - 0.35, abs(p.y) - 0.1), max(abs(p.y) - 0.35, abs(p.x) - 0.1)); // cross
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
float barSeed = floor(float(beatIndex) / 4.0);
// One notch per beat, eased in over the first quarter of the beat.
float notch = float(beatIndex) + smoothstep(0.0, 0.25, beatPhase);
uv = rot(notch * 0.39 + time * 0.05) * uv;
// Fold into slices.
float n = 6.0 + 2.0 * mod(barSeed, 3.0);
float a = atan(uv.y, uv.x), r = length(uv);
a = mod(a, 6.28318 / n);
a = abs(a - 3.14159 / n);
vec2 k = vec2(cos(a), sin(a)) * r;
// Tiles in the folded space.
vec2 q = k * (4.0 + spectrum.x * 3.0) - vec2(time * 0.3, 0.0);
vec2 id = floor(q), f = fract(q) - 0.5;
float h = hash(id + barSeed * 13.0);
float d = shape(f / (0.8 + 0.4 * kick()), h);
vec3 col = pal(h * 0.5 + barSeed * 0.21 + r * 0.3) * smoothstep(0.02, -0.02, d);
col += pal(h + 0.5) * 0.4 * smoothstep(0.03, 0.0, abs(d));
col *= smoothstep(1.2, 0.2, r) + 0.1;
fragColor = vec4(col * (0.8 + 0.6 * kick()), 1.0);
}More Audio-reactive examples
Sub-bass tunnel · Spectrum city · Kick ripples · Lissajous scope · Strobe shapes · LED meter · Bass blob