formerly known as Gif writer
Jan Skibinski, Numeric Quest Inc.
Initialized: 1998.09.17, last modified: 2000.03.24
This tool has been mainly designed to generate simple plots from within Haskell programs. But you can use it for other reasons too, although there is not much high level support as yet for such things as transformation and projection of 3D entities.
Current version can accept as input one of four graphic file formats: JPEG, PNG, XPM or XBM but produces output only in one of the two formats: PNG or JPEG.
Here is one such an example, stored in PNG format
And here is Haskell code for making the above picture:
plotting_example :: IO () plotting_example = waveforms [g 15 10, g 10 20, g 5 40] -- functions to plot [0.006,0.008..0.084] -- abscissas [pen1, pen2, pen3] -- pens (500, 200) -- width and height of gd image ["Time","s","Accel","m/s^2"] -- description of axes "Three sine functions" -- title "plot.png" -- destination file where pen1 = Pen Standard 6 1 -- solid line, color 6, thickness 1 pen2 = Pen Standard 8 2 pen3 = Pen Standard 11 4 g a f t = -- -- Example: function to plot -- a * sin (2 * pi * f * t)
And here is another simple example, saved in JPEG format:
Module GD.hs provides simple interface to relatively small C library gd, which is available at www.boutell.com/gd/.
A quote from the GD library page:
gd is a graphic library. It allows your code to quickly draw images complete with lines, arcs, text, multiple colors, cut and paste from other images, and flood fills, and write out the result as a PNG or JPEG file. This is particularly useful in World Wide Web applications, where PNG and JPEG are two of the formats accepted for inline images by most browsers.
Why not GIF? As an explanation, here is another quote from the same page:
Please do not ask us to send you the old GIF version of GD. Unisys holds a patent on LZW compression algorithm, which is used in fully compressed GIF images. The best solution is to move to legally unencumbered, well-compressed, modern image formats such as PNG and JPEG as soon as possible.
Accordingly, one and half year after our first release of Haskell module Gif, we have remade it and renamed it as the Haskell module GD. While being at it we also improved it a bit: several data types have been added to simplify and clarify the signatures, and we have added a support for lines styles and some form of brushing.
The interface to GD library is write-only, so only a subset of its functionality is implemented here. We cannot query the library driver, so anything query-based is out of reach here.
A note for readers not familiar with Haskell: Do not get a wrong impression about Haskell's capability here. Haskell can cooperate with C without restrictions using GreenCard or Foreign Function Interface mechanisms.
Secondly, we have chosen to support only a minimal subset of GD functionality -- just to be able to handle simple plots with text. No copying, tiling, no more than one picture a time, etc. These can be easily added if needed.
Haskell commands are written to an interface file, which is then parsed and executed by our C driver program. You need to compile the driver yourself and for this you also need the C header files from Gd library distribution. And of course the library itself.
Three files that make the entire Haskell GD package are available here (http://www.numeric-quest.com/haskell/GD/):
They are not compressed, so you can peruse them on line if you wish.
Our family of functional PDF writers Fun->pdf
See also Advanced Programming