' Rain Program
' Made for qbasic and gbasic
' Gab 2000
' Gabasic Version

max = 400       ' Max
endloop = 0

DIM RainX(max) AS INTEGER
DIM RainY(max) AS INTEGER
DIM RainC(max) AS INTEGER
DIM RainP(max) AS INTEGER
Dim Vscreen(32000) AS INTEGER

RANDOMIZE TIMER

SCREEN 13

' --- Lets create the palette
i = 0
c = 65

FOR i = 0 TO 63
  c = c - 1
  SETCOL c, 0, i / 2, i
NEXT i

' Random

FOR i = 0 TO max
  RainX(i) = RND(300)
  RainY(i) = RND(190)
  RainC(i) = RND(63) + 1
  RainC(i) = RainC(i)
  RainP(i) = RainC(i) \ 16
NEXT i

voffs = varptr(vscreen(0))

Setvoffs voffs

DO WHILE NOT endloop = 1

  k = INKEY
  IF k = 27 THEN
    endloop = 1
    GOTO Loop1
  END IF

  FOR i = 0 TO max
    RainY(i) = RainY(i) + 1

    IF NOT RainP(i) = 0 THEN
    IF RainY(i) \ RainP(i) > 195 THEN
      RainX(i) = RND(300)
      RainY(i) = 0
      RainC(i) = RND(63) + 1
      RainC(i) = RainC(i)
      RainP(i) = RainC(i) \ 16
    END IF
    END IF
  NEXT i

  MEMFILLD voffs, 16000, 0

  FOR i = 0 TO max
  IF NOT RainP(i) = 0 THEN
    PSET RainX(i), RainY(i) \ RainP(i), RainC(i)
  ELSE
    PSET RainX(i), RainY(i), RainC(i)
  END IF
  NEXT i

  MEMCOPYD voffs, 0A0000h, 16000

Loop1:
LOOP

SCREEN 0

END
