**The Beginner's Page**

C. Regena

**Drawing Lines**

Programming graphics on your computer can be a lot of fun. I enjoy writing graphics programs, but it's a difficult topic to cover in this column because graphics commands differ so greatly from one computer to another. However, this month I'm going to describe some of the point and line drawing commands available on the Amiga, Apple, eight-bit Atari, Atari ST, Commodore 128, and IBM PC/PCjr. Unfortunately, because of BASIC 2.0's lack of graphics commands, these examples do not work on the Commodore 64.

**Plotting Points**

Think of your computer's screen as a coordinate grid, with the origin (coordinate 0,0) in the upper-left corner. When specifying coordinates, the horizontal position (X) comes first, andthe vertical position (Y), second. For example, to plot a pointon the Amiga or IBM, you use the command PSET (10,50), where 10and 50 are the X and Y coordinates, respectively.

The following programs demonstrate point plotting on each machine:

100 REM AMIGA VERSION 110 CLS 120 PSET (20, 50) : PSET (30, 50): PSET (25, 55) 130 FOR X = 22 TO 28 : PSET (X, 58) : NEXT100 REM APPLE VERSION110 HGR : HCOLOR = 3120 HPLOT 20, 50 : HPLOT 30, 50 : HPLOT 25, 55130 FOR X = 22 TO 28 : HPLOT X, 60 : NEXT X100 REM EIGHT-BIT ATARI110 GRAPHICS 8 : COLOR 3120 PLOT 20, 50 : PLOT 30, 50 : PLOT 25, 55130 FOR X = 22 TO 28 : PLOT X, 58 : NEXT X100 REM ATARI ST - ST BASIC110 FULLW 2 : CLEARW 2120 LINEF 20, 50, 20, 50130 LINEF 30, 50, 30, 50140 LINEF 25, 55, 25, 55150 FOR X = 22 TO 28160 LINEF X, 58, X, 58170 NEXT X110 REM 128 VERSION 110 GRAPHIC 1, 1 120 DRAW 1, 20, 50 : DRAW 1, 30, 50 : DRAW 1, 25, 55 130 FOR X = 22 TO 28 : DRAW 1, X, 58 : NEXT X100 REM IBM VERSION110 SCREEN 1 : CLS120 PSET (20, 50) PSET (30, 50) : P SET (25, 55)130 FOR X = 22 TO 28 : PSET (X, 58) : NEXT X

As you can see, each computer has a different method for plotting points: The Amiga and IBM use the PSET command; the Appleplots points with HPLOT; the eight-bit Atari uses PLOT; the Atari ST must plot points by drawing a line to and from the same point using LINEF; and the 128 makes use of a DRAW command whosefirst parameter specifies the color of the point. In each of these versions, line 110 sets up and clears the graphics screen for output.

**Drawing Lines**

In many early versions of BASIC, point-plotting commands were the only way to draw graphics on the screen. This could become quite tedious. Lines had to be drawn using FOR-NEXT loops or DATA statements specifying the points to set. Essentially, every point had to be specified.

Now, most computers have line and circle commands containing many options, so you can draw much more quickly. Here's a short example of the line-drawing commands for all six computers:

100 REM AMIGA VERSION110 CLS120 X1 = 20 : Y1 = 50 : X2 = 100 : Y2 = 75130 LINE (X1, Y1) - (X2, Y2)140 X2 = 55 : Y2 = 80150 LINE -(X2, Y2)100 REM APPLE VERSION110 HGR : HCOLOR = 3120 X1 = 20 : Y1 = 50 : X2 = 100 : Y2 = 75130 HPLOT X1, Y1 TO X2, Y2140 X2 = 55 : Y2 = 80150 HPLOT TO X2, Y2100 REM EIGHT-BIT ATARI110 GRAPHICS 8 : COLOR 3120 X1 = 20 : Y1 = 50 : X2 = 100 : Y2 = 75130 PLOT X1, Y1 : DRAWTO X2, Y2140 X2 = 55 : Y2 = 80150 DRAWTO X2, Y2100 REM ATARI ST - ST BASIC120 FULLW 2 : CLEARW 2130 X1 = 20 : Yl = 50 : X2 = 100 : Y2 = 75140 LINEF X1, Y1, X2, Y2150 X1 = X2 : Y1 = Y2160 X2 = 55 : Y2 = 80170 LINEF X1, Y1, X2, Y2100 REM 128 VERSION 110 GRAPHIC 1, 1 120 X1 = 20 : Y1 = 50 : X2 = 100 : Y2 = 75 130 DRAW 1, X1, Y1 TO X2, Y2 150 X2 =55 : Y2 = 80 160 DRAW 1 TO X2, Y2100 REM IBM VERSION110 SCREEN 1 : CLS120 X1 = 20 : Y1 = 50: X2 = 100 : Y2 = 75130 LINE (X1, Y1)-(X2, Y2)140 X2 = 55 : Y2 = 80160 LINE -(X2, Y2)

In each case, X1 and Y1 specify the starting point of a line, while X2 and Y2 specify the end point. Notice line 160: Here we draw a line from the last point plotted (100,75) to coordinate X2, Y2.

If you have a lot of lines to draw, you may want to use a DATA statement system. For example, add the following lines to the program above, replacing lines where necessary:

120 READ N, X1, Y1, X2, Y2135 FOR C = 1 TO N140 READ X2, Y2170 NEXT C180 DATA 22, 38, 118, 42, 122190 DATA 46, 116, 35, 36, 38, 28, 42, 26, 45, 30, 44, 40200 DATA 36, 54, 20, 75, 17, 84, 19, 95, 24, 102, 32, 106210 DATA 50, 106, 58, 100, 62, 94, 61, 86, 58, 80, 52, 76220 DATA 40, 76, 32, 82, 30, 88, 32, 98

The first READ statement in Line 120 reads N for the number of points to be used in the loop, and then X1 and Y1 for the first point and X2 and Y2 for the second point. Lines 140–170 set up a FOR-NEXT loop that for N times reads two numbers for the coordinates of a point (X2, Y2) and draws a line to that point. I shortened the DATA statements so they would be easier for you to read, but you can put as many numbers as possible in your DATA statements and, thus, use fewer statements (and less memory). If you copy these data numbers correctly, you'll see a treble clef.

Besides points and lines, most computers offer box and circle commands as well. There are also commands that allow you to fill or paint the shapes that you have drawn. The best way to learn these commands is to sit down with your computer's manual and experiment. Who knows what you may come up with.