home *** CD-ROM | disk | FTP | other *** search
Prolog Source | 1986-10-07 | 1.8 KB | 54 lines |
- /* Program 34 */
- /*
- NOTE: all graphics programs are in white on a
- black background. If you don't like this
- combination it can easily be changed. You can
- change the parameters to the 'graphics'
- predicate, or you can change the drawing
- color. Read page 92 and try some combinations
- of parameters. For example: graphics(1,5,17)
- on a CGA will give you pink letters and a
- white line on a blue background. Other systems
- give different colors. Just explore.
- */
-
- domains
- intege = reference integer
-
- predicates
- move(char,intege,intege,intege,intege)
- start
- changestate(intege,intege)
-
- goal
- start.
-
- clauses
- start:-
- makewindow(1,7,7,"directions to turtle",0,0,24,80),
- write(" Use the letters: u to move up"),nl,
- write(" d to move down"),nl,
- write(" r to move right"),nl,
- write(" l to move left"),nl,
- write(" Press <CTRL><BREAK> when done."),
- write("\n\n Press any key to continue"),
- readchar(_),
- graphics(1,1,0),
- line(1000,1000,1000,31000,7),
- line(1000,31000,31000,31000,7),
- line(31000,31000,31000,1000,7),
- line(31000,1000,1000,1000,7),
- changestate(15000,15000).
- changestate(X,Y):-
- readchar(Z),move(Z,X,Y,X1,Y1),changestate(X1,Y1).
- move('r',X,31000,X,31000):- !.
- move('r',X,Yold,X,Ynew):- !,Ynew=Yold+100,dot(X,Yold,3).
- move('l',X,1000,X,1000):- !.
- move('l',X,Yold,X,Ynew):- !,Ynew=Yold-100,dot(X,Yold,3).
- move('u',1000,Y,1000,Y):- !.
- move('u',Xold,Y,Xnew,Y):- !,Xnew=Xold-100,dot(Xold,Y,3).
- move('d',31000,Y,31000,Y):- !.
- move('d',Xold,Y,Xnew,Y):- !,Xnew=Xold+100,dot(Xold,Y,3).
- move('*',_,_,_,_):- !,exit.
- move(_,X,Y,X,Y).
-