Bass snake
glint · Examples · Tutorials · Gallery
A chain of forty circles, each where the head was a moment earlier on a Lissajous path: the snake fattens with the bass and its colours run down its back.
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;
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; }
// Is anything playing? (Examples fake their input when not.)
bool silent() { return spectrum.x + spectrum.y + spectrum.z < 0.0001; }
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))); }
vec2 path(float t) { return vec2(sin(t * 1.3) * 0.65, sin(t * 1.7 + 1.0) * 0.35); }
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
float px = 1.5 / resolution.y;
vec3 col = vec3(0.02, 0.03, 0.04) + 0.02 * step(0.5, fract((uv.x + uv.y) * 20.0));
float bass = silent() ? 0.4 + 0.3 * kick() : spectrum.x * 1.5 + kick() * 0.3;
// Tail first, so the head is drawn on top.
for (int i = 39; i >= 0; i--) {
float fi = float(i);
vec2 p = path(time * 1.2 - fi * 0.045);
float r = (0.03 + 0.03 * bass) * (1.0 - fi / 48.0);
float d = length(uv - p);
vec3 c = pal(fi * 0.02 - time * 0.2);
col *= 1.0 - 0.5 * smoothstep(r * 1.6, r, d) * step(r + px, d); // soft shadow of this segment
col = mix(col, c * (1.0 - 0.5 * smoothstep(0.0, r, d)), smoothstep(r + px, r, d));
}
fragColor = vec4(col, 1.0);
}More Audio-reactive examples
Light curtain · Halftone spectrum · Orbitals · Bar clock · Spectrum landscape · Rising bubbles · Op art · Square tunnel