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.

            
              <h4>Please drag the circles to reshape the polygon</h4>
<div id="contenedor">
<div class="text">
  <div id="shape"></div>
  <p>En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco y galgo corredor. Una olla de algo más vaca que carnero, salpicón las más noches, duelos y quebrantos los sábados, lentejas los viernes, algún palomino de añadidura los domingos, consumían las tres partes de su hacienda. El resto della concluían sayo de velarte, calzas de velludo para las fiestas con sus pantuflos de lo mismo, los días de entre semana se honraba con su vellori de lo más fino. Tenía en su casa una ama que pasaba de los cuarenta, y una sobrina que no llegaba a los veinte, y un mozo de campo y plaza, que así ensillaba el rocín como tomaba la podadera. Frisaba la edad de nuestro hidalgo con los cincuenta años, era de complexión recia, seco de carnes, enjuto de rostro; gran madrugador y amigo de la caza. uieren decir que tenía el sobrenombre de Quijada o Quesada (que en esto hay alguna diferencia en los autores que deste caso escriben), aunque por conjeturas verosímiles se deja entender que se llama Quijana; pero esto importa poco a nuestro cuento; basta que en la narración dél no se salga un punto de la verdad. </p>
</div>
<svg width="500" height="500" viewBox="0 0 500 500">
</svg>
</div>

            
          
!
            
              #contenedor{width: 700px;box-sizing:border-box; margin:1em auto;}
svg {
  /*border: 1px solid #d9d9d9;*/
  display: block;
  position: absolute;
}

.text {
  width: 700px;
  padding: .5em;
  border: 1px solid #d9d9d9;
  position: absolute;
  line-height:150%;
  
}

#shape {
  height: 500px;
  width: 500px;
  float: left;
  shape-margin:1em;
}

svg polygon {
  fill: #6ab150;
  fill-rule: evenodd;
}

svg circle {
  fill: rgba(200, 255, 255, .5);
  stroke: #ccc;
  cursor:ew-resize;
}

h4{text-align:center;}
            
          
!
            
              var SVG_NS = 'http://www.w3.org/2000/svg';
var XLink_NS = 'http://www.w3.org/1999/xlink';
var svg = document.querySelector("svg");
var contenedor = document.querySelector("#contenedor");
var elId, circ;
m = { // mouse position
  x: 0,
  y: 0
};
var dragging = false;

var ry = [];
ry[0] = {
  x: 100,
  y: 50
};

ry[1] = {
  x: 175,
  y: 120
};

ry[2] = {
  x: 200,
  y: 200
};

ry[3] = {
  x: 260,
  y: 270
};

ry[4] = {
  x: 250,
  y: 380
};

ry[5] = {
  x: 100,
  y: 430
};

function getPoints(ry) {
  var points = "0,0 ";
  for (var i = 0; i < ry.length; i++) {
    points += ry[i].x + "," + ry[i].y + " ";
  }
  points += "0,500"
  return points;
}

function drawPolygon(ry, polygon) {
  var points = getPoints(ry);
  polygon.setAttributeNS(null, 'points', points);
}

var polygon = document.createElementNS(SVG_NS, 'polygon');
drawPolygon(ry, polygon);
svg.appendChild(polygon);

for (var i = 0; i < ry.length; i++) {
  var circ = document.createElementNS(SVG_NS, 'circle');
  circ.setAttributeNS(null, 'cx', ry[i].x);
  circ.setAttributeNS(null, 'cy', ry[i].y);
  circ.setAttributeNS(null, 'r', "15");
  circ.setAttributeNS(null, 'id', "circ" + i);
  svg.appendChild(circ);
}

var c = document.querySelectorAll("svg circle");

svg.addEventListener("mousedown", function(evt) {
  if (evt.target.id.search("circ") == 0) {
    dragging = true;
    elId = evt.target.id.replace("circ", "");
    circ = c[elId];
  }
}, false);

svg.addEventListener("mousemove", function(evt) {
  if (dragging) {
    m = oMousePos(svg, evt);

    circ.setAttributeNS(null, 'cx', m.x);
    circ.setAttributeNS(null, 'cy', m.y);

    ry[elId].x = m.x;
    ry[elId].y = m.y;

    drawPolygon(ry, polygon);
    shapeOutsidePolygon(ry);

  }
}, false);

svg.addEventListener("mouseup", function(evt) {
  dragging = false;
}, false);

/*svg.addEventListener("mouseout", function(evt) {
  dragging = false;
}, false);*/

function oMousePos(el, evt) {
  var ClientRect = el.getBoundingClientRect();
  return { //objeto
    x: Math.round(evt.clientX - ClientRect.left),
    y: Math.round(evt.clientY - ClientRect.top)
  }
}


function shapeOutsidePolygon(ry){
  var shape_outside = "polygon(";
  for(var i = 0; i < ry.length; i++){
    shape_outside += ry[i].x + "px "+ry[i].y+"px,";

  }
  shape_outside += "0 500px)";
  console.clear();
  console.log(shape_outside)
  document.querySelector("#shape").style.webkitShapeOutside = shape_outside;
  document.querySelector("#shape").style.shapeOutside = shape_outside;
}

shapeOutsidePolygon(ry)
            
          
!
999px
🕑 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.

Console