var processor = {
  canvas: null,
  ctx: null,

  // { Param
 
  width: 200,
  height: 200,

  // }
  threadRunning: false,

  getOptions: function() {
    this.options = {};
    this.options.card = document.getElementById("card").value;
    this.options.t0 = document.getElementById("T0").value;
    this.options.g = document.getElementById("g").value;
    this.options.stepsPerT = document.getElementById("stepsPerT").value;
    if (document.getElementById("pointsTxt").value != "") {
      this.options.points = eval(document.getElementById("pointsTxt").value);
    }
  },
  doLoad: function() {
    this.getOptions();
    this.canvas = document.getElementById("playground");
    this.ctx = this.canvas.getContext("2d");
    //this.worker = new Worker("compute.js");

    annealing.init(this.options, 200, 200);
    try {
      document.getElementById("pointsTxt").value = JSON.stringify(annealing.points);
    } catch(e) {}
    graph.init("graph");
    graph.newGraph("temp", B);
    graph.newGraph("weight", R);
    this.drawPoints();
  },
  clear: function() {
    this.ctx.clearRect(0, 0, 200, 200);
  },
  drawPoints: function() {
    this.ctx.fillStyle = utils.buildColor(R);
    for (var i = 0; i < annealing.card; i++) {
      var x = annealing.points[i].x;
      var y = annealing.points[i].y;
      var size = 4;
      this.ctx.fillRect(x - size/2,
                        y - size/2,
                        size, size);
    }
  },
  drawPath: function(path, color, a, tb) {
    this.ctx.strokeStyle = utils.buildColor(color);
    this.ctx.fillStyle = utils.buildAColor(color, a);
    this.ctx.strokeWidth = 3;
    if (tb) {
      this.ctx.save();
      this.ctx.scale(0.2, 0.2);
      this.ctx.translate(800, 800);
    }
    this.ctx.beginPath();
    var firstPoint = true;
    for (var i = 0; i < annealing.card; i++) {
      var idx = path[i];
      var x = annealing.points[idx].x;
      var y = annealing.points[idx].y;
      if (firstPoint) {
        this.ctx.moveTo(x, y);
        firstPoint = false;
      } else {
        this.ctx.lineTo(x, y);
      }
    }
    this.ctx.closePath();
    this.ctx.stroke();
    this.ctx.fill();

    if (tb)
      this.ctx.restore();
  }
};


