December 04, 2020, 12:03:31 PM

### Author Topic: [bb] Bank as dynamic aray by Matt Merkulov [ 1+ years ago ]  (Read 625 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Bank as dynamic aray by Matt Merkulov [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Bank as dynamic aray
Author : Matt Merkulov
Posted : 1+ years ago

Description : From article:<a href="http://blitzetcetera.org/index.php/Ð‘Ð°Ð½Ðº%2C_ÐºÐ°Ðº_Ð´Ð¸Ð½Ð°Ð¼Ð¸Ñ‡ÐµÑÐºÐ¸Ð¹_Ð¼Ð°ÑÑÐ¸Ð²" target="_blank"> Bank as dynamic array[/url] (rus)

Code :
Code: BlitzBasic
1. ;Bank as dynamic array (snow demo) by Matt Merkulov
2.
3. ;Maxrec - a maximum quantity of records, reclen - length of record in bytes
4. ;In this example record contains coordinates:  x(float), y(float), increments:
5. ;dx(Float), dy(Float), grayscale color(byte) - 17 bytes)
6. Const maxrec = 120000, reclen = 17
7. ;Creating bank
8. bnk = CreateBank(maxrec * reclen)
9. ;Address of last element in bank
11.
12. Graphics 800, 600, 32
13.
14. ;An array for storage of values of colors
15. Dim col(255)
16. For n = 0 To 255
17.  col(n) = n * 65793
18. Next
19.
20. SetBuffer BackBuffer()
21. Repeat
23.  For n = 1 To 400
25.   PokeFloat bnk, addr, Rand(800);coordinate x
26.   PokeFloat bnk, addr + 4, 0;coordinate y
27.   PokeFloat bnk, addr + 8, Rnd(-1, 1);an increment for x
28.   PokeFloat bnk, addr + 12, Rnd(2, 10);an increment for y
29.   PokeByte bnk, addr + 16, Rnd(64, 255);number of color
30.  Next
31.
32.  Cls
33.  LockBuffer BackBuffer()
34.
35. ;Checking all snowflakes in bank
36.  n = 0
39.  x# = PeekFloat(bnk, n) + PeekFloat(bnk, n + 8)
40.  y# = PeekFloat(bnk, n + 4) + PeekFloat(bnk, n + 12)
41.  If x# < 0 Or x# > 799 Or y# > 599 Then
42.   ;If the snowflake has left screen area - deleting it from bank
43.   CopyBank bnk, addr, bnk, n, reclen
45.   ;As the last entry has been moved on the place of current, so the address does not increase
46.  Else
47.   ;If it is still on the screen - updating coordinates
48.   WritePixelFast x#, y#, col(PeekByte(bnk, n + 12))
49.   PokeFloat bnk, n, x#
50.   PokeFloat bnk, n + 4, y#
51.   ;Drawing current snowflake
52.   n = n + reclen
53.  End If
54.  Wend
55.
56.  UnlockBuffer BackBuffer()
57.  Flip
58.
59. Until KeyHit (1)