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

              
                <main>  
  <svg viewBox="0 0 1200 870" preserveAspectRatio="xMinYMin meet" style="enable-background:new 0 0 1200 870;">
    
    <defs>
      <path id="motion-path" d="M 331 162 C 359.8 129.7 399.1 107.2 441.3 97.6 C 483.5 88.1 528.4 91.5 569 106.5 C 609.6 121.4 645.8 147.8 673.1 181.4 C 700.5 214.9 719 255.4 727.4 297.8 C 744.2 382.7 719.1 473.6 666.4 542.2 C 613.7 610.8 535.1 657.6 451 678 C 408.1 688.4 363.4 692.3 319.6 687.1 C 275.7 681.9 232.7 667.4 196 643 C 159.2 618.6 128.8 584.1 111.3 543.5 C 93.8 503 89.7 456.4 102 414 C 110.9 383.3 128.2 355.1 151.5 333.2 C 174.7 311.3 203.8 295.6 234.8 288.1 C 265.9 280.7 298.9 281.3 329.6 289.9 C 360.4 298.4 389 314.8 412 337 C 449.9 373.5 472.2 426.5 468.6 479 C 466.8 505.3 458.7 531.1 444.8 553.5 C 430.9 575.8 411.2 594.6 388 607 C 355.9 624.2 317.5 628.9 282 621 C 254.9 615 229.2 601.7 209.7 581.9 C 190.2 562.1 177.2 535.7 175 508 C 173.5 488.9 177 469.6 184.7 452.1 C 192.3 434.6 204.1 418.9 218.4 406.3 C 247.2 381.1 285.8 368.5 324 368 C 365.7 367.4 406.7 380.5 443.5 400.1 C 480.3 419.7 513.3 445.7 545.2 472.6 C 577.1 499.4 608.2 527.4 642.2 551.5 C 676.2 575.6 713.5 596 754 606 C 801.2 617.6 851.9 614.4 897.6 597.6 C 943.2 580.8 983.7 550.5 1013.2 511.8 C 1042.8 473.2 1061.4 426.3 1067 378 C 1072.7 329.7 1065.5 280 1047 235 C 1026.5 185.1 992 140.9 947.8 110 C 903.7 79 849.9 61.6 796 62 C 753.9 62.3 711.8 73.5 675.8 95.1 C 639.7 116.7 609.8 148.9 592 187 C 572.6 228.5 567.9 276.6 577.8 321.4 C 587.6 366.1 611.7 407.5 645 439 C 674.9 467.2 711.4 487.4 748.3 505.3 C 785.3 523.3 823.3 539.4 858.3 561 C 893.2 582.7 925.4 610.4 945.4 646.4 C 955.3 664.4 962.1 684.2 964.1 704.7 C 966.1 725.1 963.2 746.2 955 765 C 947.2 782.8 934.7 798.4 919.6 810.6 C 904.5 822.8 886.9 831.8 868.4 837.8 C 831.5 849.7 791.7 849.8 753 846 C 648.1 835.7 545.9 796.8 462 733 C 398.4 684.6 345.4 621.9 310.9 549.9 C 276.5 477.8 260.8 396.5 269 317 C 274.8 260.7 293.3 204.2 331 162" />
    </defs>
    
    <image id="image" width="1200" height="870" x="0" y="0" />    
    <rect id="rect" width="75" height="75" x="0" y="0" />
    
  </svg>
</main>

              
            
!

CSS

              
                html, body {
  height: 100%;
}

body {
  overflow: hidden;
  background: #000;
}

main {
  visibility: hidden;
  opacity: 0;
}

svg, canvas {
  position: absolute;
  width: 100%;
  height: 100%;  
  max-height: 870px;
}

#rect {
  fill: cornflowerblue;
}

              
            
!

JS

              
                console.clear();

var values  = MorphSVGPlugin.pathDataToBezier("#motion-path");
var image   = document.querySelector("#image");
var rect    = document.querySelector("#rect");
var linear  = Linear.easeNone;

var steps  = 1000;
var speeds = [];
var lines  = [];

var speed = {
  now: 1,
  min: 0.5,
  max: 2.5,
  ratio: 0.5,
  step: 0.015
};

var size = { 
  x: 1200, 
  y: 870 
};

TweenLite.set(rect, { 
  x: values[0].x, 
  y: values[0].y, 
  xPercent: -50,   
  yPercent: -50,   
  transformOrigin: "50% 50%" 
});

var bezierTween = TweenLite.to(rect, 1, {
  bezier: { values, autoRotate: true, type: "cubic" },
  paused: true, 
  ease: linear
});

var progressTween = TweenMax.to(bezierTween, 5, {
  progress: 1,
  repeat: -1,
  onStart: setSpeed,
  onUpdate: setSpeed,
  ease: linear
}); 

var transform = rect._gsTransform;

createSpeedPath();

TweenLite.to("main", 0.5, { autoAlpha: 1 });

//
// SET SPEED
// ===========================================================================
function setSpeed() {
  
  var index = Math.round(progressTween.progress() * 1000);
  
  TweenLite.to(progressTween, 0.2, { timeScale: speeds[index] });
}

//
// CREATE SPEED PATH
// ===========================================================================
function createSpeedPath() {
  
  for (var loops = 0; loops < 2; loops++) {    
    for (var i = 0; i <= steps; i++) {
      
      bezierTween.progress(i * 0.001);
      
      var rot  = transform.rotation % 90;
      var sign = rot < 0 ? -1 : 1;
      var mult = Math.abs(rot / 90);      
      var diff = (speed.ratio + speed.step * sign * mult) || 0;
      
      speed.ratio = clamp(diff, 0, 1);
      
      if (!loops) continue;
            
      lines.push({ 
        stroke: lerpColor(speed.ratio), 
        x: transform.x, 
        y: transform.y 
      });
            
      speed.now = lerp(speed.min, speed.max, speed.ratio);
      
      speeds.push(speed.now);
    }
    
    speed.now = lerp(speed.min, speed.max, speed.ratio);
  } 
  
  bezierTween.progress(0);
  plotSpeed(size);
}

//
// PLOT SPEED
// ===========================================================================
function plotSpeed(size) {
    
  var canvas  = document.createElement("canvas");
  var context = canvas.getContext("2d");
  
  canvas.width  = size.x;
  canvas.height = size.y;
    
  var size = lines.length;  
  var prev = values[0];
  
  for (var i = 0; i < size; i++) {
    
    var line = lines[i];
    
    context.beginPath();    
    context.moveTo(prev.x, prev.y);     
    context.lineTo(line.x, line.y);
    context.lineWidth = 4;
    context.lineCap = "round";
    context.strokeStyle = line.stroke;
    context.stroke();
    
    prev = line;    
  }
  
  var dataURL = canvas.toDataURL("image/png");
  
  image.setAttributeNS("http://www.w3.org/1999/xlink", "href", dataURL);
}

//
// LERP COLOR
// ===========================================================================
function lerpColor(progress) {
  
  var color1 = [255, 0, 0];
  var color2 = [0, 255, 0];
  var result = [];
  
  for (var i = 0; i < 3; i++) {
    
    var rgb1 = Math.pow(color1[i], 2);
    var rgb2 = Math.pow(color2[i], 2);
       
    result[i] = Math.round(Math.sqrt(lerp(rgb1, rgb2, progress)));
  } 
  
  return `rgb(${result})`;
}

function lerp(start, stop, amt) {
  amt = clamp(amt, 0, 1);
  return start + (stop - start) * amt;
}

function clamp(value, a, b) {
  return value < a ? a : (value > b ? b : value);
}

              
            
!
999px

Console