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.

            
              <body>
    <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" value="1">
        Grid Width:
        <input type="number" id="inputWidth" name="width" min="1" value="1">
        <input type="submit">
    </form>

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

    <h2>Design Canvas</h2>
    <table id="pixelCanvas">
      
      <!-- append grid here -->
    </table>

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


/** Custom CSS **/

table {
    table-layout: fixed;
    /* Under the "fixed" layout method, the entire table can be rendered once the first table row has been downloaded and analyzed. */
}


            
          
!
            
                  /***** IMPORTANT TODO: Consolidate local and copeden work *****/

                                 /* TODO: Push all work to GitHub */


/* VARIABLE ASSIGNMENT */

        var $submit = $("input[type=submit]");
        var inputHeight = $("#inputHeight").attr("value", 10); // inital height, width = 10
        var inputWidth = $("#inputWidth").attr("value", 10);  




    /* FUNCTION: MAKE GRID! */

    /** DONE: add input value functionality **/

        $submit.on("click", function(evt){
            evt.preventDefault();
            makeGrid(inputHeight.val(), inputWidth.val());
        });

        /* FUNCTION: Make a grid! */
        function makeGrid(height, width) {

            for (var row = 0; row < height; row++) {
                // create row
                var table = $("#pixelCanvas"); // #pixelCanvas
                var tr = document.createElement("tr");
                for (var col = 0; col < width; col++) {
                    var td = document.createElement("td");
                    // $(td).addClass("fill");
                    $(tr).append(td); // 10 times

                }
                $(table).append(tr);
            }

        }


    /***** IMPORTANT TODO: Consolidate local and copeden work *****/

                                 /* TODO: Push all work to GitHub */



    /* FUNCTION: Pick a color! */

    /** TODO: Build colorPicker functionality
        1) Select Color
        2) Assign Selected Color to currentColor
        3) Test: console.log(current color)

        Fixed: Able to set color for table, not for td. Why?
        REFERENCE: 
          http://api.jquery.com/on/
          => ".on( events [, selector ] [, data ], handler )"

    **/

    /** TODO: Create function for colorPicker  
        TODO: Fix for "submit" appending additonal grids
        TODO: V2: Feature to reset grid
        TODO: V2: Mobile-compliance for colorPicker
        TODO: V2: Feature for removing color

    **/


        $('#pixelCanvas').on('click', 'td', function() {
            var colorPicker = $("input[type=color]");
            var currentColor = colorPicker.val();
            $(this).css("backgroundColor",currentColor);

        });


    /***** IMPORTANT TODO: Consolidate local and copeden work *****/

                                 /* TODO: Push all work to GitHub */

            
          
!
999px
Loading ..................

Console