[Haskell-cafe] Re: creating graphics the functional way

Frank Buss fb at frank-buss.de
Mon Aug 6 23:13:34 EDT 2007


apfelmus wrote: 

> The idea of representing images simply by a function
> 
>   Int -> Int -> RGB
> 
> is great :) You may want to look at  Pan  and its various 
> offsprings, in
> particular  Pancito
> 
> http://www.haskell.org/haskellwiki/Applications_and_libraries/
> Graphics#Pan

this looks interesting. The Java applets demonstrates that it is possible to
implement this in realtime. I assume there are some clever optimizations
implemented, which could be done with Haskell, too.

>   positions :: [Point]
>   positions =
>     zip [0.5 + fromIntegral n * dx | n <- [-2..2]] (cycle [y1,y2])
>     where
>     dx = 0.125
>     y1 = 0.15
>     y2 = 0.25

Nice calculation for the positions, but at least for me it is more difficult
to understand it than just writing the 5 points. But using lists is a good
idea. I've updated the source:

http://www.frank-buss.de/haskell/OlympicRings2.hs.txt
http://www.frank-buss.de/haskell/OlympicRings2.png

The anti-aliasing doesn't look good anyway, so I have removed it.

Very cool for me was the "foldr (.) id" construct, which someone on #haskell
suggested. Changing separate x/y coordinates to a list with 2 elements
helped, too, to cleanup the source code. Maybe some more cleanups and the
PNG save implementation, and then this code could be used as a small
practical example for other Haskell newbies like me.

BTW: Is there any coding standard for Haskell programs? I've seen different
formattings, like how to indent "where" and the following parts of the code.
Is there a common practice?

-- 
Frank Buss, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de



More information about the Haskell-Cafe mailing list