Renderer.js 900 Bytes
Newer Older
Alexander Bazo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* eslint-env browser */

const GAZE_POINT_RADIUS = 15,
  GAZE_POINT_COLOR = "#4cd494";

var context;

class Renderer {

  static setContext(_context) {
    context = _context;
  }

  static drawGazePoints(gazePoints) {
    context.clearRect(0, 0, screen.width, screen.height);
    context.fillStyle = GAZE_POINT_COLOR;
    for (let i = 0; i < gazePoints.length; i++) {
      Renderer.drawSingleGazePoint(gazePoints[i]);
    }
  }

  static drawSingleGazePoint(gazePoint) {
    let inversedAge = 1 - gazePoint.relativeAge,
      radius = inversedAge * GAZE_POINT_RADIUS;
    context.save();
    context.globalAlpha = inversedAge;
    context.globalAlpha = 1;
    context.beginPath();
    context.ellipse(gazePoint.screenX, gazePoint.screenY, radius, radius,
      Math.PI /
      4, 0, 2 * Math.PI);
    context.closePath();
    context.fill();
    context.restore();
  }

}

export default Renderer;