Skip to content

Instantly share code, notes, and snippets.

@lustremedia
Created February 28, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lustremedia/f80df6d6c31f43d85578 to your computer and use it in GitHub Desktop.
Save lustremedia/f80df6d6c31f43d85578 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
use strict;
use warnings;
my $pi = 3.1415;
my $focDist = 700; #e.g. 10000mm = 1m Focus Distance
my $cropFactor = 1.6;
my $focLen = 24*1.6; #e.g. 50mm
my $actualFocLen = $focLen * $cropFactor;
my $fstop = 2.8; # 1, 1.4 , 2 , 2.8, 4, 5.6
my $diameter = getDiameterFromFstop();
my $coc = 0.018; #Circle of Confusion APS-C Canon -> 0.018 35mm -> 0.029
my $hfd = calcHyperFocalDistance($fstop,$coc,$focLen);
my $apertureArea = areaOfCircle($diameter);
my $nearDistance = nearDistance();
my $farDistance = farDistance();
my $dof = dof();
my $unit = "mm";
#aperture subs
sub areaOfCircle {
return $pi * ($diameter/2);
}
sub getDiameterFromFstop {
return $focLen/$fstop;
}
sub getFstopFromDiameter {
return $focLen/$diameter;
}
sub fStopUp {
$fstop = $fstop*sqrt(2);
$diameter = getDiameterFromFstop();
$apertureArea = areaOfCircle();
$hfd = calcHyperFocalDistance();
printCamValues($fstop,$focLen,$hfd,$coc,$apertureArea,$diameter,"We changed the F/STOP one UP!");
return $fstop;
}
sub fStopDown {
$fstop = $fstop/sqrt(2);
$diameter = getDiameterFromFstop();
$apertureArea = areaOfCircle();
$hfd = calcHyperFocalDistance();
printCamValues("We changed the F/STOP one Down!");
return $fstop;
}
sub changeFocLen {
$focLen = $_[0];
$diameter = getDiameterFromFstop();
$apertureArea = areaOfCircle();
$hfd = calcHyperFocalDistance();
printCamValues("We changed the FOCAL LENGTH to",$focLen," ");
return $focLen;
}
sub calcHyperFocalDistance {
return (($focLen*$focLen)/($fstop*$coc))+$focLen;
}
sub nearDistance {
return ($focDist*($hfd-$focLen))/($hfd+$focDist-(2*$focLen));
}
sub farDistance {
return ($focDist*($hfd-$focLen))/($hfd-$focDist);
}
sub dof {
return $farDistance-$nearDistance;
}
sub unitConverter {
if($_[0] eq "mm") {
return sprintf("%.1f",$_[1]),"mm";
} elsif ($_[0] eq "cm") {
return sprintf("%.1f",$_[1]/10),"cm";
} elsif ($_[0] eq "m") {
return sprintf("%.1f",$_[1]/100),"m";
} else {
return sprintf("%.1f",$_[1]),"mm";
}
}
sub printCamValues {
print "\n";
print "---------------------------\n";
print $_[0],"\n";
print "---------------------------\n";
print "------------FOCUS----------\n";
print "FOCUS DISTANCE: ",unitConverter($unit,$focDist),"\n";
print "FOCAL LENGTH: ",unitConverter($unit,$focLen),"\n";
print "HYPER FOCAL DISTANCE: ", unitConverter($unit,$hfd),"\n";
print "\n";
print "-------------DOF-----------\n";
print "NEAR DISTANCE SHARPNESS ",unitConverter($unit, $nearDistance),"\n";
print "FAR DISTANCE SHARPNESS ",unitConverter($unit, $farDistance),"\n";
print "DOF SIZE ",unitConverter($unit, $dof),"\n";
print "\n";
print "----------APERTURE---------\n";
print "FSTOP: F/",$fstop,"\n";
print "CIRCLE OF CONFUSION: ",$coc,"\n";
print "APERTURE AREA: ",unitConverter($unit, $apertureArea),"^2\n";
print "APERTURE DIAMETER: ",unitConverter($unit, $diameter),"\n";
print "---------------------------\n";
print "\n";
}
printCamValues("CAMERA DEFAULT SET");
#fStopDown();
#fStopUp();
changeFocLen(70);
#fStopUp();
#fStopDown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment