Commits

Jason S committed 183dc13

minor tweaks to improve smoothness for reduced framerate

  • Participants
  • Parent commits 3d09d10

Comments (0)

Files changed (2)

demos/pendulum/togif/pendulum.html

     
     function tick()
     {
-        pendulum.update(dt);
-        pendulum.draw(canvas, bkgdfunc);
+        var nop = function(){};
+        pendulum.update(dt*0.5);
+        pendulum.draw(canvas, {backgrounddraw: bkgdfunc, opacity: 0.05});
+        pendulum.update(dt*0.5);
+        pendulum.draw(canvas, {backgrounddraw: nop});
     } 
     var i = 0;
-    var nframes = 500;
+    var nframes = 1000;
     setInterval(function() {
         tick();
         document.getElementById('count').textContent = ''+i;

demos/pendulum/togif/pendulum.js

     simulateCoils(etc, sth, cth > 0 ? 1 : 0, dt);
 }
 
-function _draw(canvas, pendulum, backgrounddraw) {
+function _draw(canvas, pendulum, opt) {
     var ctx = canvas.getContext('2d');
     // Wipe canvas
     var cw = canvas.width;
     var ch = canvas.height;
-    if (backgrounddraw != null)
-        backgrounddraw(ctx,0,0,cw,ch);
+    if (opt == null)
+        opt = {}
+    if (opt.backgrounddraw != null)
+        opt.backgrounddraw(ctx,0,0,cw,ch);
     else
         ctx.clearRect(0, 0, cw, ch);
     var xc = cw/2;
     var y = yc + pr * cth;
     
     // Draw the box
-    ctx.strokeStyle = '#4080a0';
-    ctx.fillStyle = '#80c0e0';
+    var opacity = opt.opacity || 1.0;
+    ctx.strokeStyle = 'rgba(64,128,160,'+opacity+')';
+    ctx.fillStyle = 'rgba(128,192,224,'+opacity+')';
     
     var h = 8;
     ctx.fillRect(cw*0.1,h,cw*0.8*etc.showcoils(0),h);
 
     ctx.beginPath();    
     ctx.arc(x, y, pendulum.radius, 0, 2 * Math.PI, false);
-    ctx.fillStyle = '#80c0e0';
     ctx.fill();
     ctx.lineWidth = 2;
-    ctx.strokeStyle = '#4080a0';
     ctx.stroke();
 }
 
 return {pendulum: pendulum,
         etc: etc,
         update: function(dt) { timestep(pendulum, etc, dt); },
-        draw: function(canvas, bkgdf) { _draw(canvas, pendulum, bkgdf); }
+        draw: function(canvas, opt) { _draw(canvas, pendulum, opt); }
        };
 
 }