Displaying Text and Graphics / 9

Sample Program:

This procedure makes the working area in a window progressively smaller, filling each area with a different color. It then changes the areas' colors rapidly to produce a hypnotic effect.

PROCEDURE hypnobox
[]DIM X,Y,X1 ,Y1 ,T,R,COLOR: INTEGER
[]DIM KEY:STRING[1
OK EY=""
OX=3 \Y=1
OX1 =80-CX+X) \Y1 =24-CY+Y)
[]FOR T=O TO 1 0
ORUN GFX2C"COLOR",3,T)
[]RUN GFX2C"CLEAR")
ORUN GFX2C"CWAREA",X,Y,X1 ,Y1 )
OX=X+3 \Y=Y+1
OX1 =80-CX+X) \Y1 =24-CY+Y)
[]NEXT T
ORUN GFX2C"COLOR",3,2)
OWHILE KEY="" DO
[]RUN INKEYCKEY)
OFOR T=1 TO 16
[]R=RNDC65)
ORUN GFX2C"PALETTE",T,R)
[]NEXT T
[]ENDWHILE
ORUN GFX2C"DEFCOL")
ORUN GFX2C"CWAREA",0,0,80,24)
[]END

9-77
BASIC09 Reference

DEFBUFF Define GET/PUT buffer

Syntax: RUN GFX 2("DE FBUFF",group, buffer,size)

Function: Defines a buffer for GET/PUT operations.

When you define a buffer, you do so by group number and buffer number. Each group you define allocates eight kilobytes of memory. The system needs 30 bytes of the block for overhead, leaving 8162 bytes free. Within the group, you can allocate one or more buffers. Select a group number and a buffer number as indicated in the following "Parameters" section. Use these numbers in future references to the buffer.


A GET/PUT buffer remains allocated until you use the KILLBUFF function to remove it from your system's memory. For more information on Get/Put buffers, see KILLBUFF, PUT, GET, and GPLOAD.


Parameters:
group A number you select in the range 1-199.
buffer A number (in the range 1-255) that you
assign to the buffer you create.
size The size of the buffer, in the range of 1 to
8192 bytes, depending on available memory in
its group.
Notes:

One method of selecting a group number is to use SYSCALL and the Get ID (103F OC) system call to obtain your user's process ID number. Then, use this ID number as a group number. Using this system for all GET/PUT buffer operations, ensures against group number overlapping. See the SYS-


CALL command for more information. I-N

Examples:

RUN GFX2C"DEFBUFF",1,5,4000H0)

9-78


DEFCOL Set default colors

Syntax: RUN GFX2([path,]"DEFCOL")

Function: Sets the palette registers back to their default values. The- type of monitor you have determines the actual hues. See "The Palette" and Table 9.7 earlier in this section.

Parameters:



Examples:

RUN GFX2C"DEFCOL")

9-79
BASIC09 Reference

DELLINDelete current line of text

Syntax: RUN GFX2([path,]"DELLIN")

Function: Deletes the line on which the cursor is resting and closes the space. DELLIN operates on both text and graphics screens.

Parameters:
path The route to the window in which you want to
delete a line.
Examples:



Sample Program:

This procedure draws a series of various colored concentric circles, then produces a lemon shape by removing slices of the circle with DELLIN.

PROCEDURE slice ODIM X,Y,R,T,COLOR:INTEGER ORUN GFX2("CLEAR") OCOLOR=0 OX = 32 0 OY=96 OFOR T-18S TO 1 0 STEP -1 0 ORUN GFX2("CIRCLE",X,Y,T) ONEXT T OFOR T=140 TO 320 STEP 10 ORUN GFX2("COLOR",COLOR) ORUN GFX2("FILL",T,96) OCOLOR=COLOR+1 ONEXT T ORUN GFX2("CURXY",0,8) OFOR T=1 TO 8 ORUN GFX2("DELLIN") ONEXT T ORUN GFX2("COLOR",3,2) []END

