Advertisement
ForrestFox

Water2D

Mar 21st, 2021
1,569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 1.67 KB | None | 0 0
  1. SCREEN 13
  2.  
  3. DIM SHARED wp(320) AS SINGLE
  4. DIM SHARED wn(320) AS SINGLE
  5. DIM SHARED bt(320) AS INTEGER
  6.  
  7. ' Empty
  8. FOR i = 0 TO 319: wp(i) = 0: NEXT
  9.  
  10. Atmo
  11.  
  12. DO
  13.  
  14.   k$ = INKEY$
  15.  
  16.   ' Water effect
  17.   IF k$ = " " OR id > nx THEN
  18.  
  19.     FOR i = 0 TO 4
  20.       x = INT(RND * 320)
  21.       wp(x) = wp(x) - 8 * RND
  22.     NEXT
  23.  
  24.     id = 0
  25.     nx = INT(RND * 25 + 15)
  26.  
  27.   END IF
  28.  
  29.   ' Redraw
  30.   Update
  31.  
  32.   ' Time effect
  33.   id = id + 1
  34. LOOP UNTIL k$ = CHR$(27)
  35.  
  36. SUB Atmo
  37.  
  38.   RANDOMIZE TIMER
  39.  
  40.   LINE (0, 0)-(320, 100), 1, BF
  41.   CIRCLE (300, 20), 13, 14: PAINT (300, 20), 14
  42.  
  43.   ' Beach level
  44.   FOR x = 0 TO 320: bt(x) = 200: NEXT
  45.  
  46.   ' Draw simple beach
  47.   FOR x = 0 TO 128
  48.     h = INT(x ^ 2 / 128)
  49.     s = 150 + h
  50.     bt(x) = s
  51.     FOR y = s TO 199
  52.       l = y - 149
  53.       IF RND > l / 75 THEN cl = 14 ELSE cl = 6
  54.       PSET (x, y), cl
  55.     NEXT
  56.   NEXT
  57.  
  58. END SUB
  59.  
  60. SUB Update
  61.  
  62.   omega = .995
  63.   relax = .995
  64.  
  65.   FOR i = 0 TO 319
  66.  
  67.     IF i = 0 THEN a = wn(1) ELSE a = wn(i - 1)
  68.     IF i = 319 THEN b = wn(318) ELSE b = wn(i + 1)
  69.  
  70.     laplas = (a + b) / 2
  71.  
  72.     ' Difference between previous (wn) and current (wp) level
  73.     wp(i) = laplas + omega * (wn(i) - wp(i))
  74.  
  75.     ' Relax
  76.     wp(i) = wp(i) * relax
  77.  
  78.   NEXT
  79.  
  80.   ' Line level
  81.   WU = 100
  82.   WL = 170
  83.  
  84.   ' Swap fields
  85.   FOR i = 0 TO 319
  86.  
  87.     SWAP wp(i), wn(i)
  88.  
  89.     lv = WL - INT(wn(i))
  90.  
  91.     ' Draw
  92.     IF lv <= bt(i) THEN
  93.  
  94.       LINE (i, WU)-(i, lv - 2), 1   ' Sky
  95.       LINE (i, lv)-(i, bt(i)), 3    ' Water
  96.  
  97.       ' Lighting
  98.       nx = wn(i + 1) - wn(i)
  99.       IF nx < 0 THEN cl = 15 ELSE cl = 11
  100.       PSET (i, lv - 1), cl
  101.  
  102.     ELSE
  103.  
  104.       LINE (i, WU)-(i, bt(i)), 1' Sky
  105.  
  106.     END IF
  107.  
  108.   NEXT
  109.  
  110. END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement