JSFiddle - React, Tailwind, and code Playground

by digitalicarus

HTML

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <div id="main">
        <canvas></canvas>
        </div>
       
        <div id="controls">
            <div class="control">
                recalcOnRender <input type="checkbox"/>
            </div>
            <div class="control">
                decayRate 
            </div>               
            <div class="control">
                degree (2^N-1 midpoints) <br/>
                [slider]
                OR
                auto (based on canvas width)                        
            </div>    
            <div class="control">
                interpolation 
                <span class="label">truncate</span>
                <span class="label">average</span>
            </div>
        </div>
    </body>
</html>

CSS

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, head, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* -- MY STYLES -- */
/* -- cheat cause I don't want to blit the background with fill() */
canvas {
    background: black;
}
#main {
    position: absolute;
    overflow: hidden;
}
#controls {
    display: none;
    font-family: monospace;
    color: lime;
    position: absolute;
    top:0;
    left:0;

}

#controls input {
    vertical-align: baseline;
}
.control:before {
    content: '-';
}

JavaScript

//http://www.gamedev.net/topic/579738-web-javascript-game-loop/
// -- CREDIT http://www.gamedev.net/user/107433-bunzaga/ bunzaga
// -- requestAnimationFrame http://paulirish.com/2011/requestanimationframe-for-smart-animating/
//http://dev.opera.com/articles/view/framerate-control-system-for-javascript/
//http://jsfiddle.net/digitalicarus/4kshN/3/



var Wee = (function() {
    var FPS=           60,
        rate=          60,
        dt=            1/60,
        accrued=       0.0,
        last=          Date.now()/1000,
        fpsDisplay=    $('<div id="fpsDisplay"/>').appendTo('body')[0],
        frameCounter=  0,
        droppedFrames= 0,
        interval=      null,
        paused=        false,
        intervalRate=  Math.floor(1000/FPS) - 1,
        ciCallback=    function(){},
        upCallback=    function(){},
        rdCallback=    function(){},
        pauseCallback= function(){};
    
    // Use this callback to latch your inputs if you want
    // Kinda not useful cause you could latch em when you get the events
    //var CheckInput=    function() {
    //    ciCallback();
    //};
    
    // Updates can happen more frequently than render. This call back 
    // will fire very rapidly. Don't waste much time in here at all!
    // You can use this for collision detection etc. 
    // Just check if you have already updated this render cycle and bail ASAP.
    var Update=        function() {
        frameCounter++;
        droppedFrames++;
        upCallback();
    };
           
    // This is the one you really want. Draw the result of your state in here.
    var Render=        function() {
        rate = (droppedFrames > 0) ? 
            ((rate+(FPS/(droppedFrames*2)))/2):
            ((rate + FPS)/2);
        
        // just render every N frames to avoid a jarring display
        fpsDisplay.innerHTML = parseInt(rate,10)+" FPS";
        droppedFrames = -1;
        rdCallback();
    }; 

    var GameLoop=      function() {
        var now =...