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

              
                <canvas id="canvas">Canvas not supported.</canvas>
<ul id="navigation">
  <li>Scroll up, down and click.</li>
</ul>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  color: #FFF;
}

canvas#canvas {
  display: block;
  background: #000;
}

ul#navigation {
  display: none;
}

@media screen and (min-width: 48rem) {

  ul#navigation {
    display: block;
    position: absolute;
    height: 100%;
    top: 0;
    right: 0;
    -webkit-writing-mode: vertical-rl;
        -ms-writing-mode: tb-rl;
            writing-mode: vertical-rl;
    text-align: center;
    margin-right: 1.6rem;
    font-size: 0.8rem;
  }
  ul#navigation > li {
    display: inline-block;
  }

}
              
            
!

JS

              
                (function () {
  'use strict';
  window.addEventListener('load', function () {
    var canvas = document.getElementById('canvas');

    if (!canvas || !canvas.getContext) {
      return false;
    }

    /********************
      Random Number
    ********************/

    function rand(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }

    /********************
      Var
    ********************/

    var ctx = canvas.getContext('2d');
    var X = canvas.width = window.innerWidth;
    var Y = canvas.height = window.innerHeight;
    var mouseX = null;
    var mouseY = null;
    var flowers = [];
    var flowerNum = 1;
    var flowerSize = Y / 3;
    var flg = true;
    var angle = 137.5;

    /********************
      Animation
    ********************/

    window.requestAnimationFrame =
      window.requestAnimationFrame ||
      window.mozRequestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      window.msRequestAnimationFrame ||
      function(cb) {
        setTimeout(cb, 17);
      };

    /********************
      Flower
    ********************/
    
    function Flower(ctx, x, y) {
      this.ctx = ctx;
      this.init(x, y);
    }

    Flower.prototype.init = function(x, y) {
      this.x = x;
      this.y = y;
      this.r = Y / 2;
      this.lw = 5;
      this.a = 0;
      this.rad = this.a * Math.PI / 180; 
      this.v = {
        x: 0,
        y: 0
      };
      this.c = {
        r: rand(0, 255),
        g: rand(0, 255),
        b: rand(0, 255)
      };
    };

    Flower.prototype.draw = function() {
      var ctx  = this.ctx;
      ctx.save();
      ctx.globalCompositeOperation = 'lighter';
      ctx.fillStyle = 'rgb(' + this.c.r + ',' + this.c.g + ', ' + this.c.b + ')';
      ctx.strokeStyle = 'rgb(' + this.c.r + ',' + this.c.g + ', ' + this.c.b + ')';
      if (flg === true) {
        ctx.translate(this.x, this.y);
        ctx.rotate(Math.cos(this.rad));
        ctx.scale(Math.cos(this.rad), Math.sin(this.rad));
        ctx.translate(-this.x, -this.y);
      }
      for (var i = 0; i < this.r; i++) {
        ctx.beginPath();
        ctx.arc(Math.cos(angle * Math.PI / 180 * i) * i / 2 + this.x, Math.sin(angle * Math.PI / 180 * i) * i / 2 + this.y, 2 * i / 100, 0, Math.PI * 2, false);
        ctx.fill();
      }
      ctx.restore();
      ctx.save();
      ctx.globalCompositeOperation = 'lighter';
      ctx.lineWidth = Math.sin(this.rad) * this.lw;
      if (flg === true) {
        ctx.translate(this.x, this.y);
        ctx.rotate(Math.sin(this.rad));
        ctx.scale(Math.cos(this.rad), Math.sin(this.rad));
        ctx.translate(-this.x, -this.y);
      }
      ctx.strokeStyle = 'rgb(' + this.c.r + ',' + this.c.g + ', ' + this.c.b + ')';
      for (var i = 0; i < 36; i++) {
        ctx.translate(this.x, this.y);
        ctx.rotate(10 * Math.PI / 180);
        ctx.translate(-this.x, -this.y);
        ctx.beginPath();
        ctx.ellipse(this.x + this.r / 2, this.y + this.r / 2, this.r / 30, this.r / 6, -45 * Math.PI / 180, 0, Math.PI * 2, false);
        ctx.stroke();
      }
      ctx.restore();
    };

    Flower.prototype.updateParams = function() {
      this.a += 0.5;
      this.rad = this.a * Math.PI / 180;
    };
    
    Flower.prototype.render = function() {
      this.updateParams();
      this.draw();
    };
    
    for (var i = 0; i < flowerNum; i++) {
      var f = new Flower(ctx, X / 2, Y / 2);
      flowers.push(f);
    }

    /********************
      ChangeColor
    ********************/

    function changeColor() {
      var time = rand(1000, 5000);
      var r = rand(0, 255);
      var g = rand(0, 255);
      var b = rand(0, 255);
      for (var i = 0; i < flowers.length; i++) {
        flowers[i].c  = {
          r: r,
          g: g,
          b: b
        };
      }
      setTimeout(changeColor, time);
    }

    changeColor();

    /********************
      Render
    ********************/
   
    function render() {
      //ctx.clearRect(0, 0, X, Y);
      ctx.globalCompositeOperation = "darken";
      ctx.globalAlpha = 0.03;
      ctx.fillStyle = "rgb(0,0,0)";
      ctx.fillRect(0, 0, X, Y);
      ctx.globalCompositeOperation = "source-over";
      ctx.globalAlpha = 1;
      for (var i = 0; i < flowers.length; i++) {
        flowers[i].render();
      }
      requestAnimationFrame(render);
    }

    render();

    /********************
      Event
    ********************/
    
    function onResize() {
      X = canvas.width = window.innerWidth;
      Y = canvas.height = window.innerHeight;
      flowerSize = Y / 3;
      flowers = [];
      for (var i = 0; i < flowerNum; i++) {
        var f = new Flower(ctx, X / 2, Y / 2);
        flowers.push(f);
      }
    }

    window.addEventListener('resize', function(){
      onResize();
    });
    
    canvas.addEventListener('mousemove', function(e) {
      mouseX = e.clientX;
      mouseY = e.clientY;
    });

    canvas.addEventListener('click', function(e) {
      flg === true ? flg = false : flg = true;
    });

    canvas.addEventListener('wheel', function(e) {
      for (var i = 0; i < flowers.length; i++) {
        flowers[i].a += e.deltaY;
      }
    });

  });
  // Author
  console.log('File Name / turnsole.js\nCreated Date / Jun 05, 2020\nAuthor / Toshiya Marukubo\nTwitter / https://twitter.com/toshiyamarukubo');
})();
              
            
!
999px

Console