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

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

              
                    <div class="container">
        <canvas id="canvas" width="500" height="500" ></canvas>
    </div>
              
            
!

CSS

              
                *{
    margin: 0;
    padding: 0;
    outline: 0;
    box-sizing: border-box;
}
body{
    background: #343434;
}
#canvas{
    display: block;
    z-index: 1000;
    overflow: hidden;
}
              
            
!

JS

              
                let windowWidth = 0;
let windowHeight = 0;

const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');
resizeCanvas();
CanvasStation(ctx);
function resizeCanvas() {
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
    canvas.width = windowWidth;
    canvas.height = windowHeight;
    ctx.clearRect(0, 0, windowWidth, windowHeight);
    CanvasStation(ctx);
}

window.addEventListener('resize', resizeCanvas, false);


setInterval(resizeCanvas,1000);

function CanvasStation(ctx) {

    function randomN(min, max) {
        // return Math.floor(Math.random() * (max - min) + min);
        return Math.random() * (max - min) + min;
    }
    //Draw Moon
    ctx.beginPath();
    ctx.arc(windowWidth - windowWidth / 2, 100, 50, 0, Math.PI * 2, false);
    ctx.closePath();
    ctx.fillStyle = '#ffffff';
    ctx.fill();
    //Draw Moon noise
    ctx.beginPath();
    ctx.arc(windowWidth - windowWidth / 2, 100, 50, 0, Math.PI * 2, false);
    ctx.closePath();
    ctx.fillStyle = '#edfefe';
    ctx.fill();

    //Draw the Sea
    function drawSea() {
        ctx.beginPath();
        ctx.rect(0, windowHeight - (windowHeight / 3), windowWidth, windowHeight / 3);
        ctx.closePath();
        ctx.fillStyle = '#222222';
        ctx.fill();
    }
    drawSea();
    let xSeaMid = windowWidth - (windowWidth / 2);
    let ySea = windowHeight - (windowHeight / 3);
    
    function LinesShadow(array) {
        this.x = array.x;
        this.y = array.y;
        this.LineToX = array.LineToX;
        this.LineToY = array.LineToY;
        this.count = array.count ;
        this.helper = array.helper;
        this.speed = array.speed;
        this.counter = 0;
    }
    LinesShadow.prototype.draw = function () {
        ctx.beginPath();
        ctx.moveTo(this.x, this.y);
        ctx.lineTo(this.LineToX, this.LineToY);
        // ctx.closePath();
        ctx.globalAlpha = 0.2;
        ctx.liveWidth = 1;
        ctx.strokeStyle = '#dedede';
        ctx.stroke();
    }

    let lineValue = { x: 0, y: 0, LineToX: 0,
                     LineToY: 0, helper: 0, speed:0,count:0};
    const lines = [];
    let xPos = xSeaMid;
    let yPos = ySea ;
    let randN = 0;
    let helper = 1;
    for (let i = 0; i < 30; i++) {
        randN = randomN(50 , 300);
        lineValue.x = xSeaMid - randN;
        lineValue.y = yPos + randomN(5,10);

        lineValue.LineToX = lineValue.x + randN*2;
        lineValue.LineToY = lineValue.y;

        if(helper == 1){
            helper = -1;
        }else{
            helper = 1;
        }

        lineValue.helper = helper;
        lineValue.count = randomN(50, 100);
        lineValue.speed = randomN(10,20);

        yPos = lineValue.LineToY;

        lines.push(new LinesShadow(lineValue));
        lines[i].draw();
    }
    

    //Stars Object
    function Star(array) {

        this.radius = array.radius;
        this.x = array.x;
        this.y = array.y;
        this.opacity = array.opacity;
    }

    Star.prototype.draw = function () {

        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
        ctx.closePath();
        ctx.globalAlpha = this.opacity;
        ctx.fillStyle = '#ffffff';
        ctx.fill();
    }


    const values = { x: 0, y: 0, radius: 0, opacity: 0, color: 0 };
    const stars = [];
    for (let i = 0; i < 300; i++) {
        values.radius = randomN(0.01, 1);
        values.x = randomN(0, windowWidth);
        values.y = randomN(0, (windowHeight / 3) * 2);
        values.opacity = randomN(0.1, 0.9);
        values.color = '#efefef';

        stars.push(new Star(values));
    }

    for (let i = 0; i < stars.length; i++) {
        stars[i].draw();

    }

};
              
            
!
999px

Console