§ Программа на QBasic

ef5f1741e20e70c6f922bb0ee8522e19.png
SCREEN 13

DIM SHARED wp(320) AS SINGLE
DIM SHARED wn(320) AS SINGLE
DIM SHARED bt(320) AS INTEGER

' Empty
FOR i = 0 TO 319: wp(i) = 0: NEXT

Atmo

DO

  k$ = INKEY$

  ' Water effect
  IF k$ = " " OR id > nx THEN

    FOR i = 0 TO 4
      x = INT(RND * 320)
      wp(x) = wp(x) - 8 * RND
    NEXT

    id = 0
    nx = INT(RND * 25 + 15)

  END IF

  ' Redraw
  Update

  ' Time effect
  id = id + 1
LOOP UNTIL k$ = CHR$(27)

SUB Atmo

  RANDOMIZE TIMER

  LINE (0, 0)-(320, 100), 1, BF
  CIRCLE (300, 20), 13, 14: PAINT (300, 20), 14

  ' Beach level
  FOR x = 0 TO 320: bt(x) = 200: NEXT

  ' Draw simple beach
  FOR x = 0 TO 128
    h = INT(x ^ 2 / 128)
    s = 150 + h
    bt(x) = s
    FOR y = s TO 199
      l = y - 149
      IF RND > l / 75 THEN cl = 14 ELSE cl = 6
      PSET (x, y), cl
    NEXT
  NEXT

END SUB

SUB Update

  omega = .995
  relax = .995

  FOR i = 0 TO 319

    IF i = 0 THEN a = wn(1) ELSE a = wn(i - 1)
    IF i = 319 THEN b = wn(318) ELSE b = wn(i + 1)

    laplas = (a + b) / 2

    ' Difference between previous (wn) and current (wp) level
    wp(i) = laplas + omega * (wn(i) - wp(i))

    ' Relax
    wp(i) = wp(i) * relax

  NEXT

  ' Line level
  WU = 100
  WL = 170

  ' Swap fields
  FOR i = 0 TO 319

    SWAP wp(i), wn(i)

    lv = WL - INT(wn(i))

    ' Draw
    IF lv <= bt(i) THEN

      LINE (i, WU)-(i, lv - 2), 1   ' Sky
      LINE (i, lv)-(i, bt(i)), 3    ' Water

      ' Lighting
      nx = wn(i + 1) - wn(i)
      IF nx < 0 THEN cl = 15 ELSE cl = 11
      PSET (i, lv - 1), cl

    ELSE

      LINE (i, WU)-(i, bt(i)), 1' Sky

    END IF

  NEXT

END SUB