LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code



    
    
    
    Pixel Art Maker!
    
    



  

Lab: Pixel Art Maker

Choose Grid Size

Pick A Color

CSS
body {
  text-align: center;
  margin: 0;
}

h1 {
  font-family: 'Londrina Sketch', monospace;
  font-size: 70px;
  margin: 0;
  padding-top: 6vh;
  padding-bottom: 1vh;
  background: linear-gradient(60deg, #833ab4, #fcb045);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  opacity: 0.9;
}

/*Top section styles : BEGIN*/

.checkered {
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  border: none;
  font: normal 100%/normal Arial, Helvetica, sans-serif;
  color: rgba(255,255,255,1);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: -webkit-linear-gradient(90deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px), -webkit-linear-gradient(0deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px);
  background: -moz-linear-gradient(0deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px), -moz-linear-gradient(90deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px);
  background: linear-gradient(0deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px), linear-gradient(90deg, rgba(255,255,255,0.298039) 1px, rgba(0,0,0,0) 1px);
  background-position: -1px -1px;
  -webkit-background-origin: padding-box;
  background-origin: padding-box;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-background-size: 20px 20px;
  background-size: 20px 20px;
}

h2 {
  color:#305d73;
  font-family: 'Amatic SC', sans-serif;
  font-weight: bold;
  font-size: 30px;
}

.container {
  width:100%;
  max-width: 700px;
  box-sizing: border-box;
  margin: 0 auto;
  display: flex;
  flex-direction: row;
}

.container-item{
  flex:1;
}

form {
  display: flex;
  flex-direction: column;
}

label {
  color: #a75d93;
  display: inline-block;
  text-align: right;
  padding-right: 3px;
  width: 60px;
  line-height:20px;
  font-family: 'Amatic SC', sans-serif;
  font-weight: normal;
  font-size: 30px;
}

input[type=number] {
  font-family: 'Amatic SC', sans-serif;
  width: 60px;
  border: 1px dashed #a75d93;
  height: 25px;
  font-size: 30px;
  padding-left: 5px;
  color: #a75d93;
  margin-bottom: 10px;
}

#colorPicker {
  font-size: 0px;
  width:120px;
  text-align: center;
  height:65px;
  border: none;
  outline: none;
  cursor: pointer;
}

button {
  font-family: 'Amatic SC', sans-serif;
  font-weight: bold;
  font-size: 30px;
  width:120px;
  text-align: center;
  height:50px;
  border: none;
  outline: none;
  color: #a75d93;
  background: none;
  border: 1px dashed #a75d93;
  margin: 2vh 4vh;
  cursor: pointer;
}

table {
  border-collapse: collapse;
  margin: 5vh auto;
}

tr {
  height: 20px;
}

td {
  box-sizing: border-box;
  border: 1px solid #898989;
  width: 20px;
  cursor: url('https://raw.githubusercontent.com/Al3x4/project-pixel-art-maker/master/cursor.gif'), crosshair;
}
JS
$(function() {
  // Select color input
  $('#colorPicker').show();
  let selectedColor = '#' + $('#colorPicker').val();
  // Select size input

  //FUNCTIONS
  //function to clear existing grid and make a new grid
  function makeGrid(evt) {
    //clears existing table
    $('#pixel_canvas').empty();
    //prevent page from refreshing
    evt.preventDefault();
    //get values for table width and height
    const tableWidth = $('#input_width').val();
    const tableHeight = $('#input_height').val();
    //create tableHeight tr's
    for (let y=0; y');
      console.log('have row');
      //create tableWidth td's
      for (let x=0; x tr:last').append('');
        console.log('have cells');
      }
    }
  }

  //function to change background
  let clicked = false;
  function tint(e){
    //stops dragging the colored cells
    e.preventDefault();

    clicked = true;
    selectedColor = '#' + $('#colorPicker').val();
    $(this).css({
      'background-color': selectedColor
    });
    $('#pixel_canvas').on('mouseenter','td', function(){
      if (clicked === true){
        console.log("entered cell");
        $(this).css("background-color",selectedColor)
      };
    });
    $('html').on('mouseup', function(){
      clicked = false;
    });
  }

  //ACTIONS
  //create new grid o button click
  $('button').click(makeGrid);

  //When a cell is clicked, or mouse is down, change the     background color
  $('#pixel_canvas').on('mousedown','td', tint);
  $('input[type="number"]').on('change',makeGrid);

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

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv