PROLOG TURTLE GRAPHICS Contributed by Salleh Mustaffa, University of Manchester Received on the 17th of November 1987 Shelved on the 6th of December 1987 Amended on the 17th Of December 1987 Copyright (c) 1987 by David Lau-Kee, Univ. of York. Permission is granted to use or modify this code provided this notice is included in all complete or partial copies. I enclose a turtle graphics program written by David Lau-Kee. It came from a posting to the Prolog Digest some months ago. It had a few syntactic errors which I have corrected. The program is said to be terminal specific and probably works best on a colour VT-100 terminal, but I've only been able to see it in action on a monochrome VT-100. I have not been able to get it to work properly on a Sun terminal (even after hours of flipping through the ANSII manuals for the Sun). I think it is also Unix specific, but I may be wrong. I suspect the initial errors that I had to contend with initially are due to the control characters in the program which are not properly transmitted in the mail. [Salleh Mustaffa] The basic idea came from a colleague's thought that it would be useful to be able to show the progress of instantiations in a goal. To be really useful there needs to be some means of "unshowing" the partial groundings, so that the display is always consistent with a snapshot of the state of the system. Really this program is only an experiment on that concept. It has *lots* of rough edges and *lots* of nasty constructs... However, it does provide an interesting way of "watching" Prolog at work. A much reduced "turtle graphics" environment is presented. (Basically you can tell the turtle to turn 90 deg. clockwise or anticlockwise, and to move forward X steps.) The "interesting" feature is that backtracking over these primitives results in them being undone. For example, I have defined anysq(X) to be four sets of 'forward X steps, turn'. If I try to satisfy 'anysq(4), fail.' then all the possible solutions to: 'anysq(4).', where 'forward (drawing) X' and 'backward (erasing) X' satisfy the goal 'forward X', and 'turn clockwise' and 'turn anticlockwise' satisfy 'turn' are drawn. I wrote the program for C-Prolog 1.5, but it wouldn't require much effort to move it to other Prologs. It *is* terminal specific - I use a Microcolour m2200 in ANSII mode (basically vt100 plus colour) - but again, if your terminal has ANSII features, it won't be a problem to hack it straight. One thing may be worth thinking about: When a line is undrawn it is sometimes helpful to leave a record of it. I cope with this by switching the undo colour from black to white. This is ok on a colour terminal where the lines themselves are other than white, but it would be a bit confusing in monochrome... maybe half-intensity or something? The program is slower than it really needs to be. Previously the undo would act like paint stripper, cutting right down to the black of the background. This version paints in layers, undoing strips off a layer. (Great if you've got a lot of colours.) For a 5-fold speed increase take out the layers. [David Lau-Kee] I've reformatted the program, changed % comments to /* .. */, and made a few other syntactic changes. [JNP] SIZE : 18 kilobytes. CHECKED ON EDINBURGH-COMPATIBLE (POPLOG) PROLOG : yes. Doesn't use any non-standard predicates, but won't run on our (VT100) terminals. However, the appearance of the screen is almost correct - small changes to the terminal-handling predicates should make it work. PORTABILITY : the cursor-moving commands are terminal-specific. INTERNAL DOCUMENTATION : The cursor-addressing predicates carry very brief descriptions of what they're supposed to do.