Trivial calculation related to computer displays (core version)
Here's the core of the other version. I made something similar at first (except that it used zip ++). I have subsequently upgraded it to an ever neater form, but this does essentially the same. Read this one if you are short on time! ;-)
#!/usr/bin/runhugs
-- Calculates basic LCD monitor parameters from diagonals.
--
-- Copyright (c) bkil, 2009
-- License: GNU GPL v2 (or later), see the
-- attached gpl-2.0.txt for details.
--
--Changelog:
-- 2009.01.20 v0.0 first release
-- 2009.01.22 v0.1 refactoring: cleanup, typo in comments
-- 2009.01.29 v0.2 refactoring: friendlier names, Html type
-- 2009.01.30 v0.2.1 messy version
--
--the routine that calculates all the parameters
-- input: diagonal, horizontal pixels, vertical pixels
--
getparams :: Float -> Int -> Int -> String
getparams diag_inch xi yi =
show diag_inch ++ "in; " ++
show a ++ ":" ++ show b ++ "; " ++
show xi ++ "px; " ++
show yi ++ "px; " ++
show dotpitch ++ "mm; " ++
show megapix ++ "megapx; " ++
show area_cm ++ "cm^2; " ++
show w ++ "mm; " ++
show h ++ "mm"
where
a = xi `div` (gcd xi yi)
b = yi `div` (gcd xi yi)
x = fromIntegral xi ; y = fromIntegral yi
diag = diag_inch * inch
inch = 25.4 -- 1 inch in millimeters
aspect = x/y
calcdiag = sqrt (aspect*aspect + 1*1)
scale = diag/calcdiag
w = scale*aspect ; h = scale*1
area_cm = w*h / 1e2
megapix = x*y / 1e6
dotpitch = w/x
--outputs a few parameters of common computer displays
main = putStr result where
result = unlines results
results = [getparams diag x y | (diag,x,y) <- modes ]
modes = [
(13,640,480),
(13,800,600),
(15,1024,768),
(17,1280,1024),
(19,1440,900),
(19,1280,1024),
(20,1680,1050),
(20,1600,1200),
(22,1680,1050)
]
Comments
Post a Comment