Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body {
    margin: 0; 
    overflow: hidden;
}

a {
    position: fixed;
    display: inline-block;
    margin-left: calc(50vw - 70px);
    font-size:20px;
    z-index:1;
    color: white;
}
              
            
!

JS

              
                const factory = verticesFactory();
const stages = "GENCLUB".split('')
    .map(factory)
    .map((v,i,a) => v.map((v, j) => [...v, ...a[(i+1)%a.length][j]]).flat())

const canvas = document.createElement('canvas');
canvas.style.background = '#000'
document.body.appendChild(canvas);
const gl = canvas.getContext("webgl", {preserveDrawingBuffer: true}); 

const clearPass = program({
    type: gl.TRIANGLES, 
    vertexSize: 2,
    shaders: [`
            attribute vec2 pt;
            void main(void) {
                gl_Position=vec4(pt, 0.0, 1.0);
            }`, `
            void main(void) {
                gl_FragColor=vec4(0.0, 0.0, 0.0, 0.05);
            }`]
});

clearPass.updateVertices([-1,3,-1,-1,3,-1])

const particles = program({
    type: gl.POINTS,
    vertexSize: 4,
    uniforms: {time: '1f', resolution: '2f'},
    shaders: [`
            uniform float time;
            uniform vec2 resolution;
            attribute vec4 pt;
            varying float i;
            void main() {
                float aspect = resolution.y/resolution.x;
                float t = smoothstep(0.,1.,smoothstep(0.,1.,fract(time)))*3.1415;
                i = fract(pt.x*pt.y*pt.z*pt.w);
                vec2 c = (pt.xy + pt.zw)/2.0;
                float a = atan(pt.y - c.y, pt.x - c.x);
                float r = length(vec2(pt.x - c.x, pt.y - c.y));
                c += vec2(cos(a+t), sin(a+t)) * r;
                gl_Position = vec4(c.x*aspect, c.y, 0., 1.);
                gl_PointSize = 9.0;
            }`, `
            uniform float time;
            varying float i;
            float ch(vec2 uv) {
                float d = length(uv - 0.5);
                return smoothstep(0.2, 0.00, d);
            }
            void main() {
                float d = length(gl_PointCoord.xy-0.5);
                d = smoothstep(0.25, 0.45, d);
                gl_FragColor = vec4(
                    ch(gl_PointCoord.xy-0.25*sin(time+i)),
                    ch(gl_PointCoord.xy),
                    ch(gl_PointCoord.xy+0.25*sin(time+i)), 
                    0.01
                 );
            }`]
});

let prevIndex;

requestAnimationFrame(function draw(t) {
   
    if (canvas.width != innerWidth || canvas.height !== innerHeight) {
        particles.uniforms.resolution([innerWidth, innerHeight]);
        gl.viewport(0, 0, canvas.width = innerWidth, canvas.height = innerHeight);
    }
    
    gl.enable(gl.BLEND);
    gl.blendFunc(gl.ONE, gl.ONE); // additive
    particles.bind();
    const speed= 2000
    const index = ((t/speed)|0)%stages.length;
    if (index !== prevIndex){
        prevIndex = index;
        particles.updateVertices(stages[index])
    }
    particles.uniforms.time([t/speed]);
    particles.draw();
    
    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 
    clearPass.bind();
    clearPass.draw();
    
    requestAnimationFrame(draw);
    
});

function program(o) {
    const pid = gl.createProgram();
    const bufferId = gl.createBuffer();
    o.shaders.forEach((src, i) => {
        const id = gl.createShader(i?gl.FRAGMENT_SHADER:gl.VERTEX_SHADER);
        gl.shaderSource(id, 'precision highp float;\n'+src);
        gl.compileShader(id);
        gl.attachShader(pid, id);
    });
    gl.linkProgram(pid);
    gl.useProgram(pid);
    o.uniforms && Object.keys(o.uniforms).forEach(uf => {
        const loc = gl.getUniformLocation(pid, uf), 
            f = gl[`uniform${o.uniforms[uf]}`];
        o.uniforms[uf] = v => f.call(gl, loc, ...v);
    });
    const pt = gl.getAttribLocation(pid, "pt");
    gl.enableVertexAttribArray(pt);
    o.draw = () => gl.drawArrays(o.type, 0, o.count)
    o.bind = () => {
        gl.useProgram(pid);
        gl.bindBuffer(gl.ARRAY_BUFFER, bufferId);
        gl.vertexAttribPointer(pt, o.vertexSize, gl.FLOAT, false, 0, 0); 
    }
    o.updateVertices = (data) => {
        gl.bindBuffer(gl.ARRAY_BUFFER, bufferId);
        gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
        o.count = data.length/o.vertexSize
    }
    return o;
}

function verticesFactory() {
    const count = 999;
    const s = 500;
    const canvas = document.createElement('canvas');
    canvas.width = canvas.height = s;
    const ctx = canvas.getContext('2d');
    ctx.clearRect(0, 0, s, s);
    ctx.font = `bold ${s/3}px Arial`;
    ctx.fillStyle = "red";
    ctx.textBaseline = "middle";
    ctx.textAlign = "center";
    return text => {
        const vertices = [];
        ctx.clearRect(0, 0, s, s);
        ctx.fillText(text, s/2, s/2);
        const data = ctx.getImageData(0, 0, s, s);
        while (vertices.length < count*2) {
            const x = s*Math.random();
            const y = s*Math.random();
            if (data.data[((y|0)*s+(x|0))*4])
                vertices.push([2*(x/s-0.5), 2*(0.5-y/s)]);
        }
        return vertices;
    };
}
              
            
!
999px

Console