This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Making xfig drawings with scheme


Hi Dirk

I've used guile to draw some figures for a mathematician.  I had to do a lot 
of stuff with conics in strange positions and ordinary graphing packages 
didn't seem up to it.  So I threw this together (in a hurry - and I suspect my 
scheme skills have improved since I wrote it, but it works.)  You can get it 
from

     http://www.cl.cam.ac.uk/~ig206/guile-fig.tar.gz

It creates xfig drawings.  The test.scm example shoes how.  The following 
creates an xfig drawing in a file called test.fig in the current directory.  
The drawing is a black triangle with a 45 degree hatching and a thick 
perimeter.  Then there are two lines, one red and slightly thinner than the 
perimeter of the triangle, then another blue one that's the same width as the 
perimeter of the triangle.  Finally it draws a black circle with a thin dashed 
outline. (fig 'close) writes the file.

The depth (as in SET-DEPTH!) is used to control the layering of primitives in 
the final drawing in the obvious way.

See fig.scm to find out other commands.

(load "fig.scm")
(load "streams.scm")
(define fig (make-new-figure "test.fig"))
(fig 'set-pen-colour! 'black)
(fig 'set-line-width! 3)
(fig 'set-fill-style! 'patterned 45)
(fig 'move-to '(1200 . 1200))
(fig 'line-to '(2400 . 1200))
(fig 'line-to '(1800 . 1800))
(fig 'close-poly-path)
(fig 'set-pen-colour! 'red)
(fig 'set-line-width! 2)
(fig 'set-depth! 10)
(fig 'move-to '(1200 . 2400))
(fig 'line-to '(2400 . 2400))
(fig 'close-path)
(fig 'set-pen-colour! 'blue)
(fig 'set-line-width! 3)
(fig 'set-depth! 20)
(fig 'move-to '(1200 . 3600))
(fig 'line-to '(2400 . 3600))
(fig 'close-path)
(fig 'set-depth! 0)
(fig 'set-line-width! 1)
(fig 'set-line-style! 'dashed)
(fig 'set-dash-dot-ratio! 3.000)
(fig 'circle '(3600 . 1200) 600)
(fig 'close)

-- 
Ian Grant, Computer Lab., New Museums Site, Pembroke Street, Cambridge
Phone: +44 1223 334420          Personal e-mail: iang at pobox dot com 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]