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

Auto Save

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

              
                <main>  
    
  <main-sidebar>
    
    <div class="button-group">
      <button id="clear">Clear</button>
      <button id="play" disabled>Play</button>
    </div>
    
    <text-container>
      <textarea id="text" cols="30" rows="10"></textarea>
    </text-container>
    
  </main-sidebar>
  
  <main-content>
    <canvas id="canvas" resize></canvas>
  </main-content>
  
</main>

<!-- Browser won't load font until it's actually requested -->
<div class="temp-element" style="visibility: hidden; font-family: 'alpha_echoregular';position:absolute">i</div>
              
            
!

CSS

              
                @font-face {
  font-family: "alpha_echoregular";
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.eot");
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.eot?#iefix") format("embedded-opentype"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.woff") format("woff"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.ttf") format("truetype"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.svg#alpha_echoregular") format("svg");
  font-weight: normal;
  font-style: normal;
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

main {
  position: relative;
  flex: 1;  
  display: flex;
  flex-direction: row;  
  overflow: hidden;
}

button {
  background: none;
  border: 2px solid #616161;
  outline: 0;
  padding: 8px 16px;
  margin: 0 6px 0 0;
  color: #ccc;
  cursor: pointer;
  
  &[disabled] {
    opacity: 0.4;
    cursor: default;
  }
}

main-sidebar {
  position: relative;
  flex: 0 0 300px;
  max-width: 300px;
  max-height: 100vh;
  flex-direction: column;
  display: flex;
  background: #303030;
  box-shadow: 0 8px 9px -5px rgba(0,0,0,.2),0 15px 22px 2px rgba(0,0,0,.14),0 6px 28px 5px rgba(0,0,0,.12);  
  z-index: 1000; 
}

main-content {
  position: relative;
  flex: 1; 
  display: flex;
}

text-container {
  position: relative;
  flex: 1;
  display: flex;
  padding: 0 15px 15px;  
}

#text {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  padding: 10px;
  color: #ccc;
  background: #424242;  
  border: 0;
  resize: none;
}

.button-group {
  padding: 20px 15px 15px; 
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

              
            
!

JS

              
                
namespace App {
  
  console.clear();
  const log = _.bind(console.log, console);
  
  var baseURL = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/"
  
  var isDirty = false;
  
  var $window = $(window);
  var $clear  = $("#clear");
  var $play   = $("#play");
  var $text   = $("#text");
    
  $text.val(`GSAP &\nPaper.js\nšŸ”„šŸ˜šŸ˜šŸ˜€šŸ˜ŽšŸ˜€šŸ™ƒšŸ˜œšŸ˜`);
  
  // paper.install(this);
  paper.setup("canvas");
  
  var project = paper.project;
  var view = paper.view;
  
  var padding = 25;
  
  var baseStyle = {
    font: "alpha_echoregular",
    fillColor: "#333",
    blendMode: "color-burn",      
    shadowBlur: 0.5,
    shadowColor: new paper.Color(0, 0, 0, 0.75),
    shadowOffset: new paper.Point(0.3, 0.3)
  };
    
  var styles = [            
    _.defaults({ fillColor: "#009688" }, baseStyle),
    _.defaults({ fillColor: "#9c27b0" }, baseStyle),
    _.defaults({ fillColor: "#244191" }, baseStyle), 
    _.defaults({ fillColor: "#ac286e" }, baseStyle),   
    _.defaults({ fillColor: "#4d4b4c" }, baseStyle),       
    _.defaults({ fillColor: "#e8405d" }, baseStyle),
    _.defaults({ fillColor: "#2196f3" }, baseStyle),
  ];
  
  var numStyles = styles.length;
     
  var bounds = new paper.Rectangle({
    size: view.size.subtract(padding * 2),
    center: view.center
  });
      
  var raster = new paper.Raster(baseURL + "grunge-paper-bg.jpg?v=1");
  raster.onLoad = function() {
    raster.fitBounds(view.bounds, true);
    onLoad();
  }
  
  var layer = new paper.Layer({
    applyMatrix: false
  });
  
  var groups = [];
  
  view.on({ resize, frame });
  // $window.on("load", onLoad);
    
  function init() {
    
    layer.removeChildren();
        
    var text = _.compact(_.trim($text.val()).split(/\n\n/gm));
           
    groups = _.map(text, createTextGroup);
        
    if (!groups.length) return;
        
    _.forEach(groups, group => {
      
      var bounds = group.bounds;
            
      var rect = new paper.Path.Rectangle({
        point: bounds.point,
        size: bounds.size,
        selected: true
      });
    });
    
    fitView();
  }
    
  function createTextGroup(text, index) {
        
    var style = styles[index % numStyles];
    var group = new paper.Group(style);
    
    var prev  = group.previousSibling;
    var point = prev ? prev.bounds.bottomRight : new paper.Point(padding, padding);
    
    var lines = _.compact(_.split(text, /\n/gm));
           
    _.forEach(lines, line => {
      
      var lineItem = createLineText(line, point, style);
      group.addChild(lineItem);
      point = new paper.Point(point.x, point.y + lineItem.bounds.height);
    });
    
    if (group.previousSibling) {
      group.pivot = group.parentToLocal(group.bounds.topLeft);
      group.position = prev.bounds.bottomRight;
    }
    
    return group;
  }
    
  function createLineText(text, point, style) {
    
    var group = new paper.Group();
    var words = _.split(text, " ").filter(txt => !!_.trim(txt));    
    var last  = _.last(words);
    
    _.forEach(words, word => {
      
      var pad = word === last ? " " : "";      
      var wordItem = createWordText(" " + word + pad, point, style);
      group.addChild(wordItem);
      point = new paper.Point(point.x + wordItem.bounds.width, point.y);
    });
        
    return group;
  }
  
  function createWordText(text, point, style) {
    
    var config = _.defaults({
      point: point,
      content: text
    }, style);
    
    return new paper.PointText(config);
  }
  
  function fitView() {
        
    var w1 = bounds.size.width;
    var h1 = bounds.size.height;
    
    var w2 = layer.bounds.size.width;
    var h2 = layer.bounds.size.height;
    
    var sx = w1 / w2;
    var sy = h1 / h2;
    
    var scale = Math.min(sx, sy);
        
    if (!_.isFinite(scale)) {
      scale = 1;
    }
    
    TweenLite.to(layer.bounds, 0.2, {
      x: padding,
      y: padding,
      width:  Math.max(w2 * scale, 1),
      height: Math.max(h2 * scale, 1)
    });
  }
  
  function resize() {
    
    bounds.size = view.size.subtract(padding * 2);
    bounds.center = view.center;    
    raster.fitBounds(view.bounds, true);    
    fitView();
  }
  
  function clearText() {
    $text.val("");
    isDirty = true;
  }
  
  function frame() {
    
    if (isDirty) {
      init();
      isDirty = false;
    }
  }
  
  function input() { 
    isDirty = true;
  }
  
  function onLoad() {
        
    $(".temp-element").remove();    
    $text.on("input", input);
    $clear.click(clearText);
    isDirty = true;
  }
}
              
            
!
999px

Console