LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code



  Pixel Art Maker!
  
  



  

Lab: Pixel Art Maker

Choose Grid Size

Grid Height: Grid Width:

Pick A Color

Design Canvas

Clear a cell with a double click

CSS
body {
    text-align: center;
    background-image: url("https://cdn-images-1.medium.com/max/2000/1*juszvZeImjKKaVbd2AGz0g.jpeg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center top;
}


h1 {
    font-family: Monoton;
    font-size: 70px;
    margin: 0.2em;
}

h2 {
    font-family: Monoton;
    margin: 1em 0 0.25em;
}

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

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

table {
    border-collapse: collapse;
    margin: 0 auto;
}

tr {
    height: 20px;
}

td {
    width: 20px;
}

input[type=number] {
    width: 6em;
}
JS
// Select color input
const colorInput = $("#colorPicker");

// Select size input
const inputHeight = $("#input_height");
const inputWidth = $("#input_width");

// Define the canvas
const pixelCanvas = $("#pixel_canvas");

// When size is submitted by the user, call makeGrid()

function init() {
  $("#sizePicker").submit(function(event) {
    event.preventDefault();
    makeGrid();
  });
}

$(document).ready(init);

pixelCanvas.on("click", "td", function() {
  $(this).css("background-color", colorInput.val());
});

function makeGrid() {
  // Clear the canvas before creating a new one
  pixelCanvas.children().remove("tr");

  // removing color with double click
  pixelCanvas.on("dblclick", "td", function() {
    $(this).css("background-color", "");
  });

  // Assigns values to height and width

  let height = inputHeight.val();
  let width = inputWidth.val();

  // Build the canvas

  // Create rows
  for (let maxRows = 0; maxRows < height; maxRows++) {
    $("").appendTo(pixelCanvas);
  }

  // Create columns
  for (let maxCols = 0; maxCols < width; maxCols++) {
    $("").appendTo("tr");
  }
}
Wed, 12/27/2017 - 07:02

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv