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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <body>
    <h1>Pixel Art Maker</h1>

    <h2>Choose Grid Size</h2>
    <form id="sizePicker">
        Grid Height:
        <input type="number" id="input_height" name="height" min="1" max="200" value="1" placeholder="1-200"> Grid Width:
        <input type="number" id="input_width" name="width" min="1" max="200" value="1" placeholder="1-200">
        <input type="submit" value="Start!">
    </form>

    <h2>Pick A Color</h2>
    <span>Chose <input type="color" id="colorPicker" > for <img src="http://res.cloudinary.com/jabarlew/image/upload/v1513511893/iconmonstr-mouse-12-24_d01skr.png" alt="left">.</span>
  <span>Chose <input type="color" id="colorPickerRight" value="#ff0000"> for <img src="http://res.cloudinary.com/jabarlew/image/upload/v1513511902/iconmonstr-mouse-14-24_upps1v.png" alt="right">.</span>
   <span> Press <img src="http://res.cloudinary.com/jabarlew/image/upload/v1513597564/iconmonstr-mouse-4-24_luevhj.png" alt="middle"> to erase.</span>

    <h2>Design Canvas</h2>
    <p><input type="button" id=reset value="Reset Canvas"></p>
    <table id="pixel_canvas" ondragstart="return false;" ondrop="return false;" oncontextmenu="return false;">

    </table>

    <script src="designs.js"></script>
</body>

              
            
!

CSS

              
                body {
    text-align: center;
    background-color: #34495e;
    padding-bottom: 4em;
}

h1 {
    font-family: 'Press Start 2P', cursive;
    font-size: 60px;
    color: #ecf0f1;
    margin: 0.2em;
}

h2 {
    margin: 1em 0 0.25em;
    padding-bottom: 0.5em;
    color: #ecf0f1;
}

h2:first-of-type {
    margin-top: 0.5em;
}

table,
tr,
td {
    border: 1px solid black;
}

table {
    border-collapse: collapse;
    margin: 0 auto;
    background-color: #fff;
}

tr {
    height: 20px;
}

td {
    width: 20px;
}

input[type=number] {
    width: 6em;
}

#sizePicker {
    color: #ecf0f1;
}

p {
    color: #ecf0f1;
}

span {
    color: #ecf0f1;
    padding-left: 2em;
    
}
              
            
!

JS

              
                // Select color input
var color;
var colorRight;
// Select size input
var height;
var width;

//Run code when document is ready
$(document).ready(function() {
  /// Change val of color
  $("#colorPicker").change(function() {
    color = $(this).val();
  });

  ///change val of rightcolor
  $("#colorPickerRight").change(function() {
    colorRight = $(this).val();
  });
  ///Change val of height
  $("#input_height").change(function() {
    height = $(this).val();
  });

  /// Change val of width
  $("#input_width").change(function() {
    width = $(this).val();
  });

  /// When size is submitted by the user, call makeGrid()
  $("#sizePicker").submit(function(event) {
    var grid = makeGrid(width, height);
    event.preventDefault();
  });
  ///Reset
  $("#reset").on("click", function() {
    $("td").css("background-color", "");
  });

  //drawing on click
  $(document).on("mousedown mouseup", "td", function mouseState(e) {
    if (e.type === "mousedown") {
      if (e.which === 1) {
        let color = $("#colorPicker").val();
        $(this).css("background-color", color);
      }
      if (e.which === 3) {
        let colorRight = $("#colorPickerRight").val();
        $(this).css("background-color", colorRight);
      }
      if (e.which === 2) {
        $(this).css("background-color", "#ffffff");
        e.preventDefault();
      }
    }
  });

  //draw on hold
  $("body").mousedown(function(e) {
    if (e.which === 1) {
      $("td").bind("hover", function() {
        let color = $("#colorPicker").val();
        $(this).css("background-color", color);
      });
    }
    if (e.which === 3) {
      $("td").bind("hover", function() {
        let colorRight = $("#colorPickerRight").val();
        $(this).css("background-color", colorRight);
      });
    }
    if (e.which === 2) {
      $("td").bind("hover", function() {
        $(this).css("background-color", "#ffffff");
      });
    }
  });
  $("body").mouseup(function() {
    $("body td").unbind("hover");
    $("body").css(function() {
      return false;
    });
  });
});
////construct the grid according to the height and width
function makeGrid(width, height) {
  var grid = $("#pixel_canvas");
  grid.empty();

  for (var rows = 1; rows <= Number(height); rows++) {
    var tr = $('<tr class="rows">');
    for (var col = 1; col <= Number(width); col++) {
      var td = tr.append('<td class="cell">');
    }
    grid.append(tr);
  }
  return grid;
}

              
            
!
999px

Console