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

              
                <div class="wrap">
  <svg id="stage" width="500" height="240"></svg>
  <div class="buttons">
    <span id="out">out</span>
    <span id="in">in</span>
  </div>
</div>


              
            
!

CSS

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

body {
  background: #d4d6d7;
  font-family: 'Allerta', sans-serif;
  color: #fff;
}

svg {
  position: relative;
  background: #dddee0;
}

.wrap {
  width: 500px;
  left: 50%;
  top: 30px;
  margin-left: -250px;
  position: relative;
  height: 40px;
}

.buttons {
  width: 500px;
  top: 15px;
  text-transform: uppercase;
}

span {
  display: inline-block;
  padding: 5px 12px;
  background: #222;
  cursor: pointer;
  position: relative;
}



              
            
!

JS

              
                (function() {
    var width = 500;
    var height = 240;
    var stage, stagel; 
    var stageel; 
    var vertices = [], triangles, tris = [];
    var mousedOver = false;
    var status = 'in';
    var outBtn = document.getElementById('out');
    var inBtn = document.getElementById('in');
  
    function init() {
      stage = Snap('#stage');
      stageel = document.getElementById('stage');
      createTriangles();
      tris.sort(function(a,b) {
        return (b.d2 - a.d2);
      });
      addEvents();
      render();
    }
  
    function createTriangles(callback) {
        // get the points
        for(var x = 0; x <= width; x += 50) {
            for(var y = 0; y <=height; y += 30) {
                var xp, yp;
                if(x && (x != width)) xp = x+(-10+Math.random()*20); else  xp = x;
                if(y && (y != height)) yp = y+(-10+Math.random()*20); else yp = y;
                vertices.push([xp,yp]);
            }
        }
  
        triangles = Delaunay.triangulate(vertices);
      
        for(var i = triangles.length; i>0; i = i-3 ) {
            drawTriangle(i);
        }
    }
  
    function drawTriangle(i) {
        var poly = stage.polygon([vertices[triangles[i-1]][0], vertices[triangles[i-1]][1], vertices[triangles[i-2]][0], vertices[triangles[i-2]][1],
            vertices[triangles[i-3]][0], vertices[triangles[i-3]][1]]);
        poly.centroid = {x: (vertices[triangles[i-1]][0] + vertices[triangles[i-2]][0] + vertices[triangles[i-2]][0]) / 3,
                         y: (vertices[triangles[i-1]][1] + vertices[triangles[i-2]][1] + vertices[triangles[i-2]][1]) / 3};

        poly.d2 = Math.pow((poly.centroid.x - 0),2) + Math.pow((poly.centroid.y - 150),2);

        poly.attr({
            fill: '#36ae7d',
            stroke: '#36ae7d'
        });

        tris.push(poly);

        poly.matrix = new Snap.Matrix();
        poly.translatedPos = {x: 0, y: 0};
        poly.targetPos = {x: 550+Math.random()*100, y: -240-Math.random()*100};
    }
  
    function render() {
      for(var i in tris) { 
        if(tris[i].tweenOut) {
          tris[i].matrix.translate((tris[i].targetPos.x-tris[i].translatedPos.x)*0.02,(tris[i].targetPos.y-tris[i].translatedPos.y)*0.02);
          tris[i].transform(tris[i].matrix);
          tris[i].translatedPos.x += (tris[i].targetPos.x-tris[i].translatedPos.x)*0.02;
          tris[i].translatedPos.y += (tris[i].targetPos.y-tris[i].translatedPos.y)*0.02; 
        } else if(tris[i].tweenIn) {
          tris[i].matrix.translate((0-tris[i].translatedPos.x)*0.07,(0-tris[i].translatedPos.y)*0.07);
          tris[i].transform(tris[i].matrix);
          tris[i].translatedPos.x += (0-tris[i].translatedPos.x)*0.07;
          tris[i].translatedPos.y += (0-tris[i].translatedPos.y)*0.07; 
        }
      }
      requestAnimationFrame(render);
    }
  
    function addEvents() {
      outBtn.onclick = tweenOut;
      inBtn.onclick = tweenIn;
    }
  
    function tweenOut() {
      var delay = 0;
      for(var i in tris) {
        tweenOutTri(tris[i], delay);
        delay += Math.random()/40;
      }
    }
  
    function tweenIn() {
      var delay = 0;
      for(var i = tris.length-1; i>=0; i--) {
        tweenInTri(tris[i], delay);
        delay += Math.random()/40;
      }
    }
  
    function tweenOutTri(t, delay) {
      setTimeout(function() {
        var r = (30+Math.random()*60)/100;
        t.attr({ 
          fillOpacity: r,
          stroke: ''
        });
        t.tweenIn = false;
        t.tweenOut = true;
      }, delay*200);
      
    }
  
    function tweenInTri(t, delay) {
      setTimeout(function() {
        var r = (30+Math.random()*60)/100;
        t.attr({ 
          fillOpacity: 1
        });
        t.tweenOut = false;
        t.tweenIn = true;
      }, delay*200);
    }
  
  window.onload = init();
})();
              
            
!
999px

Console