Guest User

Untitled

a guest
Nov 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. // Select color input
  2.  
  3. var colorInput = $('#colorPicker');
  4.  
  5. // Select size input
  6.  
  7. var inputHeight = $('#input_height');
  8. var inputWidth = $('#input_width');
  9.  
  10. // Define the canvas
  11. var pixelCanvas = $('#pixel_canvas');
  12.  
  13. // When size is submitted by the user, call makeGrid()
  14.  
  15. $('#sizePicker').submit(function(event){
  16. makeGrid();
  17. event.preventDefault();
  18. });
  19.  
  20. pixelCanvas.on('click', 'td', function(){
  21. $(this).css('background-color',colorInput.val());
  22. });
  23.  
  24. function makeGrid() {
  25. // Your code goes here!
  26.  
  27. // Clear the canvas before creating a new one
  28.  
  29. pixelCanvas.children().remove('tr');
  30.  
  31. // Assigns values to height and width
  32.  
  33. var height = inputHeight.val();
  34. var width = inputWidth.val();
  35.  
  36. // Build the canvas
  37.  
  38. // Create rows
  39. for (maxRows = 0; maxRows < height; maxRows++)
  40. {
  41. $('<tr></tr>').appendTo(pixelCanvas);
  42. }
  43.  
  44. // Create columns
  45. for (maxCols = 0; maxCols < width; maxCols++)
  46. {
  47. $('<td></td>').appendTo('tr');
  48. }
  49. }
Add Comment
Please, Sign In to add comment