Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                const noise = new Noise();
Math.TWO_PI = Math.PI * 2;

const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');

var tendrils = [];

class Vector {

    constructor(x, y, z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    add(value) {
        if(value instanceof Vector) {
            this.x += value.x;
            this.y += value.y;
        } else {
            this.x += value;
            this.y += value;
        }
        return this;
    }

    multiply(value) {
        this.x *= value;
        this.y *= value;
    }

    divide(value) {
        if(value instanceof Vector) {
            this.x = this.x / value.x;
            this.y = this.y / value.y;
        } else {
            this.x = this.x / value;
            this.y = this.y / value;
        }
        return this;
    }
    
    length() {
        return Math.sqrt(this.dot(this));
    }

    normalize() {
        return this.divide(this.length());
    }
}

class Tendril {

    constructor({ angle, x, y }) {
		
        this.position = new Vector(x, y);
        this.velocity = new Vector(x * 0.025, y * 0.025);
        this.acceleration = new Vector();
        this.hue = 250 + Math.sin(angle) * 15;
        this.alpha = 0.25;
        this.fade = 0.9885;
        this.mass = Math.floor(1 + Math.random() * 10);
    }

    get x() { return this.position.x; }
    get y() { return this.position.y; }

    update(time) {
		
        let sample = noise.simplex2(this.x * 0.005, this.y * 0.005);
        let angle = sample * Math.PI;
        
		this.acceleration.x = Math.cos(angle) * this.mass;
        this.acceleration.y = Math.sin(angle) * this.mass;
        this.velocity.x += ( this.acceleration.x - this.velocity.x ) / this.mass;
        this.velocity.y += ( this.acceleration.y - this.velocity.y ) / this.mass;
        this.position.add(this.velocity);
    }

    draw(context) {

        context.beginPath();
        context.arc(this.x, this.y, 1, 0, Math.TWO_PI);
        context.fillStyle = `hsla(${this.hue},71%,55%,${this.alpha})`;
        context.fill();

        this.alpha *= this.fade;
    }
}

function loop(time) {

    loop.handle = requestAnimationFrame(loop);

    let { x, y } = canvas.center;

    context.save();
    context.translate(x, y);
    context.globalCompositeOperation = 'lighter';

    tendrils = tendrils.filter(function(tendril) {

        tendril.update();
        tendril.draw(context);

        return tendril.alpha > 0.01 && tendril.x > -x && tendril.x < x && tendril.y > -y && tendril.y < y;
    });

    context.restore();

    if( ! tendrils.length) {

        console.log('done');
        cancelAnimationFrame(loop.handle);
        loop.handle = null;
    }
}

function resize() {
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    canvas.center.x = window.innerWidth * 0.5;
    canvas.center.y = window.innerHeight * 0.5;
}

function reset() {

    let seed = Math.random();
	noise.seed(seed);
	
    let angle = 0;
    let limit = 700;
    let radius = 100;
    let slice = Math.TWO_PI / limit;

    tendrils = [];

    for(let i = 0; i < limit; i++) {

        let x = Math.cos(angle);
        let y = Math.sin(angle);
        let displacement = radius + (noise.simplex2(x, y) * 30);

        x = x * displacement;
        y = y * displacement;

        tendrils.push(new Tendril({ angle, x, y }));
        angle += slice;
    }
	
	context.clearRect(0, 0, canvas.width, canvas.height);
	loop.handle || requestAnimationFrame(loop);
}

function init() {

    canvas.center = {};

    document.body.style.cssText = 'margin:0;padding:0;background:#111;overflow:hidden;';
    document.body.appendChild(canvas);
    document.body.addEventListener('click', reset);
	
	window.addEventListener('resize', resize);
	window.addEventListener('keyup', event => event.which == 32 && reset());
	
	resize();
    reset();
}

init();
              
            
!
999px

Console