css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 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.

            
              head, body{
    width:100%;
    height:100%;
    overflow: hidden;
    top:0;
    left:0;
    margin:0;
    padding:0;
}
#fullscreen
{
    font-family: "Trebuchet", Verdana, sans-serif;
    position : absolute;

    width: 100%;
    left : 0;
    bottom: 0;

    cursor: pointer;
    color: white;
    background-color: black;
    height: 1.5em;
    font-variant: small-caps;

    text-align: center;

}
            
          
!
            
              
//utils
var Point = function() { function Point(x,y,z) { this.x = x || 0; this.y = y || 0; this.z = z || 0; } var _p = Point.prototype; _p.constructor = Point; return Point; }(); Point.prototype = { draw: function (ctx, radius) { ctx.beginPath(); ctx.arc(this.x, this.y, radius || 1, 0, Math.PI * 2); ctx.stroke(); }, copy: function (other) { this.x = other.x; this.y = other.y; return this; }, clone: function () { return new Point( this.x, this.y ); }, add: function (other) { this.x += other.x; this.y += other.y; return this; }, sub: function (other) { this.x -= other.x; this.y -= other.y; return this; }, multiply: function (other) { this.x *= other.x; this.y *= other.y; return this; }, negate: function() { this.x *= 1; this.y *= 1; return this; }, length: function () { return Math.sqrt(this.x * this.x + this.y * this.y); }, normalize: function (length) { length = length || 1; var div = ( 1 / this.length() ) * length; this.x *= div; this.y *= div; return this; }, dot : function( other ) { return this.x * other.x + this.y * other.y; } };
function distance(a,b) { var dx = a.x - b.x; var dy = a.y - b.y; var dz = a.z - b.z; return Math.sqrt( dx*dx + dy*dy + dz*dz ); }
var Poisson = function( exports ) { exports.distanceEvaluator = function( cell, point, minDist ){ return distance( cell, point ) < minDist; }; var width, height, grid; function distribute( count, radius, w, h,cx, cy ) { width = w; height = h; var cellSize = exports.cellSize = radius / Math.sqrt( 2 ); exports.grid = grid = buildGrid( Math.ceil( w / cellSize), Math.ceil( h / cellSize) ); count = Math.min( count, Math.floor( w / cellSize) * Math.floor( h / cellSize) ); var processList = []; var firstPoint = new Point( cx || w *.5, cy || h *.5); processList.push(firstPoint); setGridPoint(imageToGrid(firstPoint, cellSize), firstPoint ); var result = []; var total = count; while (result.length < count ) { var added = false; var attempt = 10; while (!added ){ var rid = ~~( Math.random() * processList.length ); var point = processList[ rid ]; var newPoint = generateRandomPointAround( point, radius ); if (inRectangle(newPoint) && !inNeighbourhood(grid, newPoint, radius, cellSize ) ) { processList.push(newPoint); result.push(newPoint); setGridPoint( imageToGrid( newPoint, cellSize ),  newPoint ); added = true; } if (attempt--<=0)break; } if (total-- <=0)break; } return result; } function buildGrid( w, h ) { var g = []; for (var i = 0; i < w; i++ ) { var tmp = []; for (var j = 0; j < h; j++ ) { tmp.push(null ); } g.push(tmp ); } return g; } function setGridPoint( gridPoint, value ) { if (grid[gridPoint.x ][ gridPoint.y ] != null )return; grid[gridPoint.x ][ gridPoint.y ] = value; } function inRectangle( point ) { return point.x > 0 && point.x < width && point.y > 0 && point.y < height; } function imageToGrid( point, cellSize) { var gridX = ~~( point.x / cellSize ); var gridY = ~~( point.y / cellSize ); return new Point(gridX, gridY); } function generateRandomPointAround( point, mindist ) { var r1 = Math.random(); var r2 = Math.random(); var radius = mindist * ( r1 + 1); var angle = 2 * Math.PI * r2; var newX = point.x + radius * Math.cos(angle); var newY = point.y + radius * Math.sin(angle); return new Point(newX, newY); } function inNeighbourhood( grid, point, mindist, cellSize) { var gridPoint = imageToGrid( point, cellSize ); var cellsAroundPoint = squareAroundPoint( grid, gridPoint.x, gridPoint.y, 4 ); var valid = false; cellsAroundPoint.forEach( function( cell ){ if (cell == null)return; if (exports.distanceEvaluator(cell, point, mindist ) ){ valid = true; } }); return valid; } function squareAroundPoint( grid, x, y, offset ) { var off = Math.round( offset / 2 ); var minX = Math.max( 0, Math.min( grid.length, x - off ) ); var maxX = Math.max( 0, Math.min( grid.length, x + off ) ); var minY = Math.max( 0, Math.min( grid[0].length, y - off ) ); var maxY = Math.max( 0, Math.min( grid[0].length, y + off ) ); var tmp = []; for (var i = minX; i < maxX; i++ ) { for (var j = minY; j < maxY; j++ ) { if (grid[i ][ j ] != null )tmp.push( grid[ i ][ j ] ); } } return tmp; } exports.distribute = distribute; return exports; }({});
//utils


