Renderer.js 907 Bytes
Newer Older
Alexander Bazo committed
1 2 3
/* eslint-env browser */

const GAZE_POINT_RADIUS = 15,
4
  DEFAULT_GAZE_POINT_COLOR = "#4cd494";
Alexander Bazo committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

var context;

class Renderer {

  static setContext(_context) {
    context = _context;
  }

  static drawGazePoints(gazePoints) {
    context.clearRect(0, 0, screen.width, screen.height);
    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();
25
    context.fillStyle = gazePoint.color;
Alexander Bazo committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
    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;