JSFiddle - React, Tailwind, and code Playground

by digitalicarus

HTML

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
    </body>
</html>

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 =...