#!/usr/bin/env python
# -*- coding: UTF8 -*-

#       Copyright Mathieu Rousseau - mathieu_AT_effraie_DOT_org
#       Derniére version disponible sur :
#       http://vrac.effraie.org/prog/hyperfocale/hyperfocale-latest.py

#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

#****************************************************
# Choisissez ici la valeur adaptee à votre boitier
# Trouvez la bonne valeur sur cette page:
# http://www.dofmaster.com/digital_coc.html
#Nikon d40/50/70/80/100/200/300:
confusion_circle = 0.02

#Canon 300D/400D/40D
#confusion_circle = 0.019

#24x36 (reflex argentiques, numeriques Full Frame...)
#confusion_circle = 0.03

#Film 6x6
#confusion_circle = 0.05

#Film 4x5
#confusion_circle = 0.01

f = raw_input("Quelle focale (en mm)? ")
focale = float(f)
d = raw_input("Quel diaphragme ? ")
diaph = float(d)
hyperfocale = ((focale*focale)/(diaph*confusion_circle))/1000
print """
Pour ce couple focale/diaphragme, l'hyperfocale est de : %.2f mètres.
Si le point est fait a cette distance, la zone de netteté s'étendra de %.2f mètres à l'infini.
""" % (hyperfocale, hyperfocale/2)
dof = raw_input("Calculer une profondeur de champ ? (o/N) ")
if (dof == "o"):
    i = raw_input("Distance de mise au point (en m.mm) : ")
    distance = float(i)
    if (distance >= hyperfocale):
        ppn = (hyperfocale*distance)/(hyperfocale + distance)
        print"""
        Premier plan net : %.2f mètres
        Dernier plan net : infini
        Profondeur de champ totale : infinie
        """ % (ppn)
        quit()
    dpn = (hyperfocale*distance)/(hyperfocale - distance)
    ppn = (hyperfocale*distance)/(hyperfocale + distance)
    profondeur = dpn - ppn
    print"""
    Premier plan net :  %.2f mètres
    Dernier plan net : %.2f mètres
    Profondeur de champ totale : %.2f m.
    """ % (ppn,dpn,profondeur)
    quit()
else:
    quit()
