Template:Team:Paris Saclay/simbox

From 2013.igem.org

(Difference between revisions)
Line 43: Line 43:
  this.timeout= null;
  this.timeout= null;
  this.curtime= 0.0;
  this.curtime= 0.0;
 +
 +
this.canv= null;
 +
this.ctx= null;
 +
this.draw_min_t= 0.0;
 +
this.draw_max_t= 0.0;
 +
this.draw_min_v= 0.0;
 +
this.draw_max_v= 100.0;
}
}
Line 145: Line 152:
  //Create canvas
  //Create canvas
-
  var canv= document.createElement('canvas');
+
  simulations[id].canv= document.createElement('canvas');
-
  var ctx= canv.getContext("2d");
+
  simulations[id].ctx= canv.getContext("2d");
-
  canv.id= "simbox_canv"+id;
+
  simulations[id].canv.id= "simbox_canv_"+id;
-
  canv.width= width;
+
  simulations[id].canv.width= width;
-
  canv.height= height;
+
  simulations[id].canv.height= height;
-
  sb.appendChild(canv);
+
  sb.appendChild(simulations[id].canv);
   
   
  //Init param box
  //Init param box
Line 263: Line 270:
  }
  }
   
   
 +
simbox_draw_graph(simid);
  simbox_update_controls(simid);
  simbox_update_controls(simid);
Line 362: Line 370:
  sim.curtime += sim.timestep;
  sim.curtime += sim.timestep;
 +
}
 +
 +
function simbox_drawXcoord(simid, t)
 +
{
 +
var tmin= simulations[simid].draw_min_t;
 +
var tmax= simulations[simid].draw_max_t;
 +
return simulations[simid].canv.width*(t-tmin)/(tmax-tmin);
 +
}
 +
function simbox_drawYcoord(simid, v)
 +
{
 +
var vmin= simulations[simid].draw_min_v;
 +
var vmax= simulations[simid].draw_max_v;
 +
return simulations[simid].canv.height*(v-vmin)/(vmax-vmin);
 +
}
 +
 +
function simbox_draw_graph(simid)
 +
{
 +
var sim= simulations[simid];
 +
var canv= sim.canv;
 +
var ctx= sim.ctx;
 +
 +
for(var i= 0 ; i < sim.molecules.length ; ++i)
 +
{
 +
  if(sim.mulecules[i].curve_show)
 +
  {
 +
  var dta= sim.mulecules[i].history;
 +
  if(dta.length < 2) continue;
 +
  ctx.moveTo( simbox_drawXcoord(simid, 0), simbox_drawYcoord(simid, dta[0]) );
 +
  for(var ti= 1 ; ti < dta.length ; ++ti)
 +
    ctx.lineTo( simbox_drawXcoord(simid, ti*sim.timestep), simbox_drawYcoord(simid, dta[ti]) );
 +
  ctx.stroke();
 +
  }
 +
}
}
}

Revision as of 01:03, 3 August 2013