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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="drawing"></canvas>
              
            
!

CSS

              
                body {
  margin: auto;
  width: 600px;
}
              
            
!

JS

              
                var width = 600,
    height = 600;

/*** Config - you can play around with these to see what you get! ***/
var 
    // Dot radius in pixels
    dotRadius = 15,
    // How many dots in a full circle. Prime numbers seem to add to the effect.
    dotCount = 31,
    // Minimum/maximum boundaries of dot placement, measured from the centre.
    minRadius = dotRadius * 0.3,
    maxRadius = height * 0.4,
    // How much further from / closer to the centre to move each successive dot.
    radiusShift = 0.5,
    // A multiplier to move dots further around the circle when they're further from the centre.
    // Changing this produces the most dramatic differences in the result.
    angleShift = 0.01;
/*** End config ***/


// Derived values
var maxRadians = Math.PI * 2,
    cx = width / 2,
    cy = height / 2,
    angleStep = maxRadians / dotCount,
    hueStep = 360 / (dotCount + 1);

// State
var curAngle = 0,
    curHue = 0,
    curRadius = minRadius,
    radiusDirection = 1;

var canvas = document.getElementById('drawing');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.translate(cx, cy);
ctx.strokeStyle = '#fff';

function drawDot() {
  var x = Math.sin(curAngle) * curRadius;
  var y = Math.cos(curAngle) * curRadius;
  ctx.save();
  ctx.beginPath();
  ctx.arc(x, y, dotRadius, 0, maxRadians);
  ctx.fillStyle = 'hsl(' + curHue + ', 50%, 50%)';
  ctx.fill();
  ctx.stroke();
  ctx.restore();
}

var stop = false;

function nextStep() {
  drawDot();
  if (radiusDirection === 1 && curRadius >= maxRadius) radiusDirection = -1;
  if (radiusDirection === -1 && curRadius <= minRadius) radiusDirection = 1;
  curRadius += radiusShift * radiusDirection;
  curHue = (curHue + hueStep) % 360;
  var angleExtra = (curRadius / maxRadius) * angleStep * angleShift;
  curAngle = (curAngle + angleStep + angleExtra) % maxRadians;
  if (!stop) {
    requestAnimationFrame(nextStep);
  }
}

nextStep();


              
            
!
999px

Console