Screen Saver



View all posts by: Vectronic | View all posts in category: Apple II Software

The program listed below is a screen saver that generates random vertical and horizontal lines in low-resolution mode. The lines don't just appear on the screen. They drag slowly across the screen from one side to the other. The program could also be described as a pattern generator. Pressing the spacebar will clear the screen and quit the screen saver. The program makes use of a pseudo random number generator built into Applesoft BASIC. RND is a function that seems to pick numbers at random.

The BASIC statement:

10 PRINT RND(1)

will generate a list of random numbers that will be different each time the program is RUN.

Any positive number included within the RND parenthesis will work. A positive number in the parenthesis will always produce a different set of random numbers each RUN. This will not be true if zero (0) or a negative number is used.

The above BASIC statement would produce an output similar to the following:

.973136996

RND(1) will always produce a random number between 0 and 1. The screen saver program requires random integer digits with no decimals. Random numbers produced by the RND function are uniformly distributed between 0 and 1. That is, they are "spread evenly" between 0 and 1. Each random number is about as likely or unlikely to occur as any other random number. RND(1) is between 0 and 1, but it is never 0 or 1. Therefore, 10 * RND(1) is between 0 and 10, but is never equal to 0 or 10.

For each random number between 0 and 10 that 10*RND(1) generates, the integer (whole number) part is a single digit. BASIC has a function that can pull the integer part from any number. INT will drop the decimal.

For example:

INT (3.15489) = 3

Therefore,

INT(10*RND(1)) = a single digit between 0 and 10

The program uses these digits to generate colors and plot points.

The program starts out by clearing the input buffer for the keyboard. In line 10, K = PEEK(-16368) resets the keyboard strobe to zero and assigns the value of 0 to K. The strobe is now clear and ready for an input. In lines 1500 and 4500, K = PEEK(-16384) assigns the number value of the key pressed to variable K. To learn more about how PEEK works read "Applesoft BASIC Paint Program" available on this site. The spacebar number is 160. The IF statement in line 500 breaks the main program loop when the spacebar is pressed (because K is assigned a value of 160) and gives control to subroutine 5000. Subroutine 5000 puts the computer back into TEXT mode and clears the screen with HOME before exiting the program at line 999.

The program will generate 50 vertical bars and 50 horizontal bars. The timer is variable C. It starts out at 1 at line 30 and increments by 1 each time the programs loops past line 600. Once the variable hits 100, line 700 will send the program control back to line 20. Line 20 clears the screen and the whole process starts over again. You can increase the number of cycles by change the value in the IF statement in line 700.

There are two random number subroutines, subroutine 2000 for random X-axis numbers and subroutine 3000 for random Y-axis number.

Movement along the X-axis is controlled by subroutine 1000. Movement along the Y-axis is controlled by subroutine 4000. Movement is always from left to right on the X-axis and from top to bottom on the Y-axis. Each subroutine has a limiting variable to keep the line from driving off the screen and causing an "out of bounds" error.

The plotting logic is fairly straightforward and can easily be modified to change the pattern.



The Screen Saver Program:

5 REM SCREEN SAVER BY VECTRONIC
10 K = PEEK(-16368): HOME
20 GR
30 C = 1
100 GOSUB 2000
200 GOSUB 1000
300 GOSUB 3000
400 GOSUB 4000
500 IF K = 160 THEN GOSUB 5000
600 C = C + 1
700 IF C = 100 THEN 20
800 GOTO 100
999 END

1000 REM X MOVEMENT
1100 A = INT (10 * RND (1))
1200 IF A = 0 THEN 1100
1300 Y = 1
1400 COLOR= A: PLOT X,Y
1500 K = PEEK (-16384)
1600 IF K = 160 THEN GOSUB 5000
1700 IF Y = 39 THEN 1999
1800 Y = Y + 1
1900 GOTO 1400
1999 RETURN

2000 REM RANDOM X
2100 B = INT (10 * RND (1))
2200 J = INT (10 * RND (1))
2300 H = INT (10 * RND (1))
2400 I = INT (10 * RND (1))
2500 X = B + J + H + 1
2999 RETURN

3000 REM RANDOM Y
3100 B = INT (10 * RND (1))
3200 J = INT (10 * RND (1))
3300 H = INT (10 * RND (1))
3400 I = INT (10 * RND (1))
3500 Y = B + J + H + 1
3999 RETURN

4000 REM Y MOVEMENT
4100 A = INT (10 * RND (1))
4200 IF A = 0 THEN 4100
4300 X = 1
4400 COLOR= A: PLOT X,Y
4500 K = PEEK (-16384)
4600 IF K = 160 THEN GOSUB 5000
4700 IF X = 39 THEN 4999
4800 X = X + 1
4900 GOTO 4400
4999 RETURN

5000 REM QUIT SEQUENCE
5100 TEXT: HOME
5200 GOTO 999
5300 RETURN



A screen saver is really not necessary on an Apple II computer. Programs cannot be run simultaneously. There is no "desktop" like in a modern computer (IIgs aside) that constantly illuminates the entire screen. You must quit any other program to run the screen saver. When you quit a program, all that is left on the screen is the tiny prompt ("]") and flashing cursor. The rest of the screen is blacked out.

Screen burn is not an issue with modern monitors but Apple II phosphor monitors are definitely subject to it. When an electron beam strikes a screen area continuously, the phosphor there eventually wears. Stationary images left for long periods may thus "burn in," leaving a faint shadow. An Apple II screensaver is really overkill. Apple II's usually idle in complete darkness, except for the prompt, until a program is run. Perhaps this BASIC program could be combined with a program that does illuminate the monitor for a long period of time. In any case, it is an interesting experiment and Vectronic's Apple World is all about doing interesting things with Apple computers.


About halfway through the current cycle



Just starting (note the progress of the light blue line
in the left corner as it moves across the screen)