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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              
            
          
!

CSS

            
              *, *:before, *:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#message {
  padding: 2px 5px;
  color: #fff;
  background: #222;
}

canvas {
  visibility: hidden;
}
            
          
!

JS

            
              // The diameter of one frame of the circle, inclusive of the line width.
const circleDiameterPx = 170;

// The size of the frame in which the circle will be centred.
const frameSizePx = 180;

// The color of the circle, self-explanatory.
const lineColor = 'rgba(255, 255, 255, 1)';

// The background color of the preview window. Will not be included in the downloaded image.
const previewBackgroundColor = '#094e9b';

// The width of the circle's outline, which is included in the diameter.
const lineWidthPx = 5;

// The direction in which the animation will progress.
let clockwise = false;

// If true, the circle will start full and progress to empty.
const reverse = true;

// The number of frames to render.
const frames = 100;

// If true, blank space will be added to the spritesheet to make the dimensions a power of 2.
const powerOfTwoSize = true;

$(document).ready(render);

function render() {
  if (reverse) {
    clockwise = !clockwise;
  }

  $('body').css('background', previewBackgroundColor);

  const cols = Math.ceil(Math.sqrt(frames));
  let canvasSize = cols * frameSizePx;
  if (powerOfTwoSize) {
    canvasSize = Math.pow(2, Math.ceil(Math.log(canvasSize) / Math.log(2)));
  }

  const canvas = $(`<canvas width="${canvasSize}" height="${canvasSize}"></canvas>`).appendTo('body');
  const ctx = canvas[0].getContext('2d');
  ctx.lineWidth = lineWidthPx;
  ctx.strokeStyle = lineColor;
  
  for (let i = 0; i < frames; ++i) {
    renderFrame(i);
  }
  
  canvas.hide();
  $('body')
    .append(`<div id="message">Right-click the image below and select "Save image as..."</div>`)
    .append(`<img src="${canvas[0].toDataURL()}" style="border: 1px solid ${lineColor}"/>`);
  
  function renderFrame(index) {
    let row = index % cols;
    let col = Math.floor(index / cols);
    
    if (reverse) {
      row = cols - row - 1;
      col = cols - col - 1;
    }

    let progress = index / frames + 0;
    progress += progress * .01 + 0.00001;
    const progressDegrees = 360 * progress;
    
    const padding = (frameSizePx - circleDiameterPx) / 2;
    const x = (circleDiameterPx / 2) + (circleDiameterPx * row) + (padding * (row * 2 + 1));
    const y = (circleDiameterPx / 2) + (circleDiameterPx * col) + (padding * (col * 2 + 1));
    const radius = (circleDiameterPx / 2) - (lineWidthPx / 2);
    
    let startAngle = toOffsetRadian(0);
    let endAngle = toOffsetRadian(progressDegrees);
    
    if (!reverse) {
      startAngle = toOffsetRadian(-progressDegrees);
      endAngle = toOffsetRadian(0);
    }
    
    ctx.beginPath();
    ctx.arc(x, y, radius, startAngle, endAngle);
    ctx.stroke();
    ctx.closePath();
  }
  
  function toOffsetRadian(degrees) {
    return (degrees - 90) * (Math.PI / 180);
  }
}
            
          
!
999px

Console