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
/**
   @fileOverview Main CSS file 
   @author www.udacity.com
*/

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
/**
    @fileOverview Main javascript program 
    @author Jaime Andres Catano
    @version 1.0
*/

/**
    @description Table generating function
    @param  evt
    @returns  nothing
 */

function makeGrid (evt) {
    /* Define variables */
    var tableHeight;
    var tableWidth;
    var tableRow = '';
    var i = 1;

    /* Prevent to delete the new table */
    evt.preventDefault();

    /*
        Delete the current table if the table was defined before
        - The use of the while loop is not required, but is used
          as is required by this exercise in order to delete the
          table rows.
    */
    while (true) {
        $('#pixel_canvas').find('tr').remove();
        break;
    }

    /* Getting the width and height values from the form */
    tableHeight = $('#input_height').val();
    tableWidth = $('#input_width').val();

    /* Generation of the table */
    /* -- Using 'for' loop in order to produce the  */
    for (var x = 1; x <= tableWidth; x++) {
        tableRow = tableRow+'';
    }

    /* -- Using 'while' loop in order to produce the  */
    while (i <= tableHeight) {
        $('#pixel_canvas').append(''+tableRow+'');
        i = i+1;
    }
    return;
}

/** @description  Getting the selected color
    @param  evt
    @returns  nothing
*/
function chooseColor (evt) {
    /* Color value from color picker */
    chosedColor = $('#colorPicker').val();

    /* Asign the color to the cell */
    $('#pixel_canvas').on('click', 'td', function() {
        $(this).css('background-color', chosedColor );
    });
    return;
}

/** @description  Starting function
    @param  nothing
    @returns  nothing
*/
function startProgram () {
    /* makeGrid function activated when the user uses the 'submit button'*/
    $('#sizePicker').on('submit', makeGrid);

    /* Color value from color picker */
    chosedColor = $('#colorPicker').val();

    /* Asign the color to the cell */
    $('#pixel_canvas').on('click', 'td', function() {
        $(this).css('background-color', chosedColor );
    });
  
    /* Color picker function */
    $('#colorPicker').on('change', chooseColor);
    return;
}

/** @description  Set the startProgram as the initial function of jQuery object
    TODO Request feedback from classmates and mentors.
*/
$(startProgram);
Wed, 12/27/2017 - 07:02

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv