css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="chart"></div>
<h1>Layered Voronis</h1>
<!-- luizneves.com -->
              body {
  background: rgb(28,28,28);
  position: relative;
  margin: 0;
  padding: 0;

  font-weight: 300;
  font-family: sans-serif;
  margin: 0;
  padding-top: 10%;
  text-align: center;
  color: whitesmoke;

#chart {
  top: 0;
  position: absolute;
  /* width: 100%; */
  /* height: 100%; */

rect {
  /* pointer-events: all; */
  /*try hiding the cursor... adds cool effect*/  
  /* cursor: none; */
/* default path variables.. feel free to uncomment other values to play with different colors easily */
path {
  /* pointer: none; */
  stroke: grey;
  /*stroke: whitesmoke;*/
  fill: none;
  /*fill: teal;*/
  /*fill: MediumTurquoise;*/
  /*fill: darkgreen;*/
  /*fill: black;*/
  fill-opacity: .2;
  stroke-opacity: .2;
  stroke-linejoin: round;
/* this is the polygons that will be moving around... try giving them a color! */
g path:first-child {
  /* fill: salmon; */
  /* stroke-opacity: .4; */

/* Every 6th polygon fill with a color */
g path:nth-child(6n) {
  /*fill: rgba(34,34,34,0);*/
  fill: rgb(25,164,151);
  /*fill: rgb(49,49,48);*/
  /*stroke: none;*/
              width = verge.viewportW();
height = verge.viewportH();

buildTess = function(width,height){
    // var counter = 0;
    var svg;
    var path,path2,path3;
    var animate;
    var points = 50;
    var width = width,
      height = height;
    var vertices,
    var point = [1,1];
    //setting x and y speed by % of viewport seems to give better performance then hard coded pixel amounts
    var xVelocity = width * 0.002;
    var yVelocity = height * 0.0025;


    function newVertices(points) {
      return d3.range(points).map(function(d) {
      return [Math.random() * width, Math.random() * height];

    var voronoi = d3.geom.voronoi()
        .clipExtent([[0, 0], [width, height]]);

    function zoomView() {
          var points = vertices.length;
          var fontSize = parseInt($("div.top h1").css("font-size").split("px")[0]);
          if (points >= 20) {
            points = points-10;
            $("div.top h1").css("font-size",fontSize+10);


    var drag = d3.behavior.drag()
        .on("dragstart", function() {
            //clear auto calling animate when dragging begins
        .on("drag", function(){
          //touch events
          touchXY = [d3.event.x,d3.event.y];
          point = touchXY;
        .on("dragend", function() {
          animate = setInterval(function(){render();}, 5);

      svg = d3.select("#chart").append("svg")
        .attr("width", width)
        .attr("height", height)
     //remove the following listeners if you simply want animation and no interaction 
        .on("mousemove", function() {
          //stop calling animate when mouse takes control
          var mouseXY = d3.mouse(this);
          point = mouseXY;
          var mouseXY = [d3.event.x,d3.event.y];
          point = mouseXY;
          //reduce number of nodes on screen to give illusion of zooming in
        .on('mouseleave', function() {
          //restart animation after mouse lives viewport
          animate  = setInterval(function(){render();}, 5);
      path = svg.append("g").selectAll("path");
      path2 = svg.append("g").selectAll("path");
      path3 = svg.append("g").selectAll("path");

      .attr("width", width)
      .attr("height", height);

  //kick off continuous animation... raising the interval will  trigger the browser to paint and actually reduce performance
  animate = setInterval(function(){render();}, 5);

  function render () {
    var crntX = point[0];
    var crntY = point[1];
    var newX, newY;
    //if moving point is at the right or left edges switch x direction
    if (crntX >= width || crntX <= 0 ) {
      xVelocity *= -1;
    //if moving point is at the top or bottom edges switch y direction
    if (crntY >= height || crntY <= 0 ) {
      yVelocity *= -1;
    newX = crntX + xVelocity;
    newY = crntY + yVelocity;

    point = [newX,newY];


  function  loadVertices(points){
    vertices = newVertices(points);
    vertices2 = newVertices(points);
    vertices3 = newVertices(points);

   function redraw(mouseXY) {
      vertices[0] = mouseXY;
      path = path.data(voronoi(vertices), polygon);
          .attr("d", polygon);

            vertices2[0] = mouseXY;
      path2 = path2.data(voronoi(vertices2), polygon);
          .attr("d", polygon);

            vertices3[0] = mouseXY;
      path3 = path3.data(voronoi(vertices3), polygon);
          .attr("d", polygon);

  function polygon(d) {
    return "M" + d.join("L") + "Z";

  function getRandom() {
    return Math.random() * (10 - 3) + 3;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................