var Canvas = require('canvas');

var clock = function (){
  this.canvas = new Canvas(24,6);
  this.ctx = this.canvas.getContext('2d');
  this.text_width = this.ctx.measureText(this.text).width;

  this.c = 0.0;
  this.params = [{'speed':0.05,'colour':'rgba(  0,128,  0,.25)'},
                 {'speed':0.07,'colour':'rgba(  0,  0,128,.25)'},
                 {'speed':0.11,'colour':'rgba(  0,128,128,.25)'},
                 {'speed':0.13,'colour':'rgba(128,  0,128,.25)'},
                 {'speed':0.17,'colour':'rgba(128,128,  0,.25)'},
                 {'speed':0.19,'colour':'rgba(128,  0,  0,.25)'}];

  this.pixels = new Array();


  for (var x = 0; x < 24;++x){ 
    this.pixels[x] = new Array();
    for (var y = 0; y < 6; y++){
      this.pixels[x][y] = new Array(); 
      for (var b = 0; b < 3; b++){ 
        this.pixels[x][y][b] = 0;
      }
    }
  }
};

// must return a 24x6x3 array of bytes (this.pixels)
clock.prototype.getFrame = function(spectrum,volume){
  this.c++;

  this.ctx.fillStyle = 'rgba(0,0,0,255)';
  this.ctx.fillRect(0,0,24,6);


  for (var i = 0; i < this.params.length; ++i) {
    var param = params[i];

    this.ctx.translate(12,3);
    this.ctx.rotate(params.speed*this.c);

    this.ctx.strokeStyle = params.colour;
    this.ctx.beginPath();
    this.ctx.lineTo(0, 0);
    this.ctx.lineTo(24, 0);
    this.ctx.stroke();

    this.ctx.rotate(-param.speed*this.c);
    this.ctx.translate(-12,-3);
  }

  for (var x = 0; x < 24;++x){ 
    for (var y = 0; y < 6; y++){
      var data = this.ctx.getImageData(x,y,1,1).data;
      this.pixels[x][y] = [data[0], data[1],data[2]];
    }
  }

  return this.pixels;
};





module.exports = clock;

@@ -598,16 +598,86 @@
 0,.25)'%7D
+,%0A                 %7B'speed':0.23,'colour':'rgba(128,  128,  128,.25)'%7D
 %5D;%0A%0A  th
@@ -1178,16 +1178,51 @@
  ++i) %7B%0A
+    if (spectrum%5Bi%5D%3C100) continue;%0A
     var 
@@ -1229,16 +1229,21 @@
 param = 
+this.
 params%5Bi
@@ -1301,17 +1301,16 @@
 te(param
-s
 .speed*t
@@ -1350,17 +1350,16 @@
  = param
-s
 .colour;

fix clock bugs