cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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
    padding 0
    margin 0
    width 100%
    height 100%
    overflow hidden
            
          
!
            
              class Wave {
    constructor(height, power) {
        this.__force = 0;
	    this.__wavePower = power || 60;
	    this.__count = 0;
	    this.__y = height;
	    this.__alpha = 1;
        this.__pos = 0;
        this.__dir = 1;
        this.__h = height;
    }
    
    get height() {
        return this.__h
    }
    set height(value) {
        this.__h = Math.max(0, value);
    }
    
    get percent() {
        return (1 - this.__y / this.__h) * 100
    }
    set percent(value) {
        this.__y = this.__h * (1  - value / 100)
    }
    
    update() {
        this.__y-=this.__dir * Math.random();
        if (this.__y < 1 || this.__y > this.__h) {
            this.__dir *= -1
        }
		this.__force = Math.sin(this.__count);
		this.__count += .1;
        this.__pos += .04;
    }
    
    draw(ctx, w, h) {   
        
        ctx.fillStyle = makeGrd(h);
        console.log(this.__y);
		ctx.beginPath();
		ctx.moveTo(0, this.__y);
        
        const p = Math.sin(this.__pos);
        
		ctx.quadraticCurveTo(w * (p + .25), this.__y + ( this.__wavePower * this.__force ), w  * (p + .5), this.__y);
		ctx.quadraticCurveTo(w * (p + .75), this.__y - ( this.__wavePower * this.__force ), w, this.__y);
		ctx.lineTo(w, h);
		ctx.lineTo(0, h);
		ctx.lineTo(0, this.__y);
		ctx.closePath();
        ctx.fill()
    }
}

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

let w = canvas.width = document.body.clientWidth;
let h = canvas.height = document.body.clientHeight;
const ctx = canvas.getContext('2d');

const wave = new Wave(h, 100);

let grd;

function makeGrd(h) {
    const g = ctx.createLinearGradient(0, 0, 0, h);
    g.addColorStop(0, '#419dff');
    g.addColorStop(1, '#66bfff');    
    return g
}

function draw() {
    requestAnimationFrame(draw);
 
    
    if (w !== document.body.clientWidth) {
        canvas.width = w = document.body.clientWidth
    }
    
    if (!grd || h !== document.body.clientHeight) {
        canvas.height = h = document.body.clientHeight;
        grd = makeGrd(h)
    }
    
    ctx.globalCompositeOperation = 'source-over';
    ctx.fillStyle = "rgba(255, 255, 255, 1)";
    ctx.fillRect(0,0,w,h);
    
    ctx.globalCompositeOperation = 'xor';
    
    ctx.fillStyle = "rgba(0, 0, 0, 1)";
    ctx.fillRect(0,0,w,h);
    
    wave.draw(ctx, w, h);
    
    ctx.textAlign="center";
    ctx.textBaseline = 'middle';
    ctx.font = 'bold 10rem serif';
    ctx.fillStyle = "rgba(0, 0, 0, 1)";
    ctx.fillText(`${wave.percent | 0 }%`, w/2, h/2);
    
    wave.update();
}

draw();

            
          
!
999px
Loading ..................

Console