Created
December 29, 2009 04:32
-
-
Save tensorpudding/265153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-| | |
The Grid module creates a grid datatype that represents the pixmap that we will output to. It is a glorified matrix. This code really sucks. | |
-} | |
module Grid (Grid | |
,createGrid | |
) where | |
import Data.Complex | |
-- |As was already stated, glorified matrix. | |
type Grid a = [[a]] | |
listFrom :: (RealFloat a, Enum c, Integral c) => (a,a) -> c -> [a] | |
listFrom (low,high) res = map f [0..res] | |
where | |
f x = low + (high - low) * ((fromIntegral x) / (fromIntegral res)) | |
{-| | |
createGrid is the main grid-creation function. | |
It takes two tuples, which describe the range of the real and imaginary parts of the inputs, and the resolution of the image in the standard format, and returns a grid of complex numbers that represents this subset of C. | |
-} | |
createGrid :: (RealFloat a, Enum c, Integral c) => (a,a) -> (a,a) -> (c, c)-> Grid (Complex a) | |
createGrid (rLow,rHigh) (iLow,iHigh) (xRes,yRes) = map (\i -> map (\r -> r :+ i) rs) $ reverse is | |
where | |
is = listFrom (iLow, iHigh) yRes | |
rs = listFrom (rLow, rHigh) xRes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment