• Thanks Gordon! mapInPlace sure is much faster. Here's my fade code with callback:

    function fade(b, direction, callback) {
      var m = 1;
      var clone = new Uint8Array(b.length);
      clone.set(b);
      var interval = setInterval(function () {
        if(direction===0){
          E.mapInPlace(b, clone, function (x) {
            return x * m;
          });
        }else{
          E.mapInPlace(b, clone, function (x) {
            return x - (x * m);
          });
        }
        
        m *= direction===0?0.85:0.95;
        leds.buffer = clone;
        leds.flip();
        if (m <= (direction===0?0.01:0.1)) {
          clearInterval(interval);
          if (callback) {
            callback();
          }
          E.mapInPlace(b, clone, function (x) {
            return direction===0?0:x;
          });
          leds.buffer = clone;
          leds.flip();
        }
      }, 10);
    }
    
About

Avatar for n00b @n00b started