9-80
Displaying Text and Graphics / 9

DRAW Draw a polyline figure

Options:

Nnum

Snum
Enum
W num
NEnum
NW num
SEnum
SW num
AUal

Syntax: RUN GFX2([path,]"DRAW", option list)

Function: Draws in the directions specified, and for the distances specified, in an option list. The option list is a string of characters and numbers. You can separate options with spaces or commas. You must include commas between the two coordinates for the B and U options.

Parameters:

path The route to the window in which you want to
draw.
option list A string consisting of one or more of the fol
lowing options:

draws north (up) num units.
draws south (down) num units.
draws east (right) num units.
draws west (left) num units.
draws northeast (up and right) num units.
draws northwest (up and left) num units.
draws southeast (down and right) num units.
draws southwest (down and left) num units.
rotates the draw axis. Possible values are:
0 = normal
1 = 90 degrees
2 = 180 degrees
3 = 270 degrees

Uxcor,ycor draws a relative vector to the specified coordi
nates. Xcor and ycor are relative to the cur
rent draw pointer position. The draw pointer
location does not change. Xcor and ycor must
be separated by a comma.

9-81
BASIC09 Reference

Bxcor,ycor produces a blank line (moves the cursor but
does not draw). The xcor and ycor coordinates
are relative to the current draw pointer loca
tion. If you specify relative coordinates located
offscreen, you cannot see subsequent lines.
Examples:

RUN GFX2("DRAW","N10,E10,S10,W10")

Sample Program:

PROCEDURE drawing ODIM T,X,Y,COLOR:INTEGER OCOLOR=0 ORUN GFX2("CLEAR") OFOR T=1 TO 96 STEP 6 ORUN GFX2("SETDPTR",320,96) OFOR Y=0 TO 3 OCOLOR=MOD(Y,2) ORUN GFX2("COLOR",COLOR) OFOR X=1 TO 4 OREAD DR$ ODR$="A"+STR$(Y)+DR$+STR$(T) ORUN GFX2("DRAW",DR$) ONEXT X ONEXT Y ORESTORE ONEXT T ORUN GFX2("COLOR",3) OEND ODATA 1IN11 , 11E-I , -IS" , "Wil

9-82


DRAW Draw a polyline figure

Syntax: RUN GFX2([path,]"DRAW",option list)

Function: Draws in the directions specified, and for the distances specified, in an option list. The option list is a string of characters and numbers. You can separate options with spaces or commas. You must include commas between the two coordinates for the B and U options.

Parameters:

path The route to the window in which you want to
draw.
option list A string consisting of one or more of the fol
lowing options:
Options:
Nnum draws north (up) num units.
Snum draws south (down) num units.
Enum draws east (right) num units.
W num draws west (left) num units.
NEnum draws northeast (up and right) num units.
NW num draws northwest (up and left) num units.
SEnum draws southeast (down and right) num units.
SW num draws southwest (down and left) num units.
Aval rotates the draw axis. Possible values are:
0 = normal
1 = 90 degrees
2 = 180 degrees
3 = 270 degrees
Uxcor,ycor draws a relative vector to the specified coordi
nates. Xcor and ycor are relative to the cur
rent draw pointer position. The draw pointer
location does not change. Xcor and ycor must
be separated by a comma.

9-81
BASIC09 Reference

Bxcor,ycor produces a blank line (moves the cursor but
does not draw). The xcor and ycor coordinates
are relative to the current draw pointer loca
tion. If you specify relative coordinates located
offscreen, you cannot see subsequent lines.
Examples:

RUN GFX2("DRAW","N10,E10,S10,W10")

Sample Program:

