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

              
                <div id="container">
  <p>a</p>
  <canvas id="text" width="700 height="100"></canvas>
</div>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Montserrat:700);

body {
  background: #555;
  height: 100%;
}

p {
  color: #555;
}

* {
  font-family: Montserrat;
  font-weight: 700;
}

#container {
  position: relative;  
  width: 100%;
  height: 100%;
}

canvas {
  left: 50%;
  top: 20px;
  margin-left: -350px;
  position: absolute;
  display: block;
}
              
            
!

JS

              
                (function(){
    var stage, textStage, textCTX, form, input;
    var hair = [], textPixels, textFormed;
    var offsetX, offsetY, text, renderer;
    var hairBitmaps = ['https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair1.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair2.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair3.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair4.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair5.png', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/53148/hair6.png'];
    var _mousePos = {x: 0, y: 0};

    function init() {
        initStages();
        initText();
        addListeners();
        resize();
        setTimeout(function() {
          createText('CODEPEN');
          animate();
        }, 200);
    }

    // Init Canvas
    function initStages() {
        textStage = document.getElementById("text");
        textStage.width = 700;
        textStage.height = 200;
        textStage.style.left = offsetX+'px';
        textStage.style.top = offsetY+'px';
        textCTX = textStage.getContext('2d');
        var rendererOptions = {
            transparent:true,
        }
        stage = new PIXI.Stage(0x66FF99);
        renderer = PIXI.autoDetectRenderer(700, 200, rendererOptions);
        document.getElementById('container').appendChild(renderer.view);
    }


    function initText() {
        textCTX.font = "700 80px 'Montserrat'";
        textCTX.fillStyle = '#555';
        textCTX.fillText("t", 350, 150);
        textCTX.textAlign = 'center';
    }

    function createHair(x, y) {
      var bitmap;
      if (x < 130) bitmap = 0;
      else if (x < 230) bitmap = 1;
      else if (x < 330) bitmap = 2;
      else if (x < 410) bitmap = 3;
      else if (x < 480) bitmap = 4;
      else if (x < 570) bitmap = 5;
      else bitmap = 6;
      
      var texture = PIXI.Texture.fromImage(hairBitmaps[bitmap]);
      // create a new Sprite using the texture
      var hairBit = new PIXI.Sprite(texture);

      // center the sprites anchor point
      hairBit.anchor.x = 0.1;
      hairBit.anchor.y = 0.1;
      hairBit.width = 30;
      hairBit.height = 30;
      hairBit.targetAngle = 0;
      hairBit.rotation = 0;
      
      // move the sprite t the center of the screen
      hairBit.position.x = x;
      hairBit.position.y = y;

      stage.addChild(hairBit);
      hair.push(hairBit);
      randomize(hairBit);
    }
  
    function randomize(bit) {
      bit.targetAngle = (bit.rotationAngle || 0) + (-0.2 + Math.random()*0.4);
      setTimeout(function() {
        randomize(bit);
      }, 100+Math.random()*200);
    }
  
    // animating circles
    function animate() {
        var l = hair.length;
        for(var i = 0; i < l; i++) {
          hair[i].rotationAngle = Math.atan2(hair[i].position.y - _mousePos.y, hair[i].position.x - _mousePos.x);
          hair[i].rotation += (hair[i].targetAngle - hair[i].rotation)*0.05;
        }
      
        renderer.render(stage); 
        requestAnimationFrame(animate);
    }

    function formText() {
        for(var i= 0, l=textPixels.length; i<l; i++) {
            createHair(textPixels[i].x, textPixels[i].y) 
        }
        textFormed = true;
        
    }


    // event handlers
    function addListeners() {
        window.addEventListener('resize', resize); 
        window.addEventListener('mousemove', function(e) {
          _mousePos.x = e.pageX - offsetX;
          _mousePos.y = e.pageY - offsetY;
        })
    }
  
    function resize() {
        offsetX = (window.innerWidth - 700)/2;
        offsetY = 20;
        textStage.style.left = offsetX+'px';
        textStage.style.top = offsetY+'px';
    }

    function createText(t) {
        var fontSize = 840/(t.length);
        
        if (fontSize > 160) fontSize = 160;
        textCTX.clearRect(0,0,700,200);
        textCTX.font = "400 "+fontSize+"px 'Montserrat'";
        textCTX.textAlign = 'center';
        textCTX.textBaseline = 'top';
        textCTX.fillText(t, 350, (172-fontSize)/2);
      
        var ctx = document.getElementById('text').getContext('2d');
        var pix = ctx.getImageData(0,0,700,200).data;
        textPixels = [];
        for (var i = pix.length; i >= 0; i -= 4) {
            if (pix[i] != 0) {
                var x = (i / 4) % 700;
                var y = Math.floor(Math.floor(i/700)/4);

                if((x && x%4 == 0) && (y && y%4 == 0)) textPixels.push({x: x, y: y});
            }
        }

        formText();

    }

    window.onload = function() { init() };
})();
              
            
!
999px

Console