

procedure cross(x,y,r:integer);
begin
line(x-r,y,x+r,y); line(x,y-r,x,y+r);
end;

procedure changeColor;
begin
inc(plotColor);
if plotColor>15 then plotColor:=1;
end;

procedure plotAxes;
var i,j,k:integer;
    x,y:integer;
begin
clearDevice;
setColor(blue);
line(0,yMid,xMax,yMid); line(xMid,0,xMid,yMax);
for i:=1 to 50 do
   begin
   y:=yMid-round(i*10*forcePix);
   line(0,y,10,y);
   y:=yMid+round(i*10*forcePix);
   line(0,y,10,y);
   end;
for i:=0 to 6 do
  begin
  x:=xMid-round(i/plotPeriod/10); {0.1 sec. marks}
  line(x,yMid+5,x,yMid-5);
  x:=xMid+round(i/plotPeriod/10);
  line(x,yMid+5,x,yMid-5);
  end;
outTextXY(xMid+10, yMax-50,'m - menu');
end;

procedure showBeads;
var x,y:integer;
begin
setColor(black);
if oldPixR<yMax then
  begin circle(oldX,oldY,oldPixR); circle(oldXP,oldYP,oldPixR);
  line(oldXP-oldPixR div 2,oldYP+oldPixR,oldXP-oldPixR,oldYP+3*oldPixR);
  line(oldXP+oldPixR div 2,oldYP+oldPixR,oldXP+oldPixR,oldYP+3*oldPixR);end;
cross(oldX,oldY,oldPixC);
x:=xMid+round((beadPosX)/pixScale);
y:=yMid+round(beadPosY/pixScale);
setColor(red);
if pixR<yMax then circle(x,y,pixR);
cross(x,y,pixC);
oldX:=x; oldY:=y; oldPixR:=pixR; oldPixC:=pixC;
x:=xMid+round((pipettePosX)/pixScale);
y:=yMid+round(pipettePosY/pixScale);
setColor(green);
circle(x,y,pixR);
line(x-pixR div 2,y+pixR,x-pixR,y+3*pixR);
line(x+pixR div 2,y+pixR,x+pixR,y+3*pixR);
oldXP:=x; oldYP:=y;
end;

procedure displayReadings;
var message,snert:string; x,y:integer;
begin
x:=0; y:=yMax-80;
bar(x,y,x+130,y+50); setColor(green);
str(fltLightForce*1e12:1:1,message); {mean light force in pN}
outTextXY(x,y,'avForce='+message);
str(sqrt(dXsqr)*1e9:1:1,message);   {trap-bead distance noise in nm}
outTextXY(x,y+10,'<deltaX>rms='+message);
str(sqrt(avdTenSqr)*1e12:2:2,message); {rms deviation in molecular tension}
outTextXY(x,y+20,'<deltaF>='+message);
str(forkPos,message);                   {fork position}
outTextXY(x,y+30,'forkPos='+message);
str(time-resetTime:1:1,message);     {current time in seconds}
outTextXY(x,y+40,'time='+message);
end;

procedure plotForce;
var x,x2,y:integer;
begin
x:=round(time/plotPeriod) mod xMax;
putPixel(x,oldYf[x],black); putPixel(x,oldYL[x],black);
{if movingForward then plotColor:=red else plotColor:=cyan;}
y:=yMid-round((avLightForce-initForce)*1e12*forcePix);
putPixel(x,y,plotColor); oldYf[x]:=y;
x:=round(xMax*(piezoPosX-2*r)/Lmax);
y:=yMax-round((avLightForce-initForce)*1e12*forcePix);
setColor(plotColor);
if (oldEx>0) and (oldF>0) then line(oldEx,oldF,x,y);
oldEx:=x; oldF:=y;
end;


procedure startGraphics;
begin
forcePix:=10;
i:=detect;
initgraph(i,j,'');
xMax:=getMaxX; yMax:= getMaxY; xMid:=xMax div 2; yMid:=yMax div 2;
clearDevice;
setFillStyle(1,blue);  setTextStyle(0,0,0); plotColor:=2;
plotAxes;
pixScale:=(4*r)/xMid;{meters/pixel}; pixR:=round(r/pixScale);
pixC:=round(1e-8/pixScale);
end;

procedure promptForces;
begin
outTextXY(100,yMid+100,'what max force? (pN)');
readln(maxForce);  maxForce:=maxForce*1e-12;
outTextXY(100,yMid+130,'what min force? (pN)');
readln(minForce);  minForce:=minForce*1e-12;
outTextXY(100,yMid+160,'what pulling rate? (nm/sec)');
readln(pullRate); piezoStep:=pullRate*cyclePeriod*1e-9;
movingForward:=true;  setColor(black);
outTextXY(100,yMid+100,'what max force? (pN)');
outTextXY(100,yMid+130,'what min force? (pN)');
outTextXY(100,yMid+160,'what pulling rate? (nm/sec)');
end;

procedure showMenu;
var xStart,yStart:integer;
begin
xStart:=150; yStart:=yMax-40;
outTextXY(xStart,yStart+10,'r-readings e-erase c-plotColor  b-Showbeads q-quit');
outTextXY(xStart,yStart+20,' <-moveTrap->  F7-autoRamp+file F8-reverseRamp');
outTextXY(xStart,yStart+30,'f/F-force l/L-length  w-constWeight g/G-wtSetPt+H/h');
end;

