cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
                <h1>Lab: Pixel Art Maker</h1>

	<h2>Choose Grid Size</h2>
	<form id="sizePicker">
		Grid Height:
		<input type="number" id="inputHeight" name="height" min="1" max="100" value="1"> Grid Width:
		<input type="number" id="inputWeigth" name="width" min="1" max="100" value="1">
		<input type="submit">
	</form>

	<h2>Pick A Color</h2>
  
	<input type="color" id="colorPicker">

	<h2>Design Canvas</h2>
  <table id="pixelCanvas"></table>

            
          
!
            
              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;
}

h3 {
    margin: 1em 0 0.25em;
    font-weight: 400;
    line-height: 2em;
}

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;
}

            
          
!
            
              const table = $("#pixelCanvas");

// Create the Canvas
function makeGrid() {
	const height = $("#inputHeight").val();
	const width = $("#inputWeigth").val();
	for (let i = 0; i < height; i++) {
		table.append("<tr></tr>");
	}
	for (let i = 0; i < width; i++) {
		$("tr").append("<td></td>");
	}
}

// Colorize! 
table.on("click", "td", function() {
	const color = $("#colorPicker").val();
	$(this).css("background-color", color);
});

// Erase color with right click
table.on("contextmenu", "td", function(clear) {
	$(this).css("background-color", "transparent");
	clear.preventDefault();
});

// Calling function
$(document).ready(function() {
	$("#sizePicker").on("submit", function(evt) {
		table.html(""); 
		makeGrid();
		evt.preventDefault();
	});
});
//GETS COLOR
//set a value for the selected color
var selectedColor = $('#colorPicker').val();
console.log(selectedColor);
//create a function for changing the value of the colorPicker
$('#colorPicker').on("input",function(evt){
  evt.preventDefault();
  selectedColor = $(evt.target).val()
  console.log(selectedColor);
});

//add a click event to all cells
function colorChange(){
  $('td').each(function (){
    $(this).on("click",function(){
      $(this).css('background-color', selectedColor);
      console.log("this cell has been clicked and is now" + selectedColor)
    });
  });
}
            
          
!
999px
Loading ..................

Console