Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

              
                <div class="container"></div>

<script type="x-shader/x-fragment" id="gooey-fragmentShader">
    precision highp float;

    const int col_number = 20;

    uniform float u_ratio;
    uniform float u_time;
    uniform float u_hover_times_fst[col_number];
    uniform float u_hover_times_scd[col_number];
    uniform float u_hover_times_trd[col_number];
    varying vec2 vUv;

    #define TWO_PI 6.28318530718
    #define PI 3.141592653589

    float random(in vec2 st) {
        return fract(sin(dot(st.xy, vec2(12.9898, 78.233)))*43758.5453123);
    }

    float circle(vec2 pos, vec2 uv, float radius) {
        return smoothstep(0., length(uv - pos), radius);
    }

    float calc_column_shape(vec2 pos, vec2 uv, float width) {
        float bt = 1. - smoothstep(0., width, abs(uv.x - pos.x));
        bt *= smoothstep(pos.y - width * 1.5, pos.y, uv.y);

        return max(bt, 0.);
    }

    float calc_bottom(vec2 uv) {
        uv.y *= 5.;
        uv.y = smoothstep(0., 1., uv.y);
        return 1. - uv.y;
    }

    void main() {

        vec2 uv = vUv;
        uv.x *= u_ratio;
		 
        float col_w = u_ratio / float(col_number);
        float radius = col_w * .12;

        float sum = calc_bottom(uv);

        for (int i = 0; i <= col_number; i++) {
            float randomiser = random(vec2(float(i), float(i) * .2));
            float x = col_w * (.5 + float(i));

            float col_time = u_time + TWO_PI * randomiser;
            float y_col = .7 + .3 * sin(col_time);
            float col_shape = calc_column_shape(vec2(x, y_col), uv, col_w);
            sum += col_shape;

            float is_way_down = step(sin(col_time + .5 * PI), 0.);
            vec2 drop_center;
            float y_drop_falling = .8 - y_col;
            y_drop_falling *= step(0., sin(u_time + TWO_PI * randomiser + .25 * TWO_PI));
            y_drop_falling = is_way_down * y_col + (1. - is_way_down) * y_drop_falling;
            drop_center = vec2(x, y_drop_falling);
            float drop_falling_shape = circle(drop_center, uv, radius * 1.8 * (1. - uv.y));
            sum += drop_falling_shape;

            drop_center = vec2(x, y_col);
            float drop_staying_shape = circle(drop_center, uv, radius * 1.3 * (1. - y_col));
            sum += drop_staying_shape;

            float drop_interactive_shape;

            drop_center = vec2(x, y_col - u_hover_times_fst[i]);
            drop_interactive_shape = circle(drop_center, uv, radius);
            sum += drop_interactive_shape;
            drop_center = vec2(x, y_col - u_hover_times_scd[i]);
            drop_interactive_shape = circle(drop_center, uv, radius);
            sum += drop_interactive_shape;
            drop_center = vec2(x, y_col - u_hover_times_trd[i]);
            drop_interactive_shape = circle(drop_center, uv, radius);
            sum += drop_interactive_shape;
        }

        vec3 color = mix(vec3(.92), mix(vec3(.91, .39, .26), vec3(.56, .31, .58), uv.y), smoothstep(.7, .72, sum));

        gl_FragColor = vec4(color, 1.);
    }
</script>
<script type="x-shader/x-vertex" id="gooey-vertexShader">
    attribute vec3 position;
    attribute vec2 uv;

    varying vec2 vUv;

    void main() {
        vUv = uv;
        gl_Position = vec4(position, 1.0);
    }
</script>
              
            
!

CSS

              
                html, body {
    overflow: hidden;
    padding: 0;
    margin: 0;
}
.container {
    width: 100%;
	 max-width: 200vh;
    height: 100vh;
	 margin: 0 auto;
}
canvas {
    display: block;
}
              
            
!

JS

              
                import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.module.min.js';

const container = document.querySelector('.container');
const numOfColumns = 20; // should be same in GLSL, prob passed as #define?
const magicValue = -1; // I know, I know

let size = {
    w: container.offsetWidth,
    h: container.offsetHeight
};
document.addEventListener('DOMContentLoaded', () => {
    let surface = new Surface(size.w, size.h);
    surface.updateSize(size.w, size.h);
    window.addEventListener('resize', () => {
        size = {
            w: container.offsetWidth,
            h: container.offsetHeight
        };
        surface.updateSize(size.w, size.h);
    });

    container.addEventListener('mousemove', (e) => {
        updateMousePosition(e.clientX, e.clientY);
    });
    container.addEventListener('touchmove', (e) => {
        updateMousePosition(e.targetTouches[0].pageX, e.targetTouches[0].pageY);
    });
    function updateMousePosition(eX) {
        const x = (eX - container.offsetLeft) / container.offsetWidth;
        for (let i = 0; i < numOfColumns; i++) {
            if (x > (i / numOfColumns) && x < (i + 1) / numOfColumns) {
                if (surface.fstHoverTimes[i] === magicValue) {
                    surface.fstHoverTimes[i] = 0;
                } else if (surface.fstHoverTimes[i] > .5 && surface.scdHoverTimes[i] === magicValue) {
                    surface.scdHoverTimes[i] = 0;
                } else if (surface.scdHoverTimes[i] > .5 && surface.trdHoverTimes[i] === magicValue) {
                    surface.trdHoverTimes[i] = 0;
                }
            }
        }
    }

    surface.loop();
});

class Surface {

    constructor(w, h) {
        this.renderer = new THREE.WebGLRenderer({ antialias: true });
        this.renderer.setPixelRatio(window.devicePixelRatio);
        container.appendChild(this.renderer.domElement);
        this.scene = new THREE.Scene();
        this.camera = new THREE.Camera();
        this.fstHoverTimes = new Array(numOfColumns).fill(magicValue);
        this.scdHoverTimes = new Array(numOfColumns).fill(magicValue);
        this.trdHoverTimes = new Array(numOfColumns).fill(magicValue);
        this.createPlane(w, h);
        this.render();
    }

    createPlane() {
        this.material = new THREE.RawShaderMaterial({
            vertexShader: document.getElementById('gooey-vertexShader').textContent,
            fragmentShader: document.getElementById('gooey-fragmentShader').textContent,
            uniforms: {
                u_time: { type: 'f', value: 0 },
                u_ratio: { type: 'f', value: 1 },
                u_hover_times_fst: { type: 'f', value: this.fstHoverTimes },
                u_hover_times_scd: { type: 'f', value: this.scdHoverTimes },
                u_hover_times_trd: { type: 'f', value: this.trdHoverTimes }
            }
        });

        this.planeGeometry = new THREE.PlaneBufferGeometry(2, 2);
        this.plane = new THREE.Mesh(this.planeGeometry, this.material);
        this.scene.add(this.plane);
    }

    render() {
        this.plane.material.uniforms.u_time.value += .007;
        this.plane.material.uniforms.u_ratio.value = size.w / size.h;
        for (let i = 0; i < numOfColumns; i++) {
            this.fstHoverTimes[i] = updateHoverTime(this.fstHoverTimes[i]);
            this.scdHoverTimes[i] = updateHoverTime(this.scdHoverTimes[i]);
            this.trdHoverTimes[i] = updateHoverTime(this.trdHoverTimes[i]);
        }
        this.plane.material.uniforms.u_hover_times_fst.value = this.fstHoverTimes;
        this.plane.material.uniforms.u_hover_times_scd.value = this.scdHoverTimes;
        this.plane.material.uniforms.u_hover_times_trd.value = this.trdHoverTimes;
        this.renderer.render(this.scene, this.camera);
        function updateHoverTime(v) {
            if (v !== magicValue) {
                v += .008;
                if (v > 1) {
                    v = magicValue;
                }
            }
            return v;
        }
    }

    loop() {
        this.render();
        requestAnimationFrame(this.loop.bind(this));
    }

    updateSize() {
        this.camera.aspect = size.w / size.h;
        this.renderer.setSize(size.w, size.h);
    }
}
              
            
!
999px

Console