Maurer rose

glint · Examples · Tutorials · Gallery

Walk round the rose curve r = sin(n·θ) in steps of d degrees, joining the dots with straight lines: 360 segments that make a different lace for every n and d. d creeps slowly, so it keeps changing.

Maurer rose: a GLSL shader

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;

in vec2 v_texcoord;
out vec4 fragColor;

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 segment(vec2 p, vec2 a, vec2 b) {
    vec2 pa = p - a, ba = b - a;
    return length(pa - ba * clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0));
}

vec2 rose(float deg, float n) { float t = radians(deg); return sin(n * t) * vec2(cos(t), sin(t)) * 0.44; }

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
    float n = 6.0, d = 71.0 + time * 0.05;
    float px = 1.2 / resolution.y;
    float lace = 1e9, curve = 1e9;
    vec2 prev = rose(0.0, n), prevC = prev;
    for (int k = 1; k <= 360; k++) {
        float fk = float(k);
        vec2 p = rose(fk * d, n);
        lace = min(lace, segment(uv, prev, p));
        prev = p;
        vec2 c = rose(fk, n);
        curve = min(curve, segment(uv, prevC, c));
        prevC = c;
    }
    vec3 col = vec3(0.03, 0.02, 0.05);
    col += pal(0.6 + length(uv) + time * 0.02) * smoothstep(px * 1.5, 0.0, lace) * 0.8;
    col += vec3(1.0, 0.8, 0.4) * smoothstep(px * 3.0, 0.0, curve);
    fragColor = vec4(col, 1.0);
}

More More GLSL examples

Wave interference · Lorenz attractor · Voxel world · Snowflakes · Spirograph · Field lines · Tesseract · Black hole