[Haskell-cafe] creating graphics the functional way
Marc Weber
marco-oweber at gmx.de
Sun Aug 5 19:34:59 EDT 2007
On Mon, Aug 06, 2007 at 12:48:02AM +0200, Frank Buss wrote:
> I've created a small program to compose images with combinators:
>
> http://www.frank-buss.de/haskell/OlympicRings.hs.txt
>
> It produces TGA output, but I've converted it to PNG, because this is
> smaller:
>
> http://www.frank-buss.de/haskell/OlympicRings.png
>
> This is my first larger Haskell program and I have some questions:
>
> Nearly anything works without thinking too much about the types, but I don't
> like the use of fromInteger in the average and main functions. Is it
(floor ((fromInteger (r1+r2+r3+r4)) / 4)) ...
what about using `div` instead of / ?
(ghci sesion)
:Loading package base ... linking ... done.
Prelude> :t (/)
(/) :: (Fractional a) => a -> a -> a
Prelude> :t div
div :: (Integral a) => a -> a -> a
Prelude>
There has been a short discussion about this..
> possible that the integers are automaticly converted to floats?
> Is it possible to write functions with an arbitrary number of arguments?
> Would be nice if the average function would accept any number of pixel
> values.
I think I've read this question on #haskell once..
The answer of someone else was that he even could'nt think of it...
Using one argument for each pixel would be overkill.. because you don't
need different kinds of arguments here. So a list should be fine,
shouldn't it?
There are also some approaches of fixed length lists
/Database/HaskellDB/BoundedString.hs (from package haskelldb)
and the module SList
http://www.haskell.org/haskellwiki/Applications_and_libraries/Data_structures#Serialising_data (-> SList)
Think of an error message showing a function having 10.000 arguments? ..
- No thanks :)
Anyway.. you should have a look at http://haskell.org/haskellwiki/Applications_and_libraries
(-> Graphics) Package Haven.. I think this library does what you want as
well. Perhaps Pan is also interesting. But I haven't tried either of
them yet.
Marc Weber
More information about the Haskell-Cafe
mailing list