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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <!-- Copyright (c) 2017 by Kultur Design 

This pen is created for demonstartion purposes only. It's design & code remain the property of Kultur Design.

We'd love to create something similar for you. Please feel free to contact us at www.kultur.design :) 
-->

<div id="animContanier_a"></div>
              
            
!

CSS

              
                html,body {
    height:100%;
    min-height:100%;
    margin: 0;
    padding: 0;
    overflow:hidden;  
}

body {
    background: #202020;
    margin: 0;
    padding: 0;
    font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
    color: #000;
}

#animContanier_a {
    margin: 0;
    padding: 0;
    width:100%;  
    height:100%;
}

              
            
!

JS

              
                

AnimApp = {

    _appVersion: "BETA 001",
    _testing: false,
    _manifest: null,
    _configJSON: [],
    _p5_anims: [],
    //_mode: "composer",

    //_container: null,
    _sketch: [],
    _uisettings: [],

    debug: function (message) {
        if (this._testing) { console.log(message) };
    },

    somePublicFunction: function() {
        // something
    },

    // init

    init: function (manifest, testing) { // configJSON, testing 
        this._manifest = manifest;
        //this._mode = mode;
        this._testing = testing;        
        this.debug("App.init, waiting for Document load");
        this.debug("Renderer Mode: " + this._mode);

        // wait for load
        this.wait();
    },

    wait: function () {

        $(document).ready(function () {
            AnimApp.debug("Document Loaded")
            AnimApp.start();
        });

    },

    
    // application runs here once doc loaded
    start: function () {
        this.debug("App Ver: " + this._appVersion);
                        
        // define sketches
        this.defineSketches();

        
        // init p5 anims
        for (i = 0; i < AnimApp._manifest.length; i++) {
            this.initAnim(i, AnimApp._manifest[i].container, JSON.parse(AnimApp._manifest[i].configJSON));
        }

        // ui
        for (i = 0; i < AnimApp._manifest.length; i++) {
            this.initUI(i, AnimApp._manifest[i].container, JSON.parse(AnimApp._manifest[i].configJSON));
        }
        

        
    },


    // ui methods

    initUI: function (id, container, configJSON) {
        if (configJSON.params.mode == "composer") {

            this._uisettings[id] = {
                color_bg: configJSON.params.color_bg,
                color_fg: configJSON.params.color_fg,  
                x: configJSON.params.x,
                y: configJSON.params.y,
                z: configJSON.params.z
            };

            settings = QuickSettings.create();
            settings.setGlobalChangeHandler(function () { AnimApp.uiChange(id); });
            settings.bindColor("color_bg", configJSON.params.color_bg, this._uisettings[id]);
            settings.bindColor("color_fg", configJSON.params.color_fg, this._uisettings[id]);
            settings.bindRange("x", 0, 1, configJSON.params.x, 0.01, this._uisettings[id]);
            settings.bindRange("y", 0, 1, configJSON.params.y, 0.01, this._uisettings[id]);
            settings.bindRange("z", 0, 1, configJSON.params.z, 0.01, this._uisettings[id]);
            settings.addButton("Restart", function () {
                AnimApp.uiRestart(id);
            });            
            settings.setPosition((container.offset().left + 20), container.offset().top + 20);
            AnimApp.uiCopySettings(id);
        }   
    },

    uiChange: function (id) {
        AnimApp._p5_anims[id].updateParams();
        AnimApp.uiCopySettings(id);
    },

    uiRestart: function (id) {
        AnimApp._p5_anims[id].restart();
    },

    uiCopySettings: function (id) {
        if (AnimApp._p5_anims[id].props.params.mode == "composer") {
            if ((AnimApp._manifest[id].copyContainer != undefined) && (AnimApp._manifest[id].copyContainer != null)) {
                // template param string
                var paramString = '"animVariation": [animVariation], "color_bg": "[color_bg]", "color_fg": "[color_fg]", "toggle": "[toggle]", "x": "[x]", "y": "[y]", "z": "[z]", "i": "[i]", "mode": "renderer"';
                // replace with param values
                paramString = paramString.replace("[animVariation]", AnimApp._p5_anims[id].props.params.animVariation);
                paramString = paramString.replace("[color_bg]", AnimApp._p5_anims[id].props.params.color_bg);
                paramString = paramString.replace("[color_fg]", AnimApp._p5_anims[id].props.params.color_fg);
                paramString = paramString.replace("[x]", AnimApp._p5_anims[id].props.params.x);
                paramString = paramString.replace("[y]", AnimApp._p5_anims[id].props.params.y);
                paramString = paramString.replace("[z]", AnimApp._p5_anims[id].props.params.z);
            }
        }
        
    },
    


    // p5  

    initAnim: function (id, container, configJSON) {
        AnimApp._p5_anims[id] = new p5(this.getSketch(configJSON.params.animVariation), container.attr('id'));
        AnimApp._p5_anims[id].initParams(id, configJSON.params, container.width(), container.height());
        
    },    

    getSketch: function (id) {  
        return this._sketch[id];
    },

    defineSketches: function () {







        // --------------------- sketch 0 (DNA) --------------------------
        this._sketch[0] = function (p) {

            p.props = [];
            p.props.id = null;
            p.props.hasParams = false;
            p.props.hasInit = false;
            p.props.params;
            p.props.w;
            p.props.h;

            p.props.fr = 60; // framerate
            p.props.animFrames = 90;
            p.props.animIncrement = 1 / p.props.animFrames;
            p.props.animProgress = 0.0;
            p.props.autorun = true;

            p.props.minHorz = 3;
            p.props.maxHorz = 100;
            p.props.minRadius = 0;
            p.props.maxRadius = 80;            
            p.props.maxFrameOffset = 150;

            p.sprites = [];
            p.colSprites = [];
            p.bgs = [];

            p.initParams = function (id, params, w, h) {

                p.props.id = id;
                p.props.params = params;
                p.props.w = w;
                p.props.h = h;
                p.props.vMax = p.props.h * 0.8;
                p.props.vMin = p.props.h * 0.2;
                p.props.randomSeed = p.random(0, 100);
                p.props.hasParams = true;


            };

           

            p.updateParams = function () {

                p.props.params.color_bg = AnimApp._uisettings[p.props.id].color_bg;
                p.props.params.color_fg = AnimApp._uisettings[p.props.id].color_fg;
                p.props.params.x = p.float(AnimApp._uisettings[p.props.id].x);
                p.props.params.y = p.float(AnimApp._uisettings[p.props.id].y);
                p.props.params.z = p.float(AnimApp._uisettings[p.props.id].z);

           
            };

            p.restart = function () {
                p.props.animProgress = 0;
            };

            p.initSketch = function () {
                p.props.hasInit = true;
                p.resizeCanvas(p.props.w, p.props.h);
            };

                                  

            p.setup = function () {
                p.frameRate(p.props.fr)
                p.imageMode(p.CENTER);
                p.background(p.props.params.color_bg);

            };

            
                   
            p.draw = function () {



                if (p.props.hasParams == true) { // have we got params passed in yet
                    if (p.props.hasInit == false) { // did we init sketch, size etc
                        p.initSketch();
                    } else {
                        p.drawState();
                    }
                }                 
            };

            p.drawState = function () {
                

                //bg
                p.background(p.props.params.color_bg);

                // make "random" deterministic every frame
                p.randomSeed(p.props.randomSeed);

                if (p.props.autorun) {
                    if (p.props.animProgress < 1) {
                        p.props.animProgress += p.props.animIncrement;
                    }
                }

                // draw the things based on progress
                p.anim();

            };


            p.anim = function () {
                // how many horizontal elements?
                var hElmnts = p.floor(p.map(p.props.params.x, 0, 1, p.props.minHorz, p.props.maxHorz));
                var elsFrameOffset = (p.props.maxFrameOffset / hElmnts) * p.props.params.z;
                
                p.stroke(p.props.params.color_fg);
                p.strokeWeight(1 * AnimApp.easeInOutQuart(p.props.animProgress));
                p.fill(p.props.params.color_fg);
                for (var h = 0; h < hElmnts; h++) {
                    var elFrameOffset = elsFrameOffset * h;
                    var elH = p.map(p.noise(h), 0, 1, p.props.vMin, p.props.vMax) * AnimApp.easeInOutQuart(p.props.animProgress) * p.sin((p.frameCount + elFrameOffset) * 0.05);
                    var elX = (h + 1) * (p.width / (hElmnts + 1)); // 3 elements = 4 screen divisions etc
                    var elY = (p.height - elH) / 2;
                    p.line(elX, elY, elX, elY + elH);
                    
                    var elR1 = p.map(p.noise(h) * p.props.params.y, 0, 1, p.props.minRadius, p.props.maxRadius) * AnimApp.easeInOutQuart(p.props.animProgress) * p.sin(p.HALF_PI + (p.frameCount + elFrameOffset) * 0.025);
                    p.ellipse(elX, elY, elR1, elR1);
                    var elR2 = p.map(p.noise(h) * p.props.params.y, 0, 1, p.props.minRadius, p.props.maxRadius) * AnimApp.easeInOutQuart(p.props.animProgress) * p.sin((p.frameCount + elFrameOffset) * 0.025);
                    p.ellipse(elX, elY + elH, elR2, elR2);

                }
            }


            // utilities        
            p.wAlpha = function (c, a) {
                var col = p.color(c);
                return p.color('rgba(' + [p.red(col), p.green(col), p.blue(col), a].join(',') + ')');
            }
            
            

        };




        
    },


    //  Shared Utilities

    // Returns a random integer between min (included) and max (included)
    // Using Math.round() will give you a non-uniform distribution!
    getRandomIntInclusive: function(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    },

    // Returns a random number between min (inclusive) and max (exclusive)
    getRandomArbitrary: function(min, max) {
      return Math.random() * (max - min) + min;
    },

    // easing utility functions based on : https://gist.github.com/cocopon/1ec025bcffb3fd7995db 

    easeOutSine: function (t) {
        return p.sin(t * (p.PI / 2));
    },

    easeInSine: function (t) {
        return -p.cos(t * (p.PI / 2)) + 1.0;
    },

    easeOutQuart: function (t) {
        --t;
        return 1.0 - t * t * t * t;
    },

    easeInQuart: function (t) {
        return t * t * t * t;
    },

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

}


// page animations manifest
var animationsManifest = [
  { container: $("#animContanier_a"), configJSON: '{ "params" : {"animVariation": 0, "color_bg": "#202020", "color_fg": "#ffffff", "toggle": "off", "x": "0.5", "y": "0.5", "z": "0.5", "mode": "composer" } }' }
];

// init 

AnimApp.init(animationsManifest, false); // animations manifest, debug output

              
            
!
999px

Console