var arcs;
var iterations = 0;
var maxIterations = 200;

function init() {

    iterations = 0;
    cancelAnimationFrame( update );

    var count = 200;
    var radius = 40;
    arcs = Poisson.distribute(count, radius, w, h );//, Math.random() * h, Math.random() * w  );


    var dist, min, closest;
    arcs.forEach(function (a){

        min = 10e10;
        arcs.forEach( function(b)
        {
            if( a == b )return;

            dist = distance(a,b);
            if( dist < min )
            {
                min = dist;
                closest = b;
            }
        });
        a.closest = closest;

    });

    arcs.forEach(function (a, i){

        a.radius = .5 * radius + ( Math.random() * .5 ) * radius;
        a.speed = RAD+ Math.random() * 10 * RAD;
        a.start = Math.random() * PI2;
        a.length = Math.random() * PI + 10 * RAD;

    });


}

function update()
{
    if( iterations++ < maxIterations )
    {
        requestAnimationFrame( update );
    }
    else
    {
        cancelAnimationFrame( update );
    }

    ctx.strokeStyle = 'rgba( 0,0,0, '+ 5/0xff + ')';

    var zero = new Point();
    var a0 = new Point();
    var a1 = new Point();
    var b;
    var b0 = new Point();
    var b1 = new Point();
    var n0, n1;

    ctx.beginPath();
    arcs.forEach( function(a){

        a.start += a.speed;

        a0.x = Math.cos( a.start + a.length *.5 ) * a.radius / 2;
        a0.y = Math.sin( a.start + a.length *.5 ) * a.radius / 2;

        b = a.closest;

        b0.x = Math.cos( b.start + b.length *.5 ) * b.radius / 2;
        b0.y = Math.sin( b.start + b.length *.5 ) * b.radius / 2;

        a0.normalize();
        b0.normalize();

        if( a0.dot( b0 ) < 0 )
        {
            ctx.moveTo( a.x, a.y );
            ctx.arc(a.x, a.y, a.radius / 2, a.start, a.start + a.length );
            ctx.lineTo( a.x, a.y );


            a0.x = a.x + Math.cos( a.start ) * a.radius / 2;
            a0.y = a.y + Math.sin( a.start ) * a.radius / 2;

            a1.x = a.x + Math.cos( a.start + a.length ) * a.radius / 2;
            a1.y = a.y + Math.sin( a.start + a.length ) * a.radius / 2;

            b0.x = b.x + Math.cos( b.start ) * b.radius / 2;
            b0.y = b.y + Math.sin( b.start ) * b.radius / 2;

            b1.x = b.x + Math.cos( b.start + b.length ) * b.radius / 2;
            b1.y = b.y + Math.sin( b.start + b.length ) * b.radius / 2;

            ctx.arc(a.x, a.y, a.radius / 2, a.start, a.start + a.length );
            ctx.moveTo( a0.x, a0.y );
            ctx.lineTo( a1.x, a1.y );
            ctx.lineTo( b0.x, b0.y );
            ctx.lineTo( b1.x, b1.y );
            ctx.lineTo( a0.x, a0.y );
        }

    });
    ctx.stroke();

}

///////////////////////////////////////////////

var PI = Math.PI;
var PI2 = PI * 2;
var RAD = PI / 180;
var DEG = 180 / PI;

//raf: https://github.com/cagosta/requestAnimationFrame/blob/master/app/requestAnimationFrame.js
(function(global) {(function() {if (global.requestAnimationFrame) {return;} if (global.webkitRequestAnimationFrame) {global.requestAnimationFrame = global[ 'webkitRequestAnimationFrame' ]; global.cancelAnimationFrame = global[ 'webkitCancelAnimationFrame' ] || global[ 'webkitCancelRequestAnimationFrame' ];} var lastTime = 0; global.requestAnimationFrame = function(callback) {var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = global.setTimeout(function() {callback(currTime + timeToCall);}, timeToCall); lastTime = currTime + timeToCall; return id;}; global.cancelAnimationFrame = function(id) {clearTimeout(id);};})(); if (typeof define === 'function') {define(function() {return global.requestAnimationFrame;});}})(window);

var canvas = document.createElement( 'canvas' );
document.body.appendChild( canvas );


var w = canvas.width = window.innerWidth;
var h = canvas.height = window.innerHeight;
var ctx = canvas.getContext("2d");

window.onmousedown =
window.ontouchstart =
window.onresize = function()
{

    w = canvas.width = window.innerWidth;
    h = canvas.height = window.innerHeight;
    init();
    update();

};

var btn = document.createElement( "div" );
btn.id = btn.innerHTML = "fullscreen";
document.body.appendChild( btn );

btn.onmousedown =
btn.ontouchstart =
function ( e )
{
    if (canvas.requestFullscreen) {
        canvas.requestFullscreen();
    } else if (canvas.mozRequestFullScreen) {
        canvas.mozRequestFullScreen();
    } else if (canvas.webkitRequestFullscreen) {
        canvas.webkitRequestFullscreen();
    }
};

init();
update();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console