LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Lab: Pixel Art Maker

Choose Grid Size

Grid Height: Grid Width:

Pick A Color

Design Canvas

One click - select color / Double click - erase color

CSS
body {
    text-align: center;
    background: url(https://i.imgur.com/en8Rjvp.jpg);
    font-family: 'Open Sans', sans-serif;
}

h1 {
    font-family: 'Codystar', cursive;
    font-size: 90px;
    margin: 0.2em;
    
}

h2 {
  font-family: 'Open Sans', sans-serif;
    margin: 1em 0 0.25em;
}

h2:first-of-type {
  font-family: 'Open Sans', sans-serif;
    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
// Defining function:
function makeGrid() {
// Defining variables:
  var gridHeight = $("#input_height").val();
  var gridWidth = $("#input_width").val();
  var grid = $("#pixel_canvas");
  var color = $("#colorPicker");
// Removes old grid:
  grid.children().remove();
// Loop for grid size:
  for (var h=1;h<=gridHeight;h++){
  grid.append("");
  for (var w=1;w<=gridWidth;w++){
  grid.children().last().append("");
        }
    }
  //Setting up color:
  grid.on('click','td',function(){
    var color = $("input[type='color']").val();
    $(this).attr("bgcolor", color);
  });
  //Double click for erasing color
  grid.on('dblclick','td',function(){
    $(this).attr("bgcolor", "");
  });
  
}


//Creating grid:
$("#sizePicker :submit").click(function(evt){
  evt.preventDefault();// prevents page from reloading
  makeGrid();
});
Wed, 12/27/2017 - 07:02

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv