G007 Example Programs

Example 1. Drawing Circles.

This demonstrates several forms of plotting.

 10 REM CIRCLES
 20 LET D = 0.099
 30 LET X = 90
 40 LET Y = 0
 50 CLS 2               set hi-res
 60 SLOW 4
 70 PLOT 130,127,95     move origin to centre
 80 PLOT 12,X,Y         initialise plot positions
 90 PLOT 12,X,Y
100 FOR I = 0 TO 63
110 LET X = X + D * Y   calculate next x, y
120 LET Y = Y - D * X
130 PLOT 10,X,Y+X*D/2   plots the point
140 NEXT I

This plots a circle of black pixels. Changing the plot number from 10 will draw and fill the circle. Before altering the program, return to low-res mode using the command SLOW.

Try changing the plot number from 10 to 2. This will draw the circle as a series of straight lines. Now change line 30 to LET X = 130 and notice how the lines are quite happily drawn to points off screen.

Change line 30 back to LET X = 90 then try the following plot numbers in line 130: 34, 66, 98 and 18. With other plot numbers in line 130, the program will fill the circle.

Try each of the following plot numbers: 58, 59 and 60. Note how the triangles are drawn with a common vertex. PLOT 59 and PLOT 60 both fill in inverting mode, but with PLOT 60 the last pixel in the triangle is missed out so that triangles join up but do not overlap.

If the PLOT number in line 130 is change to 90, the circle is filled with a texture.
Initially "grey", you can POKE 8970, 17 to get diagonal shading.
You can experiment with effects by POKEs to 8970 and 8971.
Finally, change the plot number to 12, and insert the following line:

125 PRINT CHR$(I)

This prints the character set round the circle. Note characters can be printed anywhere on the screen.


Example 2.

The following example shows how user defined characters can be generated. The first step is to draw the character on an 8x8 pixel grid, like so for this stick man:

128 64 32 16 8 4 2 1 Byte
0 0 0 1 1 1 0 0 =28
0 0 0 1 1 1 0 0 =28
0 0 0 0 1 0 0 0 =8
0 1 1 1 1 1 1 1 =127
0 0 0 0 1 0 0 0 =8
0 0 0 1 0 1 0 0 =20
0 0 1 0 0 0 1 0 =34
0 1 0 0 0 0 0 1 =65

This program will POKE the 8 bytes defining the character into the correct locations. Simply RUN the program and enter the 8 bytes worked out above. The character will then be printed.

 10 SLOW
 20 LET C = 170
 30 FOR I = 0 TO 7
 40 PRINT AT 0,0; "GIVE ROW"; I+1
 50 INPUT K
 60 POKE(8488+8*(C-160)+I),K
 70 NEXT I
 80 CLS 2
 90 SLOW 2
100 FOR I = 1 TO 255
110 PRINT CHR$ C;" ";
120 NEXT I

Example 3. Moire Pattern

This program generates a Moire pattern by using the invert mode for drawing lines. The pattern arises due to the steps in the drawn lines.

 10 REM MOIRE PATTERN
 20 CLS 2
 30 SLOW 2
 40 FOR I = 0 TO 255
 50 PLOT 12,I,0
 60 PLOT 3,255-I,191
 70 NEXT I
 80 FOR I = 0 TO 191
 90 PLOT 12,0,I
100 PLOT 3,255,191-I
110 NEXT I

Type CLS 3 to reverse the video of this pattern.


Example 4

Examples 4 and 5 show the sort of 3-dimensional effects you can get with high-res graphics.

 10 CLS 2
 20 SLOW 2
 30 PLOT 130,127,10
 40 FOR P = 0 TO 12
 50 LET X1 = P * 10
 60 LET Y1 = P * 7
 70 FOR Q = 0 TO 12
 80 LET Z = -20 * SIN (P/2)*SIN (Q/2)
 90 LET X2 = (P-Q) * 10
100 LET Y2 = Z + (P+Q)*7
110 PLOT 12,-X1,Y1
120 PLOT 12,-X2,Y2
130 PLOT 12, X1,Y1
140 PLOT 2, X2,Y2
150 LET X1 = X2
160 LET Y1 = Y2
170 NEXT Q
180 NEXT P

Example 5.

This program takes about 4 minutes to run, but the result is quite spectacular.

 10 CLS 1
 20 FAST 2
 30 PLOT 130,127, 100
 40 FOR X = 1 TO 120 STEP 2
 50 LET U = X * X
 60 LET L = INT ( 0.5 + SQR(14400-U)/4)
 70 LET M = -100
 80 FOR Y = -L TO L
 90 LET R = (U+Y*Y*16)/1000
100 LET Z = 2.5 * Y - 150/R * SIN R
110 IF Z < M THEN GOTO 150
120 LET M = Z
130 PLOT 9,X,Z
140 PLOT 9,-X,Z
150 NEXT Y
160 NEXT X