*hd3:Blazin' Forth Documentation,Graphics Support,-#- *cn1;VIC chip Support*cn0 Blazin' Forth contains an extensive implementation of Turtle Graphics which supports all of the graphics modes of the 64, and is also by far the fastest turtle graphics implementation I have ever seen on this computer. I am particularly proud of this aspect of Blazin' Forth, and I hope you get a lot of pleasure out of it. Turtle Graphics was developed by Seymour Papert of MIT as part of his Logo language, and it is an excellent way to explore computer graphics. The Turtle in Turtle Graphics is a graphics cursor, generally shaped like a triangle (shaped like an arrow-head in Blazin' Forth). You control the turtle by telling it to move FORWARD, or BACK , and as it moves, it draws a line. You control the turtles direction by giving it commands like RIGHT or LEFT. You can also use coordinates, through the SETXY command. The graphics screen in Blazin' Forth is 240 turtle steps high ( screen coordinates 0 to 239) and 320 turtle steps wide ( screen coordinates 0 to 319). Wraparound, which is usually part of Turtle Graphics systems, is not implemented, since I think it's preferable to see part of a figure instead of a mess. The lines drawn by the turtle are therefore clipped. It should also be mentioned that the graphics screen does not take any of the memory normally available to Forth due to the intensive use made of the C64's powerful bank switching feature. DRAW Sets up the graphics screen, with the turtle in the center of the screen, pointing straight up. Defaults to SCOLOR and SPLITSCREEN , but these may be changed. It is extremely important that this word (or SCOLOR or DCOLOR) be used at least once before typing any of the other graphics words! FD or FORWARD Takes a number on the stack and moves the turtle forward that distance. Draws a line if the turtles pen is down. Example: 20 FD ( move the turtle 20 turtle steps forward) BK or BACK Takes a number on the stack and moves the turtle back that distance. Draws a line if the pen is down. Example: 20 BK ( move the turtle 20 turtle steps back) RT or RIGHT Takes a number on the stack, and rotates the turtle right that number of degrees. Example: 90 RIGHT ( rotate the turtle 90 degrees to the right) LT or LEFT Takes a number on the stack, and rotates the turtle left that number of degrees. Example: 90 LT ( rotate the turtle 90 degrees to the left) *fp0 SP or SPLITSCREEN Enters SPLITSCREEN mode, with 5 lines of text on the bottom of the screen, and the rest of the screen in graphics mode. This is the default condition. Due to the location of the hires screen, a small amount of flicker may be observed, particularly when the turtle is in the region of the split. This is a hardware limitation over which I have no control. Sorry. FS or FULLSCREEN Exits SPLITSCREEN mode. The entire graphics screen is displayed. Note that if you want to mix music and graphics, you must be in FULLSCREEN mode. This is because both splitscreen mode and the music words are interrupt driven. NOSPLIT This will cause DRAW to default to FULLSCREEN mode. Executing SPLITSCREEN will restore SPLITSCREEN as the default condition. BG or BACKGROUND Takes a number on the stack, and sets the background color of the hires screen to that color. When in splitscreen mode, the border color will also be affected by this command. The number should be between 0 and 15, as described in the programmers reference guide. Example: 1 BG ( sets background to white) PC or PENCOLOR Takes a number on the stack, and sets the pencolor of the turtle to that color. Note that a pencolor of -1 is allowed, and will cause the turtle to erase, instead of draw. Example: 2 PC ( draw in red) PE or PENERASE Causes the turtle to erase instead of draw as it moves. Note that the pen must be down in order to erase. (Or the eraser must be down, in this case.) PU or PENUP Lifts the turtles pen. The turtle may be moved without drawing or eraseing a line. PD or PENDOWN Sets the turtles pen down. The turtle will once again draw a line as it moves. HT or HIDETURTLE Makes the turtle invisible. Note that a pleasant side effect of this is that drawing will become even faster. ST or SHOWTURTLE Makes the turtle visible. SCOLOR Enters single color or HIRES mode. In this mode, all colors are available, but drawing over lines drawn in one color with a line in another color will change a small portion of the previous line to the new color. Lines have a finer, sharper appearance in this mode. Note that executing either SCOLOR or DCOLOR will have the same effect as DRAW - the screen will be cleared, and the turtle moved to its home position. DCOLOR Enters double color mode. In this mode, up to three lines of different colors may share the same area without conflict. Lines are thicker, but the colors are easier to see. Note that when in DCOLOR mode, scrolling of the text screen underneath the draw screen may affect certain of the colors. Since splitscreen mode is usually used only when debugging, this should not be a serious problem. (It's due to the sharing of color memory between the text screen and the hires screen.) Once DCOLOR has been selected, draw will default to this mode until SCOLOR is once again executed. HOME Sends the turtle to its home - center screen, pointing straight up. Note that the turtle will draw a line if the pen is down. (see: WINDOW) SETXY Takes two values from the stack - the X and Y coordinates of a point, and moves the turtle to that location, drawing a line if the pen is down. Example: 100 100 SETXY ( move the turtle to 100 100 ) SETH or SETHEADING Takes a number on the stack which sets the current heading of the turtle. 0 degrees is pointing straight up, with degrees increasing to the right. Example: 90 SETH ( aim turtle at the right of the screen) G$ Takes the address of a text string, and two coordinates. G$ then types the textstring on the graphics screen. The characters are not drawn by the turtle, and so the turtles position and heading are not affected. The only commands which affect both the turtle and G$ are PC ( except -1 PC , which has no effect on G$) and WINDOW. Characters drawn in DCOLOR mode are not very legible, incidentally. Example: " THIS IS A STRING" 100 100 G$ ( type string starting at 100 100) WINDOW ( x1 y1 x2 y2 -- ) Sets up a drawing window for the turtle. Takes four entries from the stack. x1 and y1 are the coordinates of the lower left corner of the drawing window, while x2 and y2 are the coordinates of the upper right hand corner of the drawing window. Executing this command will cause the turtle to center itself inside the window, and, although the turtle can move outside of the window, lines will be drawn only within the window boundary. Note that G$ is also affected by this command. HOME will center the turtle at its new home, but DRAW will reset the window to its maximum. Note that an error occurs if the coordinates passed to WINDOW are outside of the current window. An example of windowing is provided on the source disk. Make sure the disk is mounted, and then type 130 LOAD . RESWIND Calling this word will reset the turtle window to its default condition. This word must be used if you intend to set up multiple windows, since the new window will likely be outside of the old one, and therefore cause an error. Example: : WINDOW1 RESWIND 0 0 50 50 WINDOW ; : WINDOW2 RESWIND 100 100 150 150 WINDOW ; The following are variables which may be accessed to determine the state of the turtle. XCOR YCOR These are system variables which contain the current X coordinate andd Y coordinate of the turtle. Note that these variables should only be used to determine the coordinates of the turtle. Storing values in these variables will have strange effects. If you want to change the turtles position, you should use SETXY . Example: XCOR @ YCOR @ . . ( display the current xy coordinates of the turtle.) HEADING This contains the current heading of the turtle, in degrees. 0 is straight up, increasing to the right. The same caution applies as for XCOR YCOR . If you want to change the turtles heading, use SETH or SETHEADING. Example: HEADING @ . ( print the turtles heading on the screen) PENSTATE True if pen is down. TURTLESTATE True if turtle is visible. Don't be misled by the apparent simplicity of turtle graphics. It is extremely powerful, and allows many remarkable pictures to be drawn, as well as many interesting mathematical explorations to be carried out. It's also a *lot* of fun. As a simple example, here is a word that takes one value from the stack, and draws a square with sides of that length: : SQUARE ( SIDE -- ) 4 0 DO DUP FD 90 RT LOOP DROP ; To try out this word, type DRAW and then 100 SQUARE. A square of 100 turtle units per side will be drawn. This is obviously a simple example, but the power of turtle graphics, combined with the speed and power of Forth, allow amazingly rich and complex graphics displays to be drawn with words that are barely more complex than our SQUARE definition. As another example, here is a word that trues a truly remarkable curve: : C-CURVE ( SIDE LEVEL ) ?DUP 0= IF FD EXIT THEN 2DUP 1- RECURSE 90 RT 2DUP 1- RECURSE 90 LT 2DROP ; This innocent looking definition draws a real whopper of a curve. To try it out, type DRAW, and then issue the following sequence of commands to orient the turtle: 70 BACK CLEARSCREEN FULLSCREEN 90 LEFT 3 10 C-CURVE This type of curve is known as a fractal, which have received a lot of attention recently in the popular press. They have the reputation of being *very* hairy. Note the simplicity of the definition, and note also that Turtle Graphics and recursion are naturals when used together. I hope this brief introduction will encourage you to ex...
Amiga7878