Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created May 25, 2018 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/13098a533d3081756cc248d16707ce68 to your computer and use it in GitHub Desktop.
Save johirbuet/13098a533d3081756cc248d16707ce68 to your computer and use it in GitHub Desktop.
function makeGrid() {
console.log("makeGrid is running!")
// Select size input
let canvas, cell, gridHeight, gridWidth, rows;
canvas = $('#pixelCanvas');
gridHeight = $('#inputHeight').val();
gridWidth = $('#inputWidth').val();
canvas.empty();
for (x = 0; x < gridHeight; x++) {
canvas.append('<tr></tr>');
}
rows = $('tr');
for (y = 0; y < gridWidth; y++) {
rows.append('<td></td>');
}
cell = canvas.find('td');
// When td is clicked by the user, change color of td
cell.click(function() {
// Select color input
console.log("changeColor is running!");
var color;
color = $("#colorPicker").val();
$(this).attr('bgcolor', color);
});
}
// When size is submitted by the user, call makeGrid()
var submitQuery;
submitQuery = $('input[type="submit"]')
submitQuery.click(function(event) {
event.preventDefault();
makeGrid();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment