! Sys_calibrate

Post Reply
User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

! Sys_calibrate

Post by Dutchman » Fri Nov 22, 2019 2:13 pm

! Sys_calibrate contains a function to determine the conversion factor between points on 'Screen' and millimeters on 'Display'.
Detailed information can be found in "Callibrate.pdf" which has been attached.
Callibrate.pdf
(175.12 KiB) Downloaded 6 times
During run time, function Sys_Callibrate writes several parameters to console and returns the zoom factor on exit.

Code: Select all

' {/Extensions/System/! Sys_calibrate}
[ calibration of screen to display ]
'
[–––––––––––––––––––––––– Functions ––––––––––––––––––––––––
[Calibrate Screen Scale to Display in pixels per mm}
Sys_Callibrate
determine zoomfactor between 'Screen' and 'Display'
––––
End of function description –––––––––––]
'
[–––––––––––––––––––––– Implementation ––––––––––––––––––––––]
DEF Sys_Callibrate ' by Ton Nillesen, November 2019
'--- Constants and presets
Font$="Arial Rounded MT Bold"
FontSize=20
Fh=1.55 ' ratio between fontsize and lineheight
Txt$="Enlarge screenwidth to maximum by pulling left and right edges."
DRAW FONT Font$,FontSize
DRAWCOLOR 0,0,1
th=STRHEIGHT Txt$ : tw=1.05*STRWIDTH txt$
Txt$+=CR$+"Then measure length of bar in millimeters and enter it."
SCRSIZE tw+100,100
Margin=10 ' left and right in points
R0=SCRSCALE*Margin ' ruler margin in pixels
SubDiv=20 ' pixels per subdivision between ticks
Div=5*subdiv ' pixels between major ticks
Ph=20 ' half tick height
DRAW MANUAL
DRAW COLOR 0,0,0
GOSUB Init
ww,wh=SCRSIZE|2
DO '––––––––– Dynamic section –––––––––
  CLS
  DRAW CLEAR 1,1,1
  sw=SCRWIDTH
  w$=sw$+STRTEXT sw "0"
  INSIGN TEXT 1,w$
  Pixels=sw*SCRSCALE : pixels-=2*r0
  Ruler=div*FLOOR(pixels/div)
  PRINT "Ruler =";ruler;"pixels"
'--- draw ruler
  FOR i=0 TO 5 'line width of ruler
    DRAW PIXEL r0,py-i+2,r0+ruler,py-i+2
  NEXT i
'--- draw ticks
  x=0
  DO IF x<=ruler 
    IF ABS(INT(x/div)-x/div)<1e-6 THEN GOSUB Marker
    FOR j=0 TO 3 ' tick width
      DRAW PIXEL r0+x-j+2,py+ph,r0+x-j+2,py-ph 
    NEXT j
   x+=subdiv
  REDO
'--- ruler info
  rw$="Ruler length "+(STRTEXT x-subdiv "0")+" pixels"
  INSIGN TEXT 2,rw$
  y+=fh*th
  DRAW UPDATE
'--- Get length
  DO
    CPU RELAX
  REDO IF NOT(INEDIT CHANGED 4) AND (sw=SCRWIDTH) ' wait for change
  L$=INEDIT TEXT 4
  Length=STR NUM L$
  IF Length>0
    INSIGN TEXT 3 a$+" "+L$
    INEDIT DELETE 4
  ELSE
    INEDIT TEXT 4 ""
  ENDIF
REDO IF (Length<=0)
CLS '––––––––– Display –––––––––
SCRSIZE ww, wh
rw$="Ruler was "+(STRTEXT ruler "0")+" pixels"
INSIGN TEXT 2,rw$
sw$="Display was set to " ' text in width
INSIGN TEXT 1 sw$+STRTEXT sw
PRINT "Display width =";sw;"points"
PRINT "Ruler =";ruler;"pixels"
PRINT "Length ruler =";length;"millimeter"
l$=STRTEXT Length "0.00"
Res$=STRTEXT ruler/length "0.000"
Res2$=STRTEXT 25.4*ruler/length "0.0"
PRINT "Resolution = "+Res$+" ppmm"
PRINT "           = "+Res2$+" dpi"
s1=ruler/(SCRSCALE*72) 
PRINT "On 'Screen' ruler = "+STRTEXT s1 "0.000 inch"
s2=length/25.4
PRINT "On 'Display' ruler = "+STRTEXT s2 "0.000 inch"
zoom=s2/s1
PRINT "Zoom = "+STRTEXT zoom "0.000"
txt$="Set Sys.zoom (from 'Screen' to 'Display') to "+STRTEXT s2/s1 "0.000"
'--- draw zoomfactor
DRAWCOLOR 1,0,0
DRAW TEXT txt$ margin,lasty
DRAW UPDATE
RETURN zoom' from function
'----------- Local   Subroutines -----------
Marker: '---------- draw marker
FOR j=0 TO 3 ' marker width
  DRAW PIXEL r0+x-j+2,py+2*ph,r0+x-j+2,py-2*ph 
NEXT j
RETURN
Init:'---------- initialise
'--- Message
y=10
INSIGN SET 0,txt$,margin,y,tw+5,2*fh*th ' 2 lines
INSIGN FONT 0,Font$,FontSize
INSIGN FCOLOR 0,1,0,0
y+=2*fh*th
'--- Width
y+=10
sw$="Display set to " ' text in width
ww=1.05*(STRWIDTH sw$+"was 0000")
INSIGN SET 1,"",margin,y,ww,fh*th ' 2 lines
INSIGN FONT 1,Font$,FontSize
INSIGN FCOLOR 1,  0,0,0
INSIGN BCOLOR 1,  1,1,1
'--- Ruler y
y+=2*fh*th
py=SCRSCALE*y
y+=0.5*fh*th
'---- length
rw$="Ruler length="+" 0000 "+" pixels"
rw=1.05*STRWIDTH rw$
y+=10
INSIGN SET 2,"",margin,y,rw,fh*th ' 2 lines
INSIGN FONT 2,Font$,FontSize
INSIGN FCOLOR 2, 0,0,0
INSIGN BCOLOR 2, 1,1,1
y+=2*fh*th
'--- Get length
a$=" Length of ruler in millimeters =  "
aw=1.05*STRWIDTH a$
y+=10
ew=60 'edit width
INSIGN SET 3,a$,margin,y,aw+ew+12,1.2*fh*th ' 2 lines
INSIGN FONT 3,Font$,FontSize
INSIGN FCOLOR 3, 1,1,0
INSIGN BCOLOR 3, 0,0,1
INEDIT SET 4,"",margin+aw+3,y+6,ew
DRAW SIZE 5
DRAW COLOR 1,0,0
lasty=y+10+2*fh*th
RETURN
END DEF
# Calibrate zoom.bb is a test program which also can be used to transfer the zoom factor manually to "! Sys_Spec".
It is still a long way to go

Post Reply