cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="coordinate-pane">
  <div class="coordinate-pane__inner">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 218 218">
      <line x1="20" y1="144" x2="198" y2="72" stroke="#9E9E9E"/>
      <g>
        <circle cx="20" cy="144" r="10" fill="#8A81AE"/>
        <text x="20" y="144" font-size="8" stroke-width="1" text-anchor="middle" dy="2.5em">A</text>
      </g>
      <g>
        <circle cx="198" cy="72" r="10" fill="#8A81AE"/>
        <text x="198" y="72" font-size="8" stroke-width="1" text-anchor="middle" dy="2.5em">B</text>
      </g>
      <g>
        <circle cx="20" cy="144" r="4" fill="#000"/>
        <text x="20" y="144" font-size="6" stroke-width="1" text-anchor="middle" dy="2em">P</text>
      </g>
    </svg>
  </div>
</div>

<button class="interpolate-btn">Interpolating</button>
            
          
!
            
              html,
body {
  padding: 0;
  margin: 0;
}

.coordinate-pane {
  width: 218px;
  height: 218px;
  margin-top: 10px;
  margin-left: 10px;
  border: 1px solid #ebebeb;

  &__inner {
    position: relative;
    width: 100%;
    height: 100%;
  } 
}

button {
  margin-left: 10px;
}

            
          
!
            
              const controlPointA = document.getElementsByTagName('circle')[0];
const controlPointB = document.getElementsByTagName('circle')[1];
const midpoint = document.getElementsByTagName('circle')[2];
const midpointText = document.getElementsByTagName('text')[2];
const interpolateBtn = document.getElementsByClassName('interpolate-btn')[0];
const Ax = parseInt(controlPointA.getAttribute('cx'), 10);
const Ay = parseInt(controlPointA.getAttribute('cy'), 10);
const Bx = parseInt(controlPointB.getAttribute('cx'), 10);
const By = parseInt(controlPointB.getAttribute('cy'), 10);

function blender(A, B, t) {
    if (t === 0) {
        return A;
    }

    if (t === 1) {
        return B;
    }

    return ((1 - t) * A) + (t * B); // or A + t * (B - A)
}

function interpolator(Ax, Bx, Ay, By, duration) {
  return function(update) {
    const blendX = blender.bind(null, Ax, Bx);
    const blendY = blender.bind(null, Ay, By);
    let startTime = 0;
    
    function step(timestamp) {
      if (!startTime) {
        startTime = timestamp;
      }

      const pastTime = timestamp - startTime;
      let progress = pastTime / duration;
      
      if (progress > 1) {
        update(blendX(1), blendY(1));
        return;
      }

      update(blendX(progress), blendY(progress));

      requestAnimationFrame(step);
    }
    
    requestAnimationFrame(step);
  }
}

const interpolate = interpolator(Ax, Bx, Ay, By, 1000);

interpolateBtn.addEventListener('click', function() {
  interpolate(function(x, y) {
    // do interpolating.
    midpoint.setAttribute('cx', x);
    midpoint.setAttribute('cy', y);
    midpointText.setAttribute('x', x);
    midpointText.setAttribute('y', y);
  });
});

            
          
!
999px
Loading ..................

Console