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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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;
  padding: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

              
            
!

JS

              
                
        function anim1(solidity)
        {
            var _instance = new PIXI.Graphics();
            var _itemsArr = [];
            var _directionsArr = ["in", "out"];
            var _direction;
            var _solidity = solidity || "solid";
            var _callback;

            _instance.init = function(input, callback)
            {
                _callback = callback;
                _direction = _directionsArr[Math.floor(Math.random() * _directionsArr.length)];

                reset(input);
                var lastColor;

                var color1 = "0xFFFFFF";
                var color2 = "0x000000";

                var i = 0;
                var l = 10;
                var item;
                var color;
                var scale;
                var alpha = 1;
                var delayFactor = 10;
                var x = input.width / 2;
                var y = input.height / 2;

                for (i; i < l; i++)
                {
                    color = i % 2 === 0 ? color1 : color2;

                    item = new PIXI.Graphics();
                    item.interactive = false;
                    item.buttonMode = false;

                    if (_solidity === "hollow")
                    {
                        color = "0xffffff";
                        alpha = 0;
                        delayFactor = 1;
                        x = input.mouseTouchPosition.x;
                        y = input.mouseTouchPosition.y;

                        _direction = "out";
                        item.lineStyle(1, color, 1);
                    }

                    item.beginFill(color, alpha);
                    item.drawCircle(0, 0, 100);
                    item.endFill();

                    if (_direction === "out")
                    {
                        item.visible = false;
                        item.renderable = false;

                        item._scale = 0;
                        item._delay = i * delayFactor;
                    }
                    else
                    {
                        scale = input.width > input.height ? input.width : input.height;
                        scale = scale / 140;
                        item._scale = scale;
                        item._delay = (l - i) * delayFactor;
                    }

                    item.position.set(x, y);
                    item.scale.set(item._scale, item._scale);

                    _itemsArr.push(item);
                    _instance.addChild(item);

                    lastColor = color;
                }

                return lastColor;
            };

            _instance.render = function(input)
            {
                if (!_instance.renderable)
                    return;

                var i = 0;
                var l = _itemsArr.length;
                var killCounter = 0;
                var maxScale;
                var scaleLimit;
                var item;
                var lerp;
                var isDead;

                if (_direction === "out")
                {
                    maxScale = input.width > input.height ? input.width : input.height;
                    maxScale = maxScale / 140;
                    scaleLimit = maxScale - 0.2;
                }
                else
                {
                    maxScale = 0;
                    scaleLimit = 0.1;
                }

                for (i; i < l; i++)
                {
                    item = _itemsArr[i];
                    if (item)
                    {
                        if (item._delay-- < 0)
                        {
                            if (!item.visible)
                            {
                                item.visible = true;
                                item.renderable = true;
                            }

                            lerp = _solidity === "hollow" ? 0.1 : 0.15;
                            item._scale -= (item._scale - maxScale) * lerp;
                            item.scale.set(item._scale, item._scale);

                            isDead = false;
                            if (_direction === "out")
                            {
                                if (item._scale >= scaleLimit)
                                {
                                    isDead = true;
                                }
                            }
                            else
                            {
                                if (item._scale <= scaleLimit)
                                {
                                    isDead = true;
                                }
                            }

                            if (isDead)
                            {
                                killCounter++;

                                item.visible = false;
                                item.renderable = false;

                                if (item.parent)
                                    item.parent.removeChild(item);
                                if (item.destroy)
                                    item.destroy();

                                _itemsArr[i] = null;
                            }
                        }
                    }
                    else
                    {
                        killCounter++;
                    }

                    if (killCounter >= _itemsArr.length)
                    {
                        _instance.hide(input, true);
                    }
                }
            };

            _instance.hide = function(input, animationEnded)
            {
                reset(input);

                _instance.visible = false;
                _instance.renderable = false;

                if (_instance.parent)
                    _instance.parent.removeChild(_instance);

                if (animationEnded && _callback)
                {
                    _callback(input);
                }
            };

            _instance.kill = function(input)
            {
                _instance.hide(input);

                if (_instance.destroy)
                    _instance.destroy();

                _instance = null;
            };

            function reset(input)
            {
                _instance.clear();
                _instance.interactive = false;
                _instance.buttonMode = false;
                _instance.visible = true;
                _instance.renderable = true;

                var i = _itemsArr.length;
                var item;
                while (i--)
                {
                    item = _itemsArr[i];
                    if (item)
                    {
                        item.visible = false;
                        item.renderable = false;

                        if (item.parent)
                            item.parent.removeChild(item);
                        if (item.destroy)
                            item.destroy();
                    }
                }
                _itemsArr.length = 0;
            }

            return _instance;
        }



        // ============================================== GLOBAL
        var _stepTrails = 0;
        var _trailsArr = [];
        var _trailsIndex = 0;
        var _trailsCounter = 0;

        var _nodesArr = [];



        // ============================================== FORE
        var _foreContainer;
        var _foreWrapper;
        var _cursorFore;
        var _instructionsTextFore;

        SPF.set(
        {
            at: "fore",

            init: function(PIXI, input)
            {
                _foreContainer = new PIXI.Graphics();
                _foreWrapper = new PIXI.Graphics();
                _foreContainer.addChild(_foreWrapper);
                input.container.addChild(_foreContainer);
                disableInteraction(_foreContainer);
                disableInteraction(_foreWrapper);

                var mode = input.isTouchDevice ? "Tap" : "Click";
                _instructionsTextFore = new PIXI.Text(mode + ' anywhere to get artsy',
                {
                    fontFamily: "MonostenA, 'Helvetica Neue', Helvetica, Arial Black",
                    fill: 0xFFFFFF,
                    align: 'center'
                });
                _instructionsTextFore.interactive = false;
                _instructionsTextFore.buttonMode = false;
                _instructionsTextFore.anchor.set(0.5);
                _foreContainer.addChild(_instructionsTextFore);

                disableInteraction(_instructionsTextFore);
            },

            mouseDownTouchStart: function(PIXI, input)
            {
                if (!input.isTouchDevice)
                {
                    showCursor(input);
                }

                if (_instructionsTextFore)
                {
                    _instructionsTextFore.visible = false;
                    _instructionsTextFore.renderable = false;

                    if (_instructionsTextFore.parent)
                        _instructionsTextFore.parent.removeChild(_instructionsTextFore);
                    if (_instructionsTextFore.destroy)
                        _instructionsTextFore.destroy();

                    _instructionsTextFore = null;
                }
            },

            render: function(PIXI, input)
            {
                if (_cursorFore)
                {
                    _cursorFore.render(input);
                }

                if (_instructionsTextFore)
                {
                    _instructionsTextFore.alpha = input.beat !== null ? 0 : 1;
                }

                _foreWrapper.clear();

                var i = 0;
                var l = _trailsArr.length;
                var trail;

                for (i; i < l; i++)
                {
                    // if (_trailsCounter++ > 1)
                    // {
                    // _trailsCounter = 0;

                    trail = _trailsArr[i];
                    if (trail)
                    {
                        if (trail.y > input.height || trail.y < 0 || trail.x > input.width || trail.x < 0 || !_nodesArr[trail.nodeIndex])
                        {
                            trail = null;
                            // _trailsArr[i] = null;
                            _trailsArr.splice(i, 1);
                        }
                    }
                    if (trail)
                    {
                        _foreWrapper.beginFill(input.colors[Math.floor(Math.random() * input.colors.length)], 1);
                        _foreWrapper.drawCircle(trail.x, trail.y, 4);
                        _foreWrapper.endFill();
                    }
                    // }
                }
            },

            resize: function(PIXI, input)
            {
                _foreContainer.clear();
                _foreContainer.beginFill("0x000000", 0.25);
                _foreContainer.drawRect(0, 0, input.width, input.height);
                _foreContainer.endFill();

                if (_instructionsTextFore)
                {
                    _instructionsTextFore.position.set(input.width / 2, input.height / 2);
                    _instructionsTextFore.style.fontSize = input.width / 80;
                }
            }
        });

        function showCursor(input)
        {
            if (_cursorFore)
            {
                _cursorFore.kill();
            }

            _cursorFore = new PIXI.Graphics();
            _cursorFore.lineStyle(5, "0xFFFFFF", 0.5);
            _cursorFore.drawCircle(0, 0, input.width / 100);
            _cursorFore.position.set(input.mouseTouchPosition.x, input.mouseTouchPosition.y);
            _cursorFore.render = function(input)
            {
                this.scale.x -= (this.scale.x - 2) * 0.2;
                this.scale.y -= (this.scale.y - 2) * 0.2;
                if (this.scale.x >= 1.99)
                {
                    this.kill();
                }
            };
            _cursorFore.kill = function(input)
            {
                _cursorFore.visible = false;
                _cursorFore.renderable = false;
                if (_cursorFore.parent)
                    _cursorFore.parent.removeChild(_cursorFore);
                if (_cursorFore.destroy)
                    _cursorFore.destroy();
                _cursorFore = null;
            };

            _foreContainer.addChild(_cursorFore);
            disableInteraction(_cursorFore);
        }



        // ============================================== BACK
        var _backContainer;
        var _backWrapper;
        var _gfxArrBack;
        var _animBackCounter = 0;
        var _defaultAnimBack = new anim1();
        var _currAnimationBack;

        SPF.set(
        {
            at: "mid",

            load: function(PIXI, input)
            {
                _gfxArrBack = [
                    input.maskers.bbbbird1,
                    input.maskers.botanicorganic1,
                    input.maskers.botanicorganic2,
                    input.maskers.handdrawnanimal1,
                    input.maskers.handdrawnanimal2,
                    input.maskers.handdrawnanimal3,
                    input.maskers.handdrawnanimal4,
                    input.maskers.animaltech
                ];

                return _gfxArrBack;
            },

            init: function(PIXI, input)
            {
                _backContainer = new PIXI.Graphics();
                _backWrapper = new PIXI.Graphics();
                _backContainer.addChild(_backWrapper);
                input.container.addChild(_backContainer);
                disableInteraction(_backContainer);
                disableInteraction(_backWrapper);

                // showAnimationBack(input);
            },

            mouseDownTouchStart: function(PIXI, input)
            {
                addArtNodes(null, null, input);
            },

            render: function(PIXI, input)
            {
                var i = 0;
                var l = _nodesArr.length;
                var node;

                if (l >= 50)
                {
                    _nodesArr[0].kill();
                }

                for (i; i < l; i++)
                {
                    node = _nodesArr[i];
                    if (node)
                    {
                        node.draw(input);

                        _trailsArr[_trailsIndex++] = {
                            x: node._position.x,
                            y: node._position.y,
                            nodeIndex: node._index
                        };
                        _trailsIndex = _trailsIndex >= 180 ? 0 : _trailsIndex;
                    }
                }

                if (_currAnimationBack)
                {
                    _currAnimationBack.render(input);
                }

                if (_animBackCounter++ >= 400 && input.editing.id === "full")
                {
                    _animBackCounter = 0;
                    showAnimationBack(input);
                }

                if (input.editing.id === "medium")
                {
                    SPF.midgroundMask(true);
                }
                else
                {
                    SPF.midgroundMask(false);
                }
            },

            resize: function(PIXI, input)
            {
                _backContainer.clear();
                _backContainer.beginFill(input.colors[17], 1);
                _backContainer.drawRect(0, 0, input.width, input.height);
                _backContainer.endFill();
            }
        });

        function hideAnimationBack(input)
        {
            if (_currAnimationBack)
            {
                _currAnimationBack.hide(input);
                _currAnimationBack = null;
            }
        }

        function showAnimationBack(input)
        {
            hideAnimationBack(input);

            _currAnimationBack = _defaultAnimBack;
            _currAnimationBack.init(input, animationEndedBack);
            _backWrapper.addChild(_currAnimationBack);
        }

        function animationEndedBack(input)
        {
            _currAnimationBack = null;
        }

        function addArtNodes(count, pos, input)
        {
            var i = 0;
            var l = count || Math.ceil(5 + Math.random() * 15);
            var mouse = pos || input.mouseTouchPosition;

            if (!mouse.x || !mouse.y)
            {
                mouse = {
                    x: input.width / 2,
                    y: input.height
                };
            }

            var direction;
            var speed;
            var angleInRadians;
            var velocity;
            var gfx;
            var gravity;
            var defaultSpeed;

            var node;

            for (i; i < l; i++)
            {
                direction = Math.random() * -180;
                defaultSpeed = input.isTouchDevice ? 2 : 10;
                speed = Math.random() * 6 + defaultSpeed; // 15;
                angleInRadians = direction * Math.PI / 180;
                velocity = {
                    x: Math.cos(angleInRadians) * speed,
                    y: Math.sin(angleInRadians) * speed - 10
                };
                gfx = _gfxArrBack[Math.floor(Math.random() * _gfxArrBack.length)];
                gravity = 0.2 + Math.random() * 0.4;

                node = new ArtNode(gravity, velocity, gfx, mouse, _nodesArr);
                node._index = i;
                node.draw(input);

                _nodesArr.push(node);
                _backContainer.addChild(node);
            }
        }



        // ============================================== XX
        function ArtNode(gravity, velocity, gfx, mouse, arr)
        {
            var _node = new PIXI.Graphics();

            var _gravityConstant = gravity || 0.4;
            var _velocity = velocity;
            var _mouse = mouse;
            var _gfx = gfx;
            var _arr = arr;

            var _physicsNode;
            var _sprite;

            var _step = 0;

            function init()
            {
                var scale = 0.1 + Math.random() * 0.1;
                _node.scale.set(scale, scale);

                _sprite = new PIXI.Sprite(_gfx);
                _sprite.anchor.set(0.5, 0.5);
                _node.addChild(_sprite);

                disableInteraction(_node);
                disableInteraction(_sprite);

                _physicsNode = new PhysicsNode(_gravityConstant, _velocity, _mouse);
            }

            _node.draw = function(input)
            {
                _step += 0.1; //0.05;

                _physicsNode.draw();

                this.rotation = _physicsNode._rotation;
                this._position = _physicsNode._position;
                this.position.set(this._position.x, this._position.y);

                this.checkWallBounds(input);
            };

            _node.checkWallBounds = function(input)
            {
                if (this._position.y > input.height || this._position.x > input.width || this._position.x < 0)
                {
                    this.kill();
                }
            };

            _node.kill = function()
            {
                if (!_node)
                    return;

                var index = _arr.indexOf(_node);
                if (index > -1)
                {
                    // _arr[index] = null;
                    _arr.splice(index, 1);
                }

                this.visible = false;
                this.renderable = false;

                _physicsNode.kill();

                if (_sprite.parent)
                    _sprite.parent.removeChild(_sprite);
                if (_sprite.destroy)
                    _sprite.destroy();

                if (_node.parent)
                    _node.parent.removeChild(_node);
                if (_node.destroy)
                    _node.destroy();

                _node = null;
            };

            init();

            return _node;
        }

        function PhysicsNode(gravity, velocity, pos)
        {
            var _node = {};

            var _velocity = velocity;
            var _pos = pos;

            var _gravityConstant = gravity || 0.3;
            var _gravityV = new Victor(0, 0);
            var _resetV = new Victor(0, 0);

            function init()
            {
                _node._acceleration = new Victor(0, 0);
                _node._velocity = new Victor(_velocity.x, _velocity.y);
                _node._position = new Victor(_pos.x, _pos.y);
                _node._rotation = 0;
            }

            _node.draw = function()
            {
                if (_gravityConstant)
                {
                    _gravityV.y = _gravityConstant;
                    this._acceleration.add(_gravityV);
                }

                this._velocity.add(this._acceleration);
                this._position.add(this._velocity);
                this._acceleration.multiply(_resetV);
                this._rotation += Math.PI * this._velocity.x / 300;
            };

            _node.kill = function()
            {
                if (!_node)
                    return;

                _node._acceleration = null;
                _node._velocity = null;
                _node._position = null;

                _gravityV = null;
                _resetV = null;

                _node = null;
            };

            init();

            return _node;
        }



        // ============================================== XX
        function Victor(x, y)
        {
            var _instance = {
                x: x || 0,
                y: y || 0
            };

            _instance.add = function(vec)
            {
                this.x += vec.x;
                this.y += vec.y;
                return this;
            };

            _instance.multiply = function(vector)
            {
                this.x *= vector.x;
                this.y *= vector.y;
                return this;
            };

            return _instance;
        }

        function disableInteraction(el)
        {
            el.visible = true;
            el.renderable = true;
            el.interactive = false;
            el.buttonMode = false;
        }



        SPF.info(
        {
            debug: false,
            tip: "Click/tap anywhere to get artsy",
            title: "Carry carry on",
            firstName: "Younus",
            lastName: "Abdalla",
            email: "hi@younusabdalla.com",
            section: "s6"
        });

        SPF.start("preChorus2");
              
            
!
999px

Console