Skip to content

Instantly share code, notes, and snippets.

@Dezzign
Created July 11, 2018 12:32
Show Gist options
  • Save Dezzign/4759dd3063064db467795b3c10411ae2 to your computer and use it in GitHub Desktop.
Save Dezzign/4759dd3063064db467795b3c10411ae2 to your computer and use it in GitHub Desktop.

Revisions

  1. Dezzign created this gist Jul 11, 2018.
    1 change: 1 addition & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <canvas id="canvas"> Can I have</canvas>
    57 changes: 57 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    perlin = new ClassicalNoise(),
    variation = .003,
    amp = 200,
    variators = [],
    max_lines = (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) ? 25 : 30,
    canvasWidth,
    canvasHeight,
    start_y;

    for (var i = 0, u = 0; i < max_lines; i++, u+=.02) {
    variators[i] = u;
    }

    function draw(){
    ctx.shadowColor = "rgba(43, 205, 255, 1)";
    ctx.shadowBlur = 0;

    for (var i = 0; i <= max_lines; i++){
    ctx.beginPath();
    ctx.moveTo(0, start_y);
    for (var x = 0; x <= canvasWidth; x++) {
    var y = perlin.noise(x*variation+variators[i], x*variation, 0);
    ctx.lineTo(x, start_y + amp*y);
    }
    var color = Math.floor(150*Math.abs(y));
    var alpha = Math.min(Math.abs(y), .8)+.1;
    ctx.strokeStyle = "rgba(80,210,240,"+alpha+")";
    ctx.stroke();
    ctx.closePath();

    variators[i] += .005;
    }
    }

    (function init() {
    resizeCanvas();
    animate();
    window.addEventListener('resize', resizeCanvas);
    })();

    function animate() {
    ctx.clearRect(0, 0, canvasWidth, canvasHeight);
    draw();
    requestAnimationFrame(animate);
    }

    function resizeCanvas(){
    canvasWidth = document.documentElement.clientWidth,
    canvasHeight = document.documentElement.clientHeight;

    canvas.setAttribute("width", canvasWidth);
    canvas.setAttribute("height", canvasHeight);

    start_y = canvasHeight/2;
    }
    1 change: 1 addition & 0 deletions scripts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <script src="https://codepen.io/Thibka/pen/LWGOWR"></script>
    5 changes: 5 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    html, body {
    margin: 0;
    background-color: black;
    overflow: hidden;
    }
    7 changes: 7 additions & 0 deletions waves.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Waves
    -----


    A [Pen](https://codepen.io/Dezzign/pen/NBPjQQ) by [Richard Brus](https://codepen.io/Dezzign) on [CodePen](https://codepen.io).

    [License](https://codepen.io/Dezzign/pen/NBPjQQ/license).