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="cell"></canvas>

<svg>
    <defs>
        <filter id="liquid">
            <feGaussianBlur in="sourceGraphic" stdDeviation="10" result="blur" />
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="liquid" />
            <!-- <feComposite in="sourceGraphic" in2="liquid" operator="atop" /> -->
        </filter>
    </defs>
</svg>

              
            
!

CSS

              
                
#cell {
    width: 100vw;
    height: 100vh;
    
    filter: url("#liquid");
    cursor: crosshair;
    
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
}

              
            
!

JS

              
                
/*
    -- Canvas Cells
    -- version 0.1
*/

/*
    -- I RAN OUT OF IDEAS FOR A NAME, THIS HAS NOTHING TO DO WITH CELLS!
    -- THE VARIABLES ARE TOO MUCH BUT YOU CAN MAKE YOUR CHANGES.
    -- MAYBE A SMALL UPDATE WILL HAPPEN IN THE FUTURE.
*/

const BACKGROUND = "#111",
      FOREGROUND = "#FFF",
      
      LINE_WIDTH = 50,
      PARTICLE_OFFSET = 100,

      CURVE_VERTEX_COUNT = 20,
      CURVE_SCALE = [10, 100],

      CURVE_COORDS = [
          [0.50, 0.50, 250],
          [0.05, 0.30, 160],
          [0.70, 0.20, 100],
          [0.90, 0.85, 120]
      ],

      PARTICLE_COUNT = 100,
      CURVE_COUNT = CURVE_COORDS.length,

      PARTICLE_SIZE = [15, 25],
      PARTICLE_SPEED = [-100, 100],

      PARTICLE_ANGLE = [1, 3],

      VERTEX_RADIUS = [100, 120],
      VERTEX_RANGE = [30, 40];

const T = Math.PI * 2,
      Transform = new DOMMatrix;

if (!DOMMatrix) window.DOMMatrix = WebKitCSSMatrix;

let cvs = document.getElementById("cell"),
    ctx = cvs.getContext("2d"),
    
    area = { w: null, h: null },
    random = (min, max) => ~~((Math.random() * (max - min + 1) + min) * 100) / 100,
    
    curves = [],
    particles = [];

function size_setup () {
    let w = cvs.clientWidth,
        h = cvs.clientHeight;
    
    area.w = Math.round(w);
    area.h = Math.round(h);

    cvs.width = Math.round(w * devicePixelRatio);
    cvs.height = Math.round(h * devicePixelRatio);

    ctx.scale(devicePixelRatio, devicePixelRatio);
}

class Vertex
{
    constructor (r, t) {
        this.r = r;
        this.t = t;

        this.nr = r;
        this.range = random(...VERTEX_RANGE) / 10;

        this.angle = Math.random() * T;
        this.speed = random(10, 100) / 1000;
    }

    update () {
        this.r = this.nr + this.range * Math.sin(this.angle);
        this.angle = (this.angle + this.speed) % T;
    }

    get coords () {
        return [this.r * Math.cos(this.t), this.r * Math.sin(this.t)];
    }
}

Vertex.middle = function (v1, v2) {
    let a = v1.coords,
        b = v2.coords;
    
    return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
}

class Shape
{
    constructor (n, cx, cy, scale) {
        this.center = [cx, cy];
        this.scale = scale / 100;

        this.count = n;
        this.vertices = new Array(n);

        let i, r, t,
            initial = Math.random() * T,
            angle = T / n;

        for (i = 0; i < n; i++) {
            r = random(...VERTEX_RADIUS);
            t = angle * i + initial;

            this.vertices[i] = new Vertex(r, t);
        }
    }

    update () {
        this.vertices.forEach((vertex) => vertex.update());
    }

    draw (path) {
        let d = ["M " + Vertex.middle(this.vertices[this.count - 1], this.vertices[0]).join(" ")],
            t = Transform.translate(...this.center).scale(this.scale);

        for (let i = 0; i < this.count; i++) {
            d.push(this.vertices[i].coords.join(" ") + " " + Vertex.middle(this.vertices[i], this.vertices[(i + 1) % this.count]).join(" "));
        }

        path.addPath(new Path2D(d.join(" S ")), t);
    }
}

class Particle
{
    constructor () {
        this.x = random(0, area.w);
        this.y = random(0, area.h);

        this.size = random(...PARTICLE_SIZE)
        this.radius = this.size;

        this.angle_speed = random(...PARTICLE_ANGLE) / 200;
        this.angle = Math.random() * T;

        this.speed = [
            random(...PARTICLE_SPEED) / 100,
            random(...PARTICLE_SPEED) / 100
        ];
    }

    draw (path) {
        path.moveTo(this.x + this.radius, this.y);
        path.arc(this.x, this.y, this.radius, 0, T);
    }

    update () {
        this.radius = this.size * (1 + Math.abs(Math.sin(this.angle)));
        this.angle = (this.angle + this.angle_speed) % T;

        this.x = Math.max(this.radius - PARTICLE_OFFSET, Math.min(area.w - this.radius + PARTICLE_OFFSET, this.x + this.speed[0]));
        this.y = Math.max(this.radius - PARTICLE_OFFSET, Math.min(area.h - this.radius + PARTICLE_OFFSET, this.y + this.speed[1]));

        if (this.x + this.radius === area.w + PARTICLE_OFFSET || this.x - this.radius === -PARTICLE_OFFSET) this.speed[0] *= -1;
        if (this.y + this.radius === area.h + PARTICLE_OFFSET || this.y - this.radius === -PARTICLE_OFFSET) this.speed[1] *= -1;
    }
}

function draw () {
    ctx.save();
    ctx.clearRect(0, 0, area.w + 1, area.h + 1);
    
    let particle_path = new Path2D,
        curve_path = new Path2D;

    particles.forEach((particle) => {
        particle.draw(particle_path);
        particle.update();
    });

    curves.forEach((curve) => {
        curve.draw(curve_path);
        curve.update();
    });

    ctx.fill(particle_path);
    ctx.stroke(curve_path);
    
    ctx.save();
    ctx.globalCompositeOperation = "destination-out";

    ctx.fill(curve_path);
    ctx.restore();

    ctx.restore();
    requestAnimationFrame(draw);
}

function initialize_canvas () {
    curves.length = 0;
    particles.length = 0;

    for (let i = 0; i < CURVE_COUNT; i++) {
        let coords = CURVE_COORDS[i];
        curves[i] = new Shape(CURVE_VERTEX_COUNT, coords[0] * area.w, coords[1] * area.h, coords[2]);
    }

    for (let i = 0; i < PARTICLE_COUNT; i++) {
        particles[i] = new Particle();
    }

    ctx.lineWidth = LINE_WIDTH;
    ctx.lineCap = ctx.lineJoin = "round";

    ctx.strokeStyle = FOREGROUND;
    ctx.fillStyle = FOREGROUND;
}

onload = () => {
    size_setup();
    initialize_canvas();
    
    addEventListener("resize", () => {
        size_setup();
        initialize_canvas();
    });

    document.body.style.setProperty("background-color", BACKGROUND);
    draw();
}

              
            
!
999px

Console