{"size": 1294, "ext": "js", "max_stars_repo_path": "framebuffer.js", "max_stars_repo_name": "thecoder08/node-framebuffer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "framebuffer.js", "max_issues_repo_name": "thecoder08/node-framebuffer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "framebuffer.js", "max_forks_repo_name": "thecoder08/node-framebuffer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.3103448276, "max_line_length": 89, "alphanum_fraction": 0.5347758887}
module.exports.Framebuffer = function(dev) {

var fs = require('fs');

this.framebuffer = fs.openSync(dev, 'w');

this.getPixel = function(x, y) {
  return ((y * 1920) + x) * 4;
}

this.setPixel = function(x, y, color) {
  colorToDraw = [...color];
  colorToDraw.push(0);
  fs.writeSync(this.framebuffer, new Uint8Array(colorToDraw), 0, 4, this.getPixel(x, y));
}

this.clear = function() {
  fs.writeSync(this.framebuffer, new Uint8Array(8294400), 0, 8294400, 0);
}

this.drawRectangle = function(x, y, width, height, color) {
  for (var i = y; i < (y + height); i++) {
    for (var j = x; j < (x + width); j++) {
      this.setPixel(j, i, color);
    }
  }
}

this.drawLine = function(x0, y0, x1, y1, color) {
   var dx = Math.abs(x1 - x0);
   var dy = Math.abs(y1 - y0);
   var sx = (x0 < x1) ? 1 : -1;
   var sy = (y0 < y1) ? 1 : -1;
   var err = dx - dy;

   while(true) {
      this.setPixel(x0, y0, color);

      if ((x0 === x1) && (y0 === y1)) break;
      var e2 = 2*err;
      if (e2 > -dy) { err -= dy; x0  += sx; }
      if (e2 < dx) { err += dx; y0  += sy; }
   }
}

}

module.exports.colors = {
  red: [0, 0, 255],
  blue: [255, 0, 0],
  green: [0, 255, 0],
  white: [255, 255, 255],
  black: [0, 0, 0],
  cyan: [255, 255, 0],
  magenta: [255, 0, 255],
  yellow: [0, 255, 255]
}
