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

CSS
body {
    text-align: center;
}

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

h2 {
    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
$(document).ready(function(){

var table = document.getElementById("pixel_canvas");
// Select color input
var color = $("#colorPicker").val();
$("#colorPicker").change(function(){
    color = $("#colorPicker").val();
});


// Select size input
var height = $("#input_height").val();
$("#input_height").change(function(){
    height = $("#input_height").val();
});


var width = $("#input_width").val();
$("#input_width").change(function(){
    width = $("#input_width").val();
});



// When size is submitted by the user, call makeGrid()
$("#sizePicker input[type='submit']").click(function(event){
  event.preventDefault();
  
  //Delete all table child if have
  if($(table).has( "tr" )) {
    $(table).empty();
  }
  
  makeGrid(height,width);
});

function makeGrid(gridHeight, gridWidth) {
  
  //Create Grid
  for(var i=0; i < gridHeight; i++) {
    //Append new row to table
    $(table).append( "" );
    for(var j=0; j < gridWidth; j++) {
      //Append td to the last tr on the table
      $( "#pixel_canvas tr:last-child").append( "" );
      //Event listener to cell click
      table.rows[i].cells[j].onclick = function () {
         artMixer(this);
      };
    }
  }

  function artMixer(tableCell) {
        $(tableCell).css("background-color", color);
    }
  
}


});
Wed, 12/27/2017 - 07:02

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv