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

              
                <script id="vertexShader" type="x-shader/x-vertex">

    void main(){
        gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
    }

</script>

<script id="fragmentShader" type="x-shader/x-fragment">

    // ================ variables ================ //

    // ---------------- application ---------------- //

    struct App
    {
        float time;
        vec2 resolution;
    };

    // ---------------- uniform ---------------- //

    uniform App uApp;

    // ================ functions ================ //

    // ---------------- utilities ---------------- //

    vec2 linmap(vec2 in_val, vec2 in_min, vec2 in_max, vec2 out_min, vec2 out_max)
    {
        return (in_val - in_min) / (in_max - in_min) * (out_max - out_min) + out_min;
    }

    // ---------------- complex ---------------- //

    vec2 cAdd(vec2 c1, vec2 c2)
    {
        // return vec2(c1.x + c2.x, c1.y + c2.y);
        return c1 + c2;
    }

    vec2 cSub(vec2 c1, vec2 c2)
    {
        // return vec2(c1.x - c2.x, c1.y - c2.y);
        return c1 - c2;
    }

    vec2 cMul(vec2 c1, vec2 c2)
    {
        return vec2(c1.x * c2.x - c1.y * c2.y, c1.y * c2.x + c1.x * c2.y);
    }

    vec2 cConj(vec2 c)
    {
        return vec2(c.x, -c.y);
    }

    float cNorm(vec2 c)
    {
        // return sqrt(cMul(c, cConj(c)).x);
        return length(c);
    }

    vec2 cInv(vec2 c)
    {
        return cConj(c) / pow(cNorm(c), 2.0);
    }

    vec2 cDiv(vec2 c1, vec2 c2)
    {
        return cMul(c1, cInv(c2));
    }

    vec2 cPow(vec2 c, int n)
    {
        vec2 p = vec2(1.0, 0.0);
        for (int i = 0; i < n; ++i)
        {
            p = cMul(p, c);
        }
        return p;
    }

    // ---------------- main ---------------- //

    void main()
    {
        vec2 fragCoord = linmap(gl_FragCoord.xy, vec2(0.0, 0.0), uApp.resolution, vec2(-2.0, -2.0), vec2(2.0, 2.0));

        vec2 z = fragCoord;

        // The hyperparameter from Inigo Quilez (https://www.shadertoy.com/view/MsfGRr)
        vec2 c = 0.45 * cos(vec2(0.5, 3.9) + uApp.time * 0.3 * vec2(1.2, 1.7)) - vec2(0.3, 0.0);
        
        const float N = 512.0;
        const float B = 256.0;
        for (float n = 0.0; n <= N; ++n)
        {
            z = cPow(z, 2) + c;
            float norm = cNorm(z);
            if (norm > B) 
            {
                float sn = n - log2(log(norm) / log(B));
                gl_FragColor = vec4(cos(vec3(radians(0.0), radians(30.0), radians(60.0)) + sn / N * 100.0 + radians(180.0)) * 0.5 + 0.5, 1.0);
                break;
            }
        }
    }

</script>

              
            
!

CSS

              
                
              
            
!

JS

              
                const init = () => {

    const renderer = new THREE.WebGLRenderer({ antialias:true });
    document.body.appendChild(renderer.domElement);

    const scene = new THREE.Scene();

    const orthographiCamera = new THREE.OrthographicCamera(window.innerWidth / -2.0, window.innerWidth / +2.0, window.innerHeight / +2.0, window.innerHeight / -2.0, 0.0, 1.0);
    const perspectiveCamera = new THREE.PerspectiveCamera(45.0, window.innerWidth / window.innerHeight, 0.1, 1000.0);
    const controls = new THREE.OrbitControls(perspectiveCamera, renderer.domElement);
    const clock = new THREE.Clock();

    perspectiveCamera.position.set(0.0, 0.0, 5.0);
    perspectiveCamera.lookAt(new THREE.Vector3(0.0, 0.0, 0.0));

    const geometry = new THREE.PlaneBufferGeometry(window.innerWidth, window.innerHeight);

    const uniforms = {
        uApp: {
            value: {
                time: clock.getElapsedTime(),
                resolution: new THREE.Vector2(window.innerWidth, window.innerHeight)
            }
        },
        uCamera: {
            value: {
                position: perspectiveCamera.position,
                viewMatrix: perspectiveCamera.matrixWorldInverse,
                projectionMatrix: perspectiveCamera.projectionMatrix
            }
        },
        uParams: {
            value: {
                numIterations: 300,
                convergenceCriteria: 0.0001,
                finiteDifferenceEpsilon: 0.0001
            }
        },
        uScene: {
            value: {
                backgroundColor: new THREE.Vector3(0.0, 0.0, 0.0),
                lights: [
                    {
                        direction: new THREE.Vector3(1.0, 1.0, 1.0),
                        ambientColor: new THREE.Vector3(1.0, 1.0, 1.0),
                        diffuseColor: new THREE.Vector3(1.0, 1.0, 1.0),
                        specularColor: new THREE.Vector3(1.0, 1.0, 1.0)
                    },
                    {
                        direction: new THREE.Vector3(-1.0, -1.0, -1.0),
                        ambientColor: new THREE.Vector3(1.0, 1.0, 1.0),
                        diffuseColor: new THREE.Vector3(1.0, 1.0, 1.0),
                        specularColor: new THREE.Vector3(1.0, 1.0, 1.0)
                    }
                ],
                material: {
                    ambientColor: new THREE.Vector3(0.05, 0.05, 0.05),
                    diffuseColor: new THREE.Vector3(0.5, 0.5, 0.5),
                    specularColor: new THREE.Vector3(1.0, 1.0, 1.0),
                    emissionColor: new THREE.Vector3(0.0, 0.0, 0.0),
                    shininess: 64.0
                },
                bound: {
                    position: new THREE.Vector3(0.0, 0.0, 0.0),
                    radius: 2.0
                },
                fractal: {
                    power: 2,
                    numIterations: 10,
                    escapeCriteria: 2.0
                }
            }
        }
    }

    const material = new THREE.ShaderMaterial({
        vertexShader: document.getElementById('vertexShader').textContent,
        fragmentShader: document.getElementById('fragmentShader').textContent,
        uniforms: uniforms
    });

    scene.add(new THREE.Mesh(geometry, material));

    const onWindowResize = (event) => {
        uniforms.uApp.value.resolution.x = window.innerWidth * window.devicePixelRatio;
        uniforms.uApp.value.resolution.y = window.innerHeight * window.devicePixelRatio;
        // NOTE: https://ics.media/tutorial-three/renderer_resize/
        renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize(window.innerWidth, window.innerHeight);
        perspectiveCamera.aspect = window.innerWidth / window.innerHeight;
        perspectiveCamera.updateProjectionMatrix();
    }
    onWindowResize();
    window.addEventListener('resize', onWindowResize, false);

    const animate = () => {

        requestAnimationFrame(animate);

        const update = () => {
            controls.update();
            perspectiveCamera.lookAt(new THREE.Vector3(0.0, 0.0, 0.0));
            uniforms.uApp.value.time = clock.getElapsedTime();
            uniforms.uCamera.value.position = perspectiveCamera.position;
            uniforms.uCamera.value.viewMatrix = perspectiveCamera.matrixWorldInverse;
            uniforms.uCamera.value.projectionMatrix = perspectiveCamera.projectionMatrix;
        }

        update();

        renderer.render(scene, orthographiCamera);
    };

    animate();
}

window.addEventListener("load", init);

              
            
!
999px

Console