[Haskell-cafe] creating graphics the functional way
Marc A. Ziegert
coeus at gmx.de
Mon Aug 6 16:18:14 EDT 2007
Am Montag, 6. August 2007 00:48 schrieb Frank Buss:
> I've created a small program to compose images with combinators:
>
> http://www.frank-buss.de/haskell/OlympicRings.hs.txt
>
...
> look very smooth. And it is very slow, it needs about 40 seconds on my
>computer to calculate the image. Using parametrized combinators sounds like
...
in that source file, you define Size and Pixel as structs of "Integer"s. that are neither unsigned chars (8_bit) nor ints (32-64_bit) nor floats (32_bit) but an artificial oo_bit int (1 int + list of bytes).
i'm sure you will gain a speedup by redefining these structs. i.e. use Float or Int instead of Integer; see Data.Int and Data.Word for more alternatives.
- marc
>
[code snippet from source file]
-- image size
data Size = Size { width :: Integer, height :: Integer }
deriving (Eq, Ord, Show, Read)
-- RGB components for an image pixel
data Pixel = Pixel { r :: Integer, g :: Integer, b :: Integer }
deriving (Eq, Ord, Show, Read)
-- helper functions for saving bytes
writeByte byte = putWord8 (fromIntegral byte)
writeBytes bytes = mapM_ putWord8 bytes
-- binary instance for saving Pixels
instance Binary Pixel where
put (Pixel r g b) = do
writeByte b
writeByte g
writeByte r
get = error "Pixel get not supported"
[/code]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070806/ded4d385/attachment.bin
More information about the Haskell-Cafe
mailing list