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

              
                <!--
The WebGL (ThreeJS) logo from our project for Volanti Imaging, which is live here: https://www.volanti-imaging.co.uk/.

The live version hooks into the OpenWeatheMap.org API and responds to London's current weather. High atmospheric pressure = more particles, high wind speed = faster rotation.

Here you can emulate those changing parameters via the QuickSettings panel in the to left of the screen.

More about the project here: https://www.behance.net/gallery/34648247/Volanti-Imaging-Generative-Logo-Development 

-->
<div id="logo-anim"></div>
              
            
!

CSS

              
                body {
    background:#202020;
}

#logo-anim {
    width:100%;
    height: 500px;
}
              
            
!

JS

              
                $(function () {
    "use strict";

    var weatherPressure = 0;
    var weatherSpeed = 0;
    var settings = null;



    // should have weather data or defaults in place

    // assuming jquery loaded
    var container = $("#logo-anim");
    var containerW = container.width();
    var containerH = container.height();

    var scene;
    var camera;
    var renderer;




    var uisettings = {
        AtmosPressure: weatherPressure,
        WindSpeed: weatherSpeed
    };

    $(document).ready(function () {

        // ui 
        initUI();

        // start anim
        initAnim();
    });

       

    function initUI() {
        settings = QuickSettings.create();
        settings.setGlobalChangeHandler(uiChange);
        settings.bindRange("AtmosPressure", 0, 1, weatherPressure, 0.01, uisettings);
        settings.bindRange("WindSpeed", 0, 1, weatherSpeed, 0.01, uisettings);
        settings.addButton("APPLY WEATHER", uiApply);
        //console.log("initUI", weatherPressure, weatherSpeed);
    }

    function uiChange() {
        weatherPressure = uisettings.AtmosPressure;
        weatherSpeed = uisettings.WindSpeed;
        //console.log("uiChange", weatherPressure, weatherSpeed)
    }

    function uiApply() {
        //console.log(weatherPressure, weatherSpeed);
        resetAnim();
        initAnim();
    }

    

    


    // ----------------------------------------------------------
    // THREEJS Animation 
    // ----------------------------------------------------------

    function resetAnim() {
        scene = null;
        camera = null;
        renderer = null;
        $('canvas').remove();
    }


    function initAnim() {

        scene = new THREE.Scene();
        camera = new THREE.PerspectiveCamera(75, containerW / containerH, 1, 1000);
        renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
        renderer.setSize(containerW, containerH);
        container.append(renderer.domElement);

        doWebGL();
        
      

        function doWebGL() {

            

            var TWO_PI = Math.PI * 2;
            var HALF_PI = Math.PI / 2;
            var QUARTER_PI = Math.PI / 4;

            var maxVLayers = 24;
            var minVLayers = 8;
            var vLayers = Math.round( ((maxVLayers - minVLayers) * weatherPressure) + minVLayers );
            
            var tailResolution = 90; // segments in tail for full circumference
            var maxTailLength = 0.5; //complex: 0.25 /  small: 0.5 // Norm: 0.33
            var tailSegments = Math.round(tailResolution * maxTailLength);
            var vMaxRadius = containerH / 1.4;
            var vHeight = containerH * 1.4;
            var yOffset = -vHeight / 2 - 100; // half height and push toward bottom of canvas

            var camInit = 0.7;//HALF_PI;
            var camTarget = 0.5;

            var maxPlotRadius = 25; // size of dot
            var minPlotRadius = 7;
            var plotRadius = maxPlotRadius - Math.round((maxPlotRadius - minPlotRadius) * weatherPressure);

            var maxTailWeight = plotRadius; // half plot diameter 

            var minRotationIncrement = TWO_PI / 600;
            var maxRotationIncrement = TWO_PI / 150;
            var linearRotationPerFrame = ((maxRotationIncrement - minRotationIncrement) * weatherSpeed) + minRotationIncrement;

            var maxAnimationLength = 5; //20; // seconds
            var animationProgress = 0;

            var plotColor = 0xe1e1e1;
            var plotOpacity = 1;

            var tailColor = 0xe1e1e1;
            var tailOpacity = 0.33;

            //console.log("pressure: ", weatherPressure, vLayers, plotRadius);
            //console.log("speed: ", weatherSpeed, linearRotationPerFrame, ("{" + minRotationIncrement + " to " + maxRotationIncrement + "}" ));

            
            var vSpheregeometry = new THREE.SphereGeometry(plotRadius, 20, 20);
            var vSphereMaterial = new THREE.MeshBasicMaterial({ color: plotColor });
            var vTailMaterial = new THREE.MeshBasicMaterial({ color: tailColor, side: THREE.DoubleSide, wireframe: false, transparent: true, opacity: tailOpacity });

            var targetFrameRate = 30;

            var vSpheres = [];
            var vTails = [];
            var initRotations = [];
            var targetRotations = [];

            init();


            function init() {
                createVSpheres();
                createVTails();
            }

            function createVSpheres() {
                for (var i = 0; i < vLayers; i++) {
                    var sphereMesh = new THREE.Mesh(vSpheregeometry, vSphereMaterial);
                    scene.add(sphereMesh);
                    vSpheres[i] = sphereMesh;
                    initRotations[i] = getRandom(0, 1);
                    targetRotations[i] = getRandom(0, 1);
                }
            }

            function createVTails() {
                for (var i = 0; i < vLayers; i++) {
                    var vTailGeometry = new THREE.PlaneGeometry(0, 0, tailSegments, 1); // arbitary w,h
                    var tailMesh = new THREE.Mesh(vTailGeometry, vTailMaterial);
                    scene.add(tailMesh);
                    vTails[i] = tailMesh;
                }
            }

            function drawLayers() {

                for (var l = 1; l <= vLayers; l++) {

                    var layerAnimationTarget = targetRotations[l] * TWO_PI; // (value of property, like angle in radians) 
                    var layerAnimationLength = maxAnimationLength; // (time) this could be randomised later
                    var layerAnimationFrames = layerAnimationLength * targetFrameRate;
                    var layerAnimationProgress = Math.min((animationProgress / layerAnimationFrames), 1);
                    var layerAnimationProgressEased = GSAPEase(layerAnimationProgress);
                    var layerAngleStart = initRotations[l] * TWO_PI + t * (linearRotationPerFrame * layerAnimationProgressEased);
                    var layerAnimationNext = layerAngleStart + (layerAnimationProgressEased * layerAnimationTarget);

                    tail(l, layerAnimationNext, layerAnimationProgressEased);
                    plot(l, layerAnimationNext, layerAnimationProgressEased);

                }

            }




            function plot(layer, next, progress) {

                var plotCenterX = 0;
                var plotCenterY = 0;
                var plotCenterZ = 0;
                var layerScale = Math.tan((QUARTER_PI / vLayers) * layer);

                var layerRadius = vMaxRadius * layerScale;

                var nextX = plotCenterX + (layerRadius * Math.cos(next));
                var nextY = (yOffset + (vHeight / vLayers) * layer);
                var nextZ = plotCenterZ + (layerRadius * Math.sin(next));

                var sphere = vSpheres[layer - 1];
                var sphereScale = layerScale * progress;
                sphere.scale.set(sphereScale, sphereScale, sphereScale);
                sphere.position.set(nextX, nextY, nextZ);


            }

            function tail(layer, next, progress) {

                var plotCenterX = 0;
                var plotCenterY = 0;
                var plotCenterZ = 0;
                var layerScale = Math.tan((QUARTER_PI / vLayers) * layer);
                var layerRadius = vMaxRadius * layerScale;

                var radianIncrement = (TWO_PI * progress) / tailResolution;
                //var tailLength = maxTailLength*progress;  

                var tail = vTails[layer - 1];
                var tailVertexPairs = tail.geometry.vertices.length / 2;

                for (var v = tailVertexPairs - 1; v >= 0; v--) {

                    var pProximity = 1 - (Math.max(1, v) / tailVertexPairs);
                    var tailWeight = (progress * (maxTailWeight * layerScale)) * pProximity;

                    var nextAngle = next - (v * radianIncrement);
                    var nextX = plotCenterX + (layerRadius * Math.cos(nextAngle));
                    var nextY = (yOffset + (vHeight / vLayers) * layer) + tailWeight / 2;
                    var nextZ = plotCenterZ + (layerRadius * Math.sin(nextAngle));


                    tail.geometry.vertices[v].x = nextX;
                    tail.geometry.vertices[v].y = nextY;
                    tail.geometry.vertices[v].z = nextZ;

                    var oppositeV = v + tailVertexPairs;
                    tail.geometry.vertices[oppositeV].x = nextX;
                    tail.geometry.vertices[oppositeV].y = nextY - tailWeight;
                    tail.geometry.vertices[oppositeV].z = nextZ;

                    tail.geometry.verticesNeedUpdate = true;

                }
            }











            var t = 0;

            camera.position.z = 550;

            var render = function () {
                requestAnimationFrame(render);
                animationProgress++;
                drawLayers();

                t++;
                animateCamera();
                renderer.render(scene, camera);
            };

            render();


           

            var rotation = HALF_PI;
            function animateCamera() {
                //console.log(rotation);
                //console.log(map_range(0.5, 0, 1, 200, 300));

                var camAnimationLength = maxAnimationLength; // could be adjusted later
                var camAnimationFrames = camAnimationLength * targetFrameRate;
                var camAnimationProgress = Math.min((animationProgress / camAnimationFrames), 1);
                var camAnimationProgressEased = GSAPEase(camAnimationProgress);



                rotation = map_range(camAnimationProgressEased, 0, 1, camInit, camTarget)

                //rotation -= 0.0025;
                camera.position.x = 0;
                camera.position.y = Math.sin(rotation) * 550;
                camera.position.z = Math.cos(rotation) * 550;
                camera.lookAt(scene.position); // the origin
            }


            /*
            * This easing function converted from a great processing port of Robert Penner's easing functions:
            * Easing.pde (c) 2015 cocopon -> https://gist.github.com/cocopon/1ec025bcffb3fd7995db
            *
            * http://www.robertpenner.com/easing/
            * http://www.robertpenner.com/easing_terms_of_use.html
            */
            function easeInOutQuart(t) {
                //test
                GSAPEase(t);

                t *= 2;
                if (t < 1) {
                    return 0.5 * t * t * t * t;
                }
                t -= 2;
                return -0.5 * (t * t * t * t - 2);
            }

            /* alternative to above, the GSAP library */
            function GSAPEase(t) {
                return Power4.easeInOut.getRatio(t);
                //return Expo.easeInOut.getRatio(t);
            }

            // input, input low, input high, target low, target high 
            function map_range(value, low1, high1, low2, high2) {
                return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
            }




            /* get random value frim range */
            function getRandom(min, max) {
                return Math.random() * (max - min) + min;
            }


        }



    }


});

              
            
!
999px

Console