cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              html, body
  height: 100%

body
  display: flex
  align-items: center
  justify-content: center
  margin: 0
  background: #606058

canvas
  padding: 6px
  border: 12px solid #a0a098
  border-radius: 4%
  background: #fff
  
            
          
!
            
              const {cos, PI, random, sin, sqrt} = Math;
const PI2 = PI * 2;

const N = 600;   // Number of particles.
const L = 1000;  // Canvas length.
const R = 40;    // Radius of inner circle.
const TWIST_FACTOR = 0.98;
const NOISE_MAGNITUDE = 10;
const SPREAD = 1.04;

// Helper constants (vectors are stored as [x, y]).
const X = 0;
const Y = 1;

const unit = (() => {
  const hypot = Math.hypot || ((x, y) => sqrt(x*x, y*y));
  return (x, y) => {
    const l = hypot(x, y) / SPREAD;
    return [x/l, y/l];
  };
})();

const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
let particles = Array.from({length: N}, (_, i) => {
  const a = i / N * PI2;
  const v = [sin(a), cos(a)];
  const d = v.map(c => R * c + (random() - 0.5) * NOISE_MAGNITUDE);
  return {d, v};
});

canvas.height = canvas.width = L;
canvas.style.height = canvas.style.width = `${L/2}px`;
ctx.transform(1, 0, 0, -1, L/2, L/2);
ctx.arc(0, 0, R + NOISE_MAGNITUDE, 0, PI2);
ctx.fill();

// Go for it.
!function step () {
  particles = particles.map(({d: [dX0, dY0], v: [vX0, vY0]}, i) => {        
    const {d: [dX1, dY1]} = particles[(i || N) - 1];
    const d = [dX0 + vX0, dY0 + vY0];
    const v = unit(dX1 - dX0 * TWIST_FACTOR, dY1 - dY0 * TWIST_FACTOR);
    
    // Gross side effect. Draw the particles.
    ctx.beginPath();
    ctx.moveTo(dX0, dY0);
    ctx.lineTo(...d);
    ctx.stroke();
    
    // Update displacement and velocity for next time around.
    return {d, v};
  });
	window.requestAnimationFrame(step);
}();

document.body.appendChild(canvas);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console