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

              
                <canvas></canvas>
<svg viewBox="0 0 400 488">
  <path d="m 376.3299,351.06186 c 4.45361,47.0103 -51.46392,124.20619 -127.17526,105.40206 -75.71134,-18.80413 9.89692,-176.65979 69.7732,-140.53608 59.87628,36.12371 -80.02665,144.51868 -165.7732,140.53608 -51.44793,-2.38956 -95.0103,-28.70103 -80.65979,-101.4433 14.35051,-72.74227 207.83505,-255.3402 264.24742,-194.96907 56.41237,60.37113 -171.71134,177.15461 -229.60825,173.6907 -57.89691,-3.46391 -114.55671,-62.35051 -65.31959,-137.567 49.23712,-75.21649 131.76348,-45.721 131.76348,-45.721" fill="none" stroke="#4F7FFF" stroke-linecap="round" stroke-width="2" />
  <path d="M207.83505,122.567C243.83505,117 308.04124,69.98969 288.24742,21.49485C215.62887,21.49485 199.858,109.20619 203.01031,131.84536" fill="none" stroke="#4F7FFF" stroke-linecap="round" stroke-width="2" />
</svg>

              
            
!

CSS

              
                svg {
  width: 80vmin;
  opacity: 0;
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  transition: 0.15s ease-out;
  &:hover {
    opacity: 1;
  }
}
body {
  height: 100vh;
  overflow: hidden;
  cursor: pointer;
}
canvas {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
}
              
            
!

JS

              
                console.clear();

const canvas = document.querySelector('canvas');
const svg = document.querySelector('svg');
const ctx = canvas.getContext('2d');
let width = svg.clientWidth;
let height = svg.clientHeight;

canvas.width = width;
canvas.height = height;

const gradients = [
  [
    [0, [118, 179, 236]],
    [10, [41, 102, 193]],
    [20, [129, 77, 185]],
    [30, [129, 77, 185]],
    [50, [250, 148, 170]],
    [60, [237, 70, 54]],
    [70, [253, 134, 100]],
    [80, [254, 156, 33]],
    [90, [250, 213, 0]],
    [100, [171, 211, 96]]
  ],
  [
    [0, [1, 123, 147]],
    [100, [131, 201, 167]]
  ]
];

const dots = [];
class Dot {
  constructor (x, y, color, delay) {
    this.x = x;   
    this.y = y;
    this.r = 0;
    this.color = color;
    this.delay = (delay * 0.9);
    this.tween = gsap.fromTo(this, {
      r: 0,
      x: x - 0.05,
      y: y - 0.05
    }, {
      x: x,
      y: y,
      r: () => width * 0.03 + (Math.abs(Math.sin(this.delay * 3.4 - 1.5)) * width * 0.02),
      duration: 1.8,
      ease: 'elastic.out(1, 0.5)',
      delay: this.delay
    });
  }
  draw () {
    ctx.fillStyle = this.color;
    ctx.beginPath();
    ctx.arc(this.x * width, this.y * height, this.r, 0, 2 * Math.PI);
    ctx.fill();
  }
}

function init () {
  const paths = svg.querySelectorAll('path');
  const totalLength = [...paths].reduce((p) => p.getTotalLength());
  let sum_length = 0;
  paths.forEach((path, pathIndex) => {
    const length = path.getTotalLength();
    for (let i = 0; i < length; i+=2) {
      const point = path.getPointAtLength(i);
      const x = point.x / 400;
      const y = point.y / 488;
      const RGB_color = getColor(pathIndex, length, i / length);
      const color = `rgb(${RGB_color[0]}, ${RGB_color[1]}, ${RGB_color[2]})`;
      
      const dot = new Dot(x, y, color, (1.5 - (sum_length / totalLength)));
      dots.push(dot);
      sum_length += 2;
    }
  });
}

/* Code copied from https://stackoverflow.com/a/30144587 */
function pickHex(color1, color2, weight) {
  var p = weight;
  var w = p * 2 - 1;
  var w1 = (w/1+1) / 2;
  var w2 = 1 - w1;
  var rgb = [Math.round(color1[0] * w1 + color2[0] * w2),
      Math.round(color1[1] * w1 + color2[1] * w2),
      Math.round(color1[2] * w1 + color2[2] * w2)];
  return rgb;
}
function getColor(pathIndex, pathLength, colorIndex) {
  var colorRange = [];
  let stop = false;
  const gradient = gradients[pathIndex];
  gradient.forEach((step, index) => {
    if (!stop && (colorIndex * 100) <= step[0]) {
      if (index === 0) {
        index = 1;
      }
      colorRange = [index - 1, index];
      stop = true;
    }
  });

  //Get the two closest colors
  var firstcolor = gradient[colorRange[0]][1];
  var secondcolor = gradient[colorRange[1]][1];
  //Calculate ratio between the two closest colors
  var firstcolor_x = pathLength * (gradient[colorRange[0]][0]/100);
  var secondcolor_x = pathLength * (gradient[colorRange[1]][0]/100)-firstcolor_x;
  var slider_x = pathLength * colorIndex - firstcolor_x;
  var ratio = slider_x / secondcolor_x;

  //Get the color with pickHex(thx, less.js's mix function!)
  return pickHex(secondcolor, firstcolor, ratio);
}


function render () {
  requestAnimationFrame(render);
  ctx.clearRect(0, 0, width, height);
  dots.forEach(dot => {
    dot.draw();
  });
}

window.addEventListener('click', () => {
  dots.forEach(dot => {
    dot.tween.restart(true);
  });
});

window.addEventListener('resize', () => {
  width = svg.clientWidth;
  height = svg.clientHeight;

  canvas.width = width;
  canvas.height = height;
  dots.forEach(dot => {
    dot.tween.invalidate().restart(true);
  });
});

init();
requestAnimationFrame(render);
              
            
!
999px

Console