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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="rainbow-pixel-canvas"></canvas>
Double tap to clear the canvas
              
            
!

CSS

              
                .rainbow-pixel-canvas {
  border: solid 2px gray;

  -ms-touch-action: none;
      touch-action: none;
}
              
            
!

JS

              
                var pixelSize = 16;

interact(".rainbow-pixel-canvas")
  .origin("self")
  .draggable({
    max: Infinity,
    maxPerElement: Infinity,
    modifiers: [
      interact.modifiers.snap({
        // snap to the corners of a grid
        targets: [
          interact.snappers.grid({ x: pixelSize, y: pixelSize })
        ],
      })
    ],
    listeners: {
      // draw colored squares on move
      move: function(event) {
        var context = event.target.getContext("2d"),
          // calculate the angle of the drag direction
          dragAngle = 180 * Math.atan2(event.dx, event.dy) / Math.PI;

        // set color based on drag angle and speed
        context.fillStyle =
          "hsl(" +
          dragAngle +
          ", 86%, " +
          (30 + Math.min(event.speed / 1000, 1) * 50) +
          "%)";

        // draw squares
        context.fillRect(
          event.pageX - pixelSize / 2,
          event.pageY - pixelSize / 2,
          pixelSize,
          pixelSize
        );
      }
    }
  })
  // clear the canvas on doubletap
  .on("doubletap", function(event) {
    var context = event.target.getContext("2d");

    context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  });

function resizeCanvases() {
  [].forEach.call(document.querySelectorAll(".rainbow-pixel-canvas"), function(
    canvas
  ) {
    canvas.width = document.body.clientWidth;
    canvas.height = window.innerHeight * 0.7;
  });
}

// interact.js can also add DOM event listeners
interact(document).on("DOMContentLoaded", resizeCanvases);
interact(window).on("resize", resizeCanvases);
              
            
!
999px

Console