[Haskell-cafe] creating graphics the functional way

Frank Buss fb at frank-buss.de
Sun Aug 5 18:48:02 EDT 2007


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
possible that the integers are automaticly converted to floats?

There are many functions like circle1Center, circle2Center, ... Is it
possible to rewrite the program that it will be shorter, maybe using lists
or an interpreter for a language for this kind of combinator programming
style?

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.

Is there a PNG writer library for Haskell? I've seen a zlib interface,
should be not too difficult to implement it in Haskell itself.

Finally, what do you think about using this concept for generating images?
It has some advantages, e.g. it is possible to scale the image without
quality loss. But it needs some improvement, e.g. the anti-aliasing doesn't
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
a good idea for an interactive interface, like it is implemented in this
program:

http://www.theprodukkt.com/werkkzeug1#28

But this is impossible, if changing one parameter needs so long to update
the image.

-- 
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