PROCEDURE drawing ODIM T,X,Y,COLOR:INTEGER pCOLOR=0 ORUN GFX2("CLEAR") OFOR T=1 TO 96 STEP 6 pRUN GFX2("SETDPTR",320,96) OFOR Y=0 TO 3 OCOLOR=MOD(Y,2) ORUN GFX2("COLOR",COLOR) pFOR X=1 TO 4 DREAD DR$ pDR$="A"+STR$(Y)+DR$+STR$(T) pRUN GFX2("DRAW",DR$) pNEXT X ONEXT Y ORESTORE pNEXT T ORUN GFX2("COLOR",3) pEND pDATA 'IN" 7 "Ell 7 "S" , "W"

9-82











,.-- Examples:






PROCEDURE decorate pDIM PATH,T,Y:INTEGER DOPEN PATH,"/W3":WRITE ORUN GFX2CPATH,"DWSET",7,0,0,80,24,3,2,2) ORUN GFX2CPATH,"SELECT") DY =1 ORUN GFX2CPATH,"COLOR",3,2) OFOR T=1 TO 185 STEP 3 DY=Y+1 ORUN GFX2CPATH,"ELLIPSE",320,96,T,Y) ONEXT T ORUN GFX2CPATH,"COLOR",1,2) OFOR T=18S TO 1 STEP -6


BASIC09 Reference

ORUN GFX2CPATH,"ELLIPSE",320,96,T,Y) pIF INTCT/3)=T/3 THEN pY=Y+1 pENDIF ONEXT T pRUN GFX2(1,"SELECT") ORUN GFX2CPATH,"DWEND") pCLOSE #PATH OEND

84
                Displaying Text and Graphics l 9


DWPROTSWDevice window protect switch

Syntax: RUN GFX2([path,]"DWPROTSW","switch")

Function: Lets you unprotect one device window and set other device windows on top of it.

OS-9 on the Color Computer 3 normally uses a protected windowing system that does not allow window devices to overlap. Removing the window protection with DWPROTSW lets one device window exist on the same screen area as another window device. Because this might destroy the contents of an unprotected window, you need to use care with this function.

Parameters:
path The route to the window you want to
unprotect.
switch Either OFF to turn off protection, or ON to
turn on protection. The default is ON.
Examples:

RUN GFX2("DWPROTSW",OFF)

9-85
BASIC09 Reference

DWSET Device window set

Syntax: RUN GFX2([path,]"DWSET",forma4xcorycor,
width,length,foreground, background, border)

Function: Defines a device window. Normally, you first open a path to a window, then use DWSET to set the window format, location, size, and colors.

Parameters:
path The route to the window you are defining.
format The code for the type of screen you want to
establish. See Table 9.6 at the beginning of
this section for the formats available.
xcor,ycor The coordinates (character column and row) of
the upper left corner of the screen you want to
create.
width The width (in characters) of the new window.
length The depth (in lines) of the new window.
foreground The code for the window's foreground color.
background The code for the window's background color.
border The code for the window's border color.

Examples:

RUN GFX2("DWSET",06,50,100,50,10,20,12,9)

Sample Program:

This procedure opens a path to Window 3, uses DWSET to define the new window, displays the new window, and draws a graphic lemon shape. It then uses SELECT to return to the /TERM window or screen, deallocates Window 3, and closes the path.

9-86
        Displaying Text and Graphics l 9


PROCEDURE lemon
pDIM PATH,T,X,Y:INTEGER
OOPEN #PATH,"/W3":WRITE
ORUN GFX2CPATH,"DWSET",7,0,0,80,24,3,2,2)
ORUN GFX2CPATH,"SELECT")
DY =1
ORUN GFX2CPATH,"COLOR",0,2)
OFOR T=1 TO 185 STEP 3
OY=Y+1
ORUN GFX2CPATH,"ELLIPSE",320,96,T,Y)
ONEXT T
OX =T
ORUN GFX2CPATH,"COLOR",3,2)
OFOR T=62 TO 1 STEP -3
ORUN GFX2CPATH,"ELLIPSE",320,96,X,T)
OIF INTCT/3)=T/3 THEN
OX=X+1
REND I F
ONEXT T
ORUN GFX2(1,"SELECT")
O R U N G F X 2 C P A T H , "D W E N D" )
OCLOSE #PATH
REND

9-87
BASIC09 Reference

ELLIPSE Draw an ellipse

        Syntax: RUN GFX2([path,]"ELLIPSE"[,xcorycor], xrad, grad)


Function: Draws an ellipse with the center at the current draw pointer position or at the specified X,Y coordinates. The X coordinates are in the range 0-639. The Y coordinates are in the range 0-191.

Parameters:

path The route to the window in which you want to
draw.
xcor,ycor The coordinates for the ellipse's center. If you
omit these coordinates, ELLIPSE uses the
current draw pointer position.
xrad,yrad The radii of the ellipse's length and height.

Examples:

RUN GFX2("ELLIPSE",100,50)

RUN GFX2("ELLIPSE",100,125,100,10)

Sample Program:

This program uses ELLIPSE to draw a graphic design shaped like a Christmas tree decoration.

PROCEDURE xbulb
ODIM T,Y:INTEGER
Ely =1
ORUN GFX2("COLOR",3,2)
ORUN GFX2("CLEAR")
pFOR T=1 TO 180 STEP 3
OY=Y+1
pRUN GFX2("ELLIPSE",320,96,T,Y)
ONE XT T
ORUN GFX2("COLOR",1,2)
OFOR T=180 TO 1 STEP -6

9-88
              Displaying Text and Graphics / 9


RUN GFX2C"ELLIPSE",320,96,T,Y)
pIF INTCT/3)=T/3 THEN
Ely =Y+1
pEND I F
ONEXT T
ORUN GFX2C"COLOR",3,2)
SEND

9-89
BASIC09 Reference

EREOLINE Erase to end of line

Syntax: RUN GFX2([pa th,]"E RE OLINE ")

Function: Deletes the portion of the current line from the cursor to the right side of the window.

Parameters:

          path The route to the window in which you want to erase a portion of a line.


Examples:

RUN GFX2("EREOLINE")

Sample Program:

This procedure uses EREOLINE to produce a series of steps down the screen.

PROCEDURE steps ODIM T,J,K:INTEGER
RUN GFX2("COLOR",2,3)
ORUN GFX2("CLEAR")
ORUN GFX2("COLOR",3,2)
OFOR T=0 TO 22
OJ=T*3
ORUN GFX2("CURXY",J,T)
ORUN GFX2("EREOLINE")
ONEXT T

w
Displaying Text and Graphics l 9

EREOWNDWErase to end of window

Syntax: RUN GFX2([path,]"EREOWNDW")

Function: Deletes all the lines in a window from the line on

which the cursor is positioned to the bottom of the window.


Parameters:

          path The route to the window in which you want to delete screen contents.


Examples:

RUN GFX2C"EREOWNDW")

9-91
BASIC09 Reference

ERLINE Delete current line of text

Syntax: RUN GFX2([path,]"E RLINE ")

Function: Deletes the current line (on which the cursor is resting) from the window but does not close the space.

Parameters:

          path The route to the window in which you want to remove the contents of a screen line.


Examples:

RUN GFX2("ERLINE")

Sample Program:

This procedure draws a bull's-eye design, then slices it with the ERLINE function.

PROCEDURE cut
ODIM X,Y,R,T,COLOR:INTEGER
OCOLOR=0
OX=320
OY=96
ORUN GFX2("CLEAR")
OCOLOR=0
OFOR T=185 TO 10 STEP -10
ORUN GFX2("CIRCLE",X,Y,T)
ONEXT T
OFOR T=140 TO 320 STEP 10
ORUN GFX2("COLOR",COLOR)
[]RUN GFX2("FILL",T,96)
[]COLOR=COLOR+ 1
ONEXT T
OFOR T=2 TO 22 STEP 2
ORUN GFX2("CURXY",O,T)
ORUN GFX2("ERLINE")
ONEXT T
ORUN GFX2("COLOR",3,2)
REND

9-92
                Displaying Text and Graphics l 9


FILL Fill (paint) window

      Syntax: RUN GFX2([path,]"FILL",[xcorycor])


      Function: Paints an area with the current foreground color. Paint fills the portion of the window that is the same color as the pixel under the draw pointer.


      Parameters:


path The route to the window in which you want to
use the FILL function.
xcor,ycor Are optional X- and Y-coordinates to reposi
tion the draw pointer before FILL begins. If
you omit these coordinates, BASIC09 uses the
current draw position.
"°' ~Examples:

      RUN GFX2("FILL",100,100)


      Sample Program:


      This procedure draws and fills 100 boxes on a window.


      PROCEDURE colorbox

      ODIM A,B,C,D,T,COLOR:INTEGER

      OCOLOR=0

      ORUN GFX2("CLEAR")

      OFOR T=1 TO 1 0 0

      DA=RND(SG0)

      OB=RND(1 51

      OC=A+RND(80)

      OD=B+RND(40) -

      OCOLOR=COLOR+ 1

      ORUN GFX2("COLOR",COLOR)

      ORUN GFX2("BOX",A,B,C,D)

      ORUN GFX2("FILL",A+1 ,B+1

      ONEXT T


                                    9-93

BASIC09 Reference

FONT Define font buffer

Syntax: RUN GFX2([path,]"FONT",group, buffer)

Function: Defines a buffer from which BASIC09 gets the character font (style) for the current screen. Use the text/cursor handling functions referenced in this section with the font you load. When you merge the Stdfonts file in your SYS directory with a graphics window, you have the choice of three fonts from Buffers 1, 2, and 3, located in Group 200. You can also create your own fonts. FONT works only on graphics screen. See "Using Fonts" earlier in this chapter.


You must load the font you want to use into the defined buffer before using FONT.


Parameters:

path

group

buffer

Examples:

The route to the window in which you want to use an alternate font.

The group number of the buffer containing the font to use.

The number of the buffer containing the font to use.

RUN GFX2C"FONT",200,2)

9-94
Displaying Text and Graphics / 9

GCSET Set graphics cursor

Syntax: RUN GFX2("GC SET",group, buffer)

Function: Defines a buffer from which BASIC09 gets the graphics cursor. This lets you define your own cursor for graphics operations. To turn the graphics cursor off, use a group Number 0. You must execute this command to display a graphics cursor. Before using GCSET, you must merge the Stdcur file in the SYS directory to the window.


Parameters:

group

buffer

Examples:

RUN GFX2C"GCSET",1,5)

The group number of the buffer containing the cursor image to use. See OS-9 Windowing System for information on the group to use.


The number of the buffer that contains the cursor image to use. See OS-9 Windowing System for information on the buffer to use.


9-95
BASIC09 Reference

GET Get a block from the window

        Syntax: RUN GFX2([path,]"GET",g*roupbufferxcor, ycor,xsize,ysize)


Function: Saves a window area Get/Put buffer. Use PUT to replace the image to the window. If you did not previously define the buffer, BASIC09 creates it. If you store the window data in a predefined buffer, the data must be the same size or smaller than the buffer. If not, BASIC09 truncates the data to the size of the buffer. (Also see PUT and DEFBUFF.)


Parameters:

path The route to the window where you want to
save an image.
group The group number of the Get buffer (1-199).
buffer The Get buffer number (1-255).
XCor'YCor The X- and Y-coordinates of the upper left cor
ner of the window image to save. The X
coordinates are in the range 0-639. The Y
coordinates are in the range 0-191.
xsize The horizontal size of the window section to
save.
ysize The vertical size of the window section to save.

Examples:

RUN GFX2C-GET--,1,5,0,0,10,1S)

9-96
                Displaying Text and Graphics l 9


Sample Program:

This procedure draws a character, loads it into a buffer, then repeatedly replaces the character to the window screen using PUT. Each new image erases the previous image, giving an impression of animation.

PROCEDURE puttdown
DIM T,J:INTEGER
RUN GFX2C"CLEAR")
ORUN GFX2C"ELLIPSE",320,96,12,4)
pRUN GFX2C"CIRCLE",320,90,5)
ORUN GFX2C"COLOR", 1 )
pRUN GFX2C"FILL",320,96)
RUN GFX2C"COLOR",3)
RUN GFX2C"FILL",320,90)
pRUN GFX2C"HAR",305,100,335,104)
RUN GFX2C"GET",1 ,1 ,288,85,50,23)
pRUN GFX2C"GET",1 ,2,1 ,1 ,50,23)
RUN GFX2C"PUT",1,2,288,85)
DJ =1 0
pFOR T=20 TO 559 STEP 6
DJ=J+2
pRUN GFX2C"PUT",1 , 1 ,T, J)
NEXT T
RUN GFX2C"KILLHUFF",1 ,1 )
ORUN GFX2C"CURON")
SEND

9-97
BASIC09 Reference

GPLOAD Load data unto Get/Put buffer

        Syntax: RUN GFX2("GPLOAD",group, buffer,forma 4 xdim, ydim, size)


Function: Loads a buffer with image data that PUTBLK can use for window displays. If the Get/Put buffer is not created, BASIC09 creates it. If it is defined, the size of the data should not be larger than the buffer.

Parameters:
group The group number you select, in the range 1
199, to let you group buffers.
buffer A number in the range 1-255 that you assign
to the buffer you create.
format The type code of the screen format. (See Table
9.4. )
xdim The X (horizontal) dimension of the stored
block.
ydim The Y (vertical) dimension of the stored block.
size The size of the buffer in bytes. A buffer size
can be in the range of 1 to 8 kilobytes,
depending on available memory.
Examples:

RUN GFX2("DEFBUFF",1,5,06,100,50,5000)

9-98
                Displaying Text and Graphics l 9


INSLIN Insert line

Syntax: RUN GFX2([path,]"INSLIN")

Function: Moves the window lines at and below the cursor down one line.

Parameters:
path The route to the window in which you want a
blank line.
Examples:

RUN GFX2("INSLIN")

Sample Program:

This procedure draws a round face on the screen, then uses INSLIN and DELLIN to make a mouth appear to move.

PROCEDURE chomp
ODIM X,Y,T:INTEGER
OD I M RESPONSE :STRING [ 1 J
aRESPONSE=""
ORUN GFX2("CLEAR")
pRUN GFX2("CIRCLE",320,96,80)
ORUN GFX2("COLOR",0,2)
pRUN GFX2("FILL",320,96)
ORUN GFX2("COLOR",2)
ORUN GFX2("CIRCLE",285,80,12)
ORUN GFX2("CIRCLE",355,80,12)
ORUN GFX2("FILL",285,80)
ORUN GFX2("FILL",355,80)
ORUN GFX2("CIRCLE",315,96,3)
ORUN GFX2("CIRCLE",325,96,3)
ORUN GFX2("ARC",320,92,14,3,3,1 ,1 ,1 )
ORUN GFX2("COLOR",3,2)
ORUN GFX2("CIRCLE",289,77,3)
ORUN GFX2("CIRCLE",359,77,3)
ORUN GFX2("CURXY",0,14)
DREPEAT

                                9-99

BASIC09 Reference

ORUN GFX2C"INSLIN")
OFOR X=1 TO 1 00
ONEXT X
ORUN GFX2C"DELLIN")
ORUN INKEYCRESPONSE)
OUNTIL RESPONSE""
OEND

9-100