03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1 Program 37 1/<br />

predicates<br />

inspiral(integer)<br />

goal<br />

graphics(2,1,0),inspiral(10).<br />

clauses<br />

inspiral(X):forward(SOOO),right(X),Y=X+1,inspiral(Y).<br />

/1 Program 38 1/<br />

predicates<br />

square(integer)<br />

fillsquare(integer)<br />

goal<br />

fillsquare(SOOO).<br />

clauses<br />

square(X) :forward(X),right(90),forward(X),right(90),<br />

forward(X),right(90),forward(X),right(90).<br />

fillsquare(X):-X>10000,!.<br />

fillsquare(X):-square(X),Y=X+SOO,fillsquare(Y).<br />

predicates<br />

goal<br />

clauses<br />

/1 Program 39 1/<br />

circle<br />

circle.<br />

circle:-forward(1000),right(1),circle.<br />

<strong>Turbo</strong> <strong>Prolog</strong>'s graphics can also be used within windows, as illustrated in Program 40.<br />

A window is drawn and a "spotlight" effect (several lines drawn from a fixed point to<br />

fifteen other points) is repeated at five different positions. Another overlapping window<br />

is drawn and five more "spotlights" appear. Finally, a text window is drawn, which<br />

contains an invitation for the user to press the space bar. Each time the space bar is<br />

pressed, one of the windows is removed and the invitation reappears.<br />

Note that text and graphics can be used simultaneously both inside a window and on<br />

the full screen.<br />

/1 Program L;O 1/<br />

domains<br />

list=integer l<br />

predicates<br />

spotlight(integer,integer,integer)<br />

xy(list)<br />

goal undo<br />

graphics(2,0,1),<br />

makewindow(1,7,7,"First",1,1,18,70),<br />

xy([O,0,0,9000,3000,26S00,20100,2L;L;00,201DO,1000J),<br />

makewindow(2,7,7,"Second",10,20,1t;,6D),<br />

xy([O,100D,D,9DOO,O,20DDO,1S0DO,200DD,1S000,100DJ),<br />

Tutorial VI: Graphics and Sound 95

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!