10 PRINT

glint · Examples · Tutorials · Gallery

The famous one-line Commodore 64 program, 10 PRINT CHR$(205.5+RND(1)); : GOTO 10, which prints / or \ at random and makes a maze. Here it scrolls up as it types, in C64 blue.

10 PRINT: 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))); }

void main() {
    vec2 st = gl_FragCoord.xy / resolution;
    // The border and the screen inside it.
    vec2 inner = (st - 0.08) / 0.84;
    vec3 border = vec3(0.53, 0.47, 0.93), screen = vec3(0.27, 0.2, 0.75), ink = vec3(0.53, 0.47, 0.93);
    if (any(lessThan(inner, vec2(0.0))) || any(greaterThan(inner, vec2(1.0)))) { fragColor = vec4(border, 1.0); return; }
    float cols = 40.0, rows = 25.0;
    float typed = time * 300.0;                                     // characters printed so far
    float scroll = max(0.0, floor(typed / cols) - rows + 1.0);
    vec2 cellF = vec2(inner.x * cols, (1.0 - inner.y) * rows);
    vec2 cell = floor(cellF), f = fract(cellF);
    float index = (cell.y + scroll) * cols + cell.x;
    vec3 col = screen;
    if (index < typed) {
        float slash = step(0.5, hash(vec2(cell.x, cell.y + scroll)));
        float d = slash > 0.5 ? abs(f.x - f.y) : abs(f.x + f.y - 1.0);
        col = mix(screen, ink, smoothstep(0.18, 0.1, d));
    } else if (index < typed + 1.0 && fract(time * 2.0) < 0.5) col = ink;   // the cursor
    fragColor = vec4(col, 1.0);
}

More More GLSL examples

Field lines · Tesseract · Black hole · Low poly · Invaders · Gears · Phyllotaxis · Pong