# contribute by Heinrich Liesefeld hr.liesefeld@mx.uni-saarland.de # First the program displays the default values Ð if you want to change anything, # type in the corresponding words that stand inside the brackets # It then prompts you for the parameters you want to change. # Afterwards you can enter the value you want to convert along # with the appropriate unit (cm, pix, or dg). # It prints out the converted values. # With ÒnÓ you restart the program to Êtype in another value # with the same settings or type ÒyÓ to change the settings. ÒxÓ ends the program #default settings $Bcm=36; #visible display width in cm $Ausg="20pix"; #start value in pix, dg oder cm $Bpix=1024; #resolution width in pixel $Abst=70; #distance between (the eyes of) the subject and the screen &Settings; &Input; &Main; sub Main { if ($Ausg=~/dg/) { &UmrechnungSehcm; print "\nSize in centimeters:\t$Res$EinhRes\n"; $Ausg=$Res.$EinhRes; &Umrechnungcmpix; print "Size in pixels:\t$Res$EinhRes\n\n"; } elsif ($Ausg=~/pix/) { &Umrechnungcmpix; print "\nSize in centimeters:\t$Res$EinhRes\n"; $Ausg=$Res.$EinhRes; &UmrechnungSehcm; print "Size in degree:\t$Res$EinhRes\n\n"; } elsif ($Ausg=~/cm/) { &Umrechnungcmpix; print "\nSize in pixels:\t$Res$EinhRes\n"; &UmrechnungSehcm; print "\nSize in degree:\t$Res$EinhRes\n\n"; } $weiterFr="\nChange settings? (y/n; escape: x): "; print $weiterFr; chomp($weiter=); until ($weiter eq "y" or $weiter eq "n" or $weiter eq "x") { print $weiterFr; chomp($weiter=); } if ($weiter eq "y") {&Settings; &Input; &Main;} elsif ($weiter eq "n") {&Input; &Main;} elsif ($weiter eq "x") {print "\n\n";} } sub UmrechnungSehcm { $konst1=0.017453293; #1dg ist 0,017rad! $konst2=57.29577951; if ($Ausg=~/dg/) { ($Start)=substr ($Ausg, 0, length($Ausg)-2); $Start=($Start/2)*$konst1; $Res=2*$Abst*(sin($Start)/cos($Start)); $EinhRes="cm"; } elsif ($Ausg=~/cm/) { ($Start)=substr ($Ausg, 0, length($Ausg)-2); $x=2*$Abst; $Res=2*atan2 ($Start, $x); $Res=$Res*$konst2; $EinhRes="dg"; } } sub Umrechnungcmpix { if ($Ausg=~/cm/) { ($Start)=substr ($Ausg, 0, length($Ausg)-2); $Res=($Bpix/$Bcm)*$Start; $EinhRes="pix"; } elsif ($Ausg=~/pix/) { ($Start)=substr ($Ausg, 0, length($Ausg)-3); $Res=($Bcm/$Bpix)*$Start; $EinhRes="cm"; } } sub Settings { print "\nThe default settings are:\ndisplay width in cm [Bcm]: $Bcm\n"; print "display width in pixels [Bpix]: $Bpix\n"; print "distance from screen in cm [Abst]: $Abst\n"; print "If you want to change anything, type in the corresponding words inside the brackets: "; chomp($Change=); if ($Change=~/Bpix/i) { $BpixFr = "\nDisplay width in pixels:"; print $BpixFr; chomp($Bpix=); while ($Bpix=~/[a-z]/) { print "\nJust type in a number (without unit)!"; print $BpixFr; chomp($Bpix=); } } if ($Change=~/Bcm/i) { $BcmFr = "\nDisplay width in cm:"; print $BcmFr; chomp($Bcm=); while ($Bcm=~/[a-z]/) { print "\nJust type in a number (without unit)!"; print $BcmFr; chomp($Bcm=); } } if ($Change=~/Abst/i) { $AbstFr = "\nDistance from screen in cm:"; print $AbstFr; chomp($Abst=); while ($Abst=~/[a-z]/) { print "\nJust type in a number (without unit)!"; print $AbstFr; chomp($Abst=); } } } sub Input { $Ausgfr = "\nInitial value in cm, dg or pix: "; print $Ausgfr; chomp($Ausg=); until ($Ausg=~/cm/ or $Ausg=~/pix/ or $Ausg=~/dg/) { print "\nPlease add the unit as pixel (pix), angle of view (dg) or centimeter (cm) to the value!"; print $Ausgfr; chomp($Ausg=); } while ($Ausg=~/,/) { print "\nUse "." as decimal point!"; print $Ausgfr; chomp($Ausg=); } }