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 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

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>
  <button id="play">Play</button>
</div>

<svg width="1000" height="1000">
  <svg x="200" y="200" width="200" height="200" overflow="visible">
    <!--<text font-family="sans-serif" y="-3%" opacity=".3">time</text>-->
    
    <rect width="100%" height="100%" fill-opacity=".5"  stroke="black" stroke-width="1" />
    <line id="progress" x1="0" y1="200" x2="215" y2="200" stroke="darkred" opacity="0"/>
    
    <!--<text font-family="sans-serif" y="107%" x="-100%" opacity=".3" transform="rotate(-90)">progress</text>-->
    <path id="curve" fill="none" stroke="#000000" stroke-miterlimit="10" d="M0,200C140,140,180,40,200,0"/>
    
    
    
    <line id="line1" y1="200" x2="140" y2="140" stroke="darkgrey"/>
    <line id="line2" x1="200" x2="180" y2="40" stroke="darkgrey"/>
    
    <circle class="handle" cx="0" cy="200" r="5" />
    <circle class="handle" cx="170" cy="180" r="5" cursor="move" />
    <circle class="handle" cx="20" cy="20" r="5" cursor="move" />
    <circle class="handle" cx="200" cy="0" r="5"/>
    
    <polyline id="plotter" fill="none" stroke="tomato" stroke-width="2"></polyline>
    <circle id="point" cx="0" cy="0" r="8" fill="yellowgreen" stroke="#333" />
    
  </svg>
</svg>
<!--<input id="timeSlider" type="range" min="0" max="1" step=".01" value="0" oninput="sliderUpdate(event)">-->




              
            
!

CSS

              
                body{
  background:grey;
  margin:0;
}
#timeSlider{
  position:absolute;
  left:200px;
  top:410px;
  width:200px;
}
              
            
!

JS

              
                var p0, p1, p2, p3, q0, q1, q2, r0, r1, target,selectedHandle;
var point=document.querySelector("#point");
var progressLine=document.querySelector("#progress");
var handles = document.querySelectorAll(".handle");
var line1=document.querySelector("#line1");
var line2=document.querySelector("#line2");
var curve=document.querySelector("#curve");
var progress=0;
update(progress);



var h = 200;
var w = 200;
TweenLite.set(point, { x: 0, y: 200 });

var tween = TweenMax.to(point, 3, {
  y: 0,
  ease: update,
  onUpdate: function() {
    var y = point._gsTransform.y;
    var x = this.progress() * w;
    TweenLite.set(point, { x: x });
    points.push(x,y);
    plotter.setAttribute("points", points);
  }
});

var plotter = document.querySelector("#plotter");
var points = [];

document.querySelector("#play").addEventListener("click", function() {
  plotter.setAttribute("points", (points = []));
  tween.restart();
});


function update(time, start, change, duration) {
//function update(percent) {

  var percent = (time / duration) || 0;
  progress=percent;

  for (var p = 0; p < 4; p++) {
    var handle = handles[p];
    if(p>0&p<=2){
      handle.addEventListener("mousedown",onDown);
    }
    this["p" + p] = {
      x: Number(handle.getAttribute("cx")),
      y: Number(handle.getAttribute("cy"))
    };
  }
  for (var q = 0; q < 3; q++) {
    this["q" + q] = getPoint(this["p" + q], this["p" + (q + 1)], percent);
  }
  for (var r = 0; r < 2; r++) {
    this["r" + r] = getPoint(this["q" + r], this["q" + (r + 1)], percent);
  }
  target=getPoint(r0,r1,percent);
  
  /*point.setAttribute("cx", target.x);
  point.setAttribute("cy", target.y);*/
  progressLine.setAttribute("y2", target.y);
  progressLine.setAttribute("y1", target.y);
  line1.setAttribute("x2", p1.x);
  line1.setAttribute("y2", p1.y);
  line2.setAttribute("x2", p2.x);
  line2.setAttribute("y2", p2.y);
  curve.setAttribute("d", "M0,200C"+[p1.x,p1.y,p2.x,p2.y]+",200,0");
  
  var y = 1 - target.y / h;
  return y;
}

function onDown(e){
  selectedHandle=e.target;
 window.addEventListener("mouseup",onUp); window.addEventListener("mousemove",onDrag);
}
function onUp(e){
 window.removeEventListener("mouseup",onUp); window.removeEventListener("mousemove",onDrag);
}
function onDrag(e){
  selectedHandle.setAttribute("cx",e.clientX-200);
  selectedHandle.setAttribute("cy",e.clientY-200);
  update(progress);
  
}

function getPoint(point1, point2, percent) {
  return {
    x: interpolate(point1.x, point2.x, percent),
    y: interpolate(point1.y, point2.y, percent)
  }
}

function interpolate(min, max, percent) {
  return (1 - percent) * min + percent * max;
}
function sliderUpdate(e){
  update(e.target.value);
}
              
            
!
999px

Console