Author Topic: Re: Matrix Digital Rain Effect  (Read 1435 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Matrix Digital Rain Effect
« on: March 14, 2019, 10:55:52 am »
Cool [banned user]! :D I like these matrix effect!
Here is my version which I have coded some years ago.
Code: QB64: [Select]
  1. _TITLE "Matrix Rain Effect By Ashish"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.  
  4. TYPE matRain
  5.     x AS INTEGER
  6.     y AS INTEGER
  7.     col AS INTEGER
  8.     length AS INTEGER
  9.     txt AS STRING * 32
  10.     ys AS DOUBLE
  11.     stp AS INTEGER
  12.     fade AS DOUBLE
  13.     u AS INTEGER
  14.     f AS INTEGER
  15. DIM SHARED Matrix(500) AS matRain
  16.  
  17. FOR i = 1 TO UBOUND(matrix)
  18.     Matrix(i).x = RND * _WIDTH
  19.     Matrix(i).y = -INT(RND * _HEIGHT * 2)
  20.     Matrix(i).col = INT(RND * 100) + 1
  21.     Matrix(i).ys = RND * 3
  22.     Matrix(i).length = INT(RND * 31) + 1
  23.     FOR o = 1 TO Matrix(i).length
  24.         c$ = CHR$(RND * 40 + 65)
  25.         cc$ = cc$ + c$
  26.     NEXT
  27.     Matrix(i).txt = cc$
  28.     cc$ = ""
  29.     Matrix(i).fade = RND * 2
  30.     Matrix(i).stp = 1
  31.     Matrix(i).u = INT(RND * 10)
  32. height = _HEIGHT
  33.     CLS
  34.     'LINE (0, 0)-(width, height), _RGBA(0, 0, 0, 80), BF
  35.     FOR i = 1 TO UBOUND(matrix)
  36.         COLOR _RGB(0, (Matrix(i).col / 100 * 255), 0)
  37.         q = 1
  38.         FOR k = Matrix(i).y TO Matrix(i).y + Matrix(i).length * 10 STEP 12
  39.             _PRINTSTRING (Matrix(i).x, k), MID$(Matrix(i).txt, q, 1)
  40.             q = q + 1
  41.         NEXT
  42.         Matrix(i).y = Matrix(i).y + Matrix(i).ys
  43.         Matrix(i).ys = Matrix(i).ys + .05
  44.         tmp$ = ""
  45.         IF Matrix(i).f > Matrix(i).u THEN
  46.             Matrix(i).f = 0
  47.             FOR o = 1 TO Matrix(i).length
  48.                 tmp$ = MID$(Matrix(i).txt, o, 1)
  49.                 tmp$ = CHR$(ASC(tmp$) + Matrix(i).stp)
  50.                 IF ASC(tmp$) > 121 THEN Matrix(i).stp = -Matrix(i).stp
  51.                 IF ASC(tmp$) < 66 THEN Matrix(i).stp = -Matrix(i).stp
  52.                 ff$ = ff$ + tmp$
  53.             NEXT
  54.             Matrix(i).txt = ff$
  55.             ff$ = ""
  56.         END IF
  57.         Matrix(i).f = Matrix(i).f + 1
  58.         IF Matrix(i).y > _HEIGHT THEN
  59.             Matrix(i).x = RND * width
  60.             Matrix(i).y = -INT(RND * height)
  61.             Matrix(i).col = INT(RND * 100) + 1
  62.             Matrix(i).ys = RND * 3
  63.             Matrix(i).length = INT(RND * 31) + 1
  64.             FOR o = 1 TO Matrix(i).length
  65.                 c$ = CHR$(RND * 40 + 65)
  66.                 cc$ = cc$ + c$
  67.             NEXT
  68.             Matrix(i).txt = cc$
  69.             cc$ = ""
  70.             Matrix(i).stp = 1
  71.             Matrix(i).u = INT(RND * 10)
  72.         END IF
  73.         Matrix(i).col = Matrix(i).col + Matrix(i).fade
  74.         IF Matrix(i).col >= 100 OR Matrix(i).col <= 0 THEN Matrix(i).fade = -Matrix(i).fade
  75.     NEXT
  76.     _DISPLAY
  77.     _LIMIT 40
  78.  
  79.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Marked as best answer by on May 03, 2020, 06:32:33 pm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #1 on: March 14, 2019, 09:33:45 pm »
I throw my hat into the ring:
 
QB64 Purple Rain.PNG

* Matrix Rain.zip (Filesize: 3.83 KB, Downloads: 55)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #2 on: March 15, 2019, 10:40:30 pm »
A second effort to get the text to spin as drop descends down the string:
 
Matrix Rain 2.PNG


EDIT: Dah! Don't need the Character Set.DAT file, and so don't need to send this in a .zip package.
Code: QB64: [Select]
  1. _TITLE "Matrix Rain 2" 'B+ started 2019-03-15
  2. ' from Matrix Rain 2019-03-14
  3. ' or QB64 Purple Rain!
  4.  
  5. '>>>>>>>>>>>>>>>> Save this file as: Matrix Rain 2.bas, so the program can load the strings from it.  <<<<<<<<<<<<<<<<<
  6.  
  7. '2019-03-15 This will attempt to spin the drops as they fall
  8. '2019-03-16  Don't need no damn Character Set.DAT file!!!
  9.  
  10. CONST xmax = 1280
  11. CONST ymax = 740
  12. CONST maxChars = ymax \ 16
  13. CONST nDrops = 60
  14. TYPE dropType
  15.     x AS SINGLE
  16.     sz AS SINGLE
  17.     curY AS INTEGER
  18.     xscale AS SINGLE
  19.     dxscale AS SINGLE
  20.  
  21. SCREEN _NEWIMAGE(xmax, ymax, 32)
  22. DIM SHARED fileString$
  23.  
  24. 'use big string from this file for drop text
  25. OPEN "Matrix Rain 2.bas" FOR INPUT AS #1
  26.     INPUT #1, s$
  27.     fileString$ = fileString$ + "B+" + s$
  28.  
  29. 'setup drops
  30. DIM SHARED drop(nDrops) AS dropType
  31. DIM SHARED text(nDrops) AS STRING
  32. FOR i = 0 TO nDrops
  33.     newDrop i, 1
  34.  
  35. WHILE _KEYDOWN(27) = 0
  36.     CLS
  37.     FOR i = 0 TO nDrops
  38.         drawDrop (i)
  39.         drop(i).curY = drop(i).curY + 1
  40.         IF drop(i).curY > LEN(text(i)) THEN newDrop i, 0
  41.     NEXT
  42.     _DISPLAY
  43.     _LIMIT 8
  44.  
  45. SUB drawDrop (i)
  46.     FOR j = 1 TO drop(i).curY
  47.         d = drop(i).curY - j
  48.         IF d = 0 THEN
  49.             c~& = _RGBA32(255, 100, 255, 255)
  50.         ELSEIF d = 1 THEN
  51.             c~& = _RGBA32(255, 50, 255, 215)
  52.         ELSEIF d = 2 THEN
  53.             c~& = _RGBA32(255, 10, 255, 180)
  54.         ELSEIF d = 3 THEN
  55.             c~& = _RGBA32(255, 0, 255, 150)
  56.         ELSEIF d = 4 THEN
  57.             c~& = _RGBA32(255, 0, 255, 125)
  58.         ELSEIF d = 5 THEN
  59.             c~& = _RGBA32(255, 0, 255, 105)
  60.         ELSEIF d = 6 THEN
  61.             c~& = _RGBA32(255, 0, 255, 90)
  62.         ELSEIF d = 7 THEN
  63.             c~& = _RGBA32(255, 0, 255, 80)
  64.         ELSEIF d = 8 THEN
  65.             c~& = _RGBA32(255, 0, 255, 70)
  66.         ELSEIF d = 9 THEN
  67.             c~& = _RGBA32(255, 0, 255, 60)
  68.         ELSEIF d = 10 THEN
  69.             c~& = _RGBA32(255, 0, 255, 50)
  70.         ELSE
  71.             c~& = _RGBA32(255, 0, 255, 0)
  72.         END IF
  73.         rot = drop(i).xscale: dir = 1
  74.         FOR k = 1 TO j
  75.             rot = rot + drop(i).dxscale * dir
  76.             IF rot > 1 THEN rot = 1: dir = -1 * dir
  77.             IF rot < -1 THEN rot = -1: dir = dir * -1
  78.         NEXT
  79.         drwChar MID$(text(i), j, 1), c~&, drop(i).x + 4 * drop(i).sz, drop(i).sz * 16 * (j - 1) + 8 * sz, rot * drop(i).sz, drop(i).sz, 0
  80.     NEXT
  81.  
  82. SUB newDrop (i, start)
  83.     drop(i).x = RND * xmax
  84.     drop(i).sz = RND * 4 + 1
  85.     IF start <> 0 THEN drop(i).curY = INT(RND * (maxChars \ drop(i).sz + 1)) + 1 ELSE drop(i).curY = 1
  86.     text(i) = MID$(fileString$, INT(RND * (LEN(fileString$) - maxChars \ drop(i).sz + 1)), maxChars \ drop(i).sz + 1)
  87.     drop(i).xscale = RND
  88.     r = RND
  89.     IF r < .5 THEN drop(i).dxscale = -.3 * r - .1 ELSE drop(i).dxscale = .3 * r + .1
  90.  
  91. SUB drwChar (char$, c AS _UNSIGNED LONG, midX, midY, xScale, yScale, Rotation) 'what ever the present color is set at
  92.     I& = _NEWIMAGE(8, 16, 32)
  93.     _DEST I&
  94.     COLOR c
  95.     _PRINTSTRING (0, 0), char$
  96.     _DEST 0
  97.     RotoZoom2 midX, midY, I&, xScale, yScale, Rotation
  98.     _FREEIMAGE I&
  99.  
  100. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
  101.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  102.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  103.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  104.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  105.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  106.     FOR i& = 0 TO 3
  107.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  108.         px(i&) = x2&: py(i&) = y2&
  109.     NEXT
  110.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  111.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  112.  
  113.  

Do need to save this file as "Matrix Rain 2.bas" so the program can use strings from the file.
« Last Edit: March 16, 2019, 12:24:31 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #3 on: March 16, 2019, 01:46:12 pm »
Ah finally, I have text strings / drops spinning as originally imagined.
Code: QB64: [Select]
  1. _TITLE "Matrix Rain 3" 'B+ started 2019-03-16
  2. ' from Matrix Rain 2019-03-14
  3. ' or QB64 Purple Rain!
  4.  
  5. '>>> Save this file as: Matrix Rain 3.bas, so the program can load the strings from it.  <<<
  6.  
  7. '2019-03-15 This will attempt to spin the drops as they fall
  8. '2019-03-16  Don't need no damn Character Set.DAT file!!!
  9. '2019-03-16 Ijust want to see the vertical code strings dangle and twist.
  10.  
  11. CONST xmax = 1280
  12. CONST ymax = 740
  13. CONST nDrops = 100
  14. TYPE dropType
  15.     x AS SINGLE
  16.     sz AS SINGLE
  17.     curY AS INTEGER
  18.     dxs AS SINGLE 'direction and change of spin some small fraction of 1, +-1/3, +-1/4, +-1/5...
  19.  
  20. SCREEN _NEWIMAGE(xmax, ymax, 32)
  21. _SCREENMOVE 80, 0 'for snap shot
  22. '_FULLSCREEN    'as screen saver
  23.  
  24. REDIM SHARED fileStrings$(1000) 'container for these program lines that will be dangling
  25. OPEN "Matrix Rain 3.bas" FOR INPUT AS #1
  26.     LINE INPUT #1, fs$
  27.     IF LEN(LTRIM$(fs$)) <> 0 THEN 'less empty spaces
  28.         fileStrings$(i) = LTRIM$(fs$)
  29.         i = i + 1
  30.     END IF
  31. REDIM _PRESERVE fileStrings$(i - 1)
  32. ' check loading
  33. 'FOR i = 0 TO UBOUND(fileStrings$)
  34. '    PRINT i, fileStrings$(i)
  35. 'NEXT
  36. 'END
  37.  
  38. 'setup drops
  39. DIM SHARED drop(nDrops) AS dropType
  40. DIM SHARED s$(nDrops)
  41.  
  42. FOR i = 0 TO nDrops
  43.     newDrop i, 1
  44.  
  45. WHILE _KEYDOWN(27) = 0
  46.     CLS
  47.     FOR i = 0 TO nDrops
  48.         drawDrop (i)
  49.         drop(i).curY = drop(i).curY + 1
  50.         IF drop(i).curY > LEN(s$(i)) THEN newDrop i, 0
  51.     NEXT
  52.     _DISPLAY
  53.     _LIMIT 4
  54.  
  55. SUB newDrop (i, start)
  56.     drop(i).x = RND * xmax 'set location
  57.     drop(i).sz = RND * 4 + .3 'set size
  58.     'length of text string can fit on screen
  59.     charLength = ymax \ (drop(i).sz * 16) + 1 'from size determine how many chars fit on screen
  60.     randLine = INT(RND * UBOUND(fileStrings$)) 'pick a random program line
  61.     s$(i) = MID$(fileStrings$(randLine), 1, charLength) 'here is text string to dangle
  62.     WHILE LEN(s$(i)) < charLength
  63.         IF randLine + 1 > UBOUND(fileStrings$) THEN randLine = 0 ELSE randLine = randLine + 1
  64.         s$(i) = MID$(s$(i) + " : " + fileStrings$(randLine), 1, charLength)
  65.     WEND
  66.     IF start <> 0 THEN drop(i).curY = INT(RND * (charLength)) + 1 ELSE drop(i).curY = 1 'flat and readable at curY
  67.     drop(i).dxs = 1 / (INT(RND * 7) + 3) 'change of spin rate +-1/3, +-1/4, ... +-1/9
  68.     IF RND < .5 THEN drop(i).dxs = -drop(i).dxs
  69.  
  70. SUB drawDrop (i)
  71.     FOR j = 1 TO drop(i).curY
  72.         d = drop(i).curY - j
  73.         IF d = 0 THEN
  74.             c~& = _RGBA32(255, 100, 255, 225)
  75.         ELSEIF d = 1 THEN
  76.             c~& = _RGBA32(255, 50, 255, 205)
  77.         ELSEIF d = 2 THEN
  78.             c~& = _RGBA32(255, 25, 255, 180)
  79.         ELSEIF d >= 3 THEN
  80.             c~& = _RGBA32(255, 0, 255, 190 - d * 5)
  81.         END IF
  82.         rot = 1: dir = -1
  83.         FOR k = 0 TO d
  84.             rot = rot + drop(i).dxs * dir
  85.             IF rot > 1 THEN dir = -1 * dir: rot = 1 + drop(i).dxs * dir
  86.             IF rot < -1 THEN dir = dir * -1: rot = -1 + drop(i).dxs * dir
  87.         NEXT
  88.         drwChar MID$(s$(i), j, 1), c~&, drop(i).x + 4 * drop(i).sz, drop(i).sz * 16 * (j - 1) + 8 * drop(i).sz, rot * drop(i).sz, drop(i).sz, 0
  89.     NEXT
  90.  
  91. SUB drwChar (char$, c AS _UNSIGNED LONG, midX, midY, xScale, yScale, Rotation) 'what ever the present color is set at
  92.     I& = _NEWIMAGE(8, 16, 32)
  93.     _DEST I&
  94.     COLOR c
  95.     _PRINTSTRING (0, 0), char$
  96.     _DEST 0
  97.     RotoZoom2 midX, midY, I&, xScale, yScale, Rotation
  98.     _FREEIMAGE I&
  99.  
  100. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
  101.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  102.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  103.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  104.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  105.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  106.     FOR i& = 0 TO 3
  107.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  108.         px(i&) = x2&: py(i&) = y2&
  109.     NEXT
  110.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  111.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  112.  

 
Matrix Rain 3.PNG



Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #4 on: March 17, 2019, 05:38:21 am »
Cool bplus! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
Re: Matrix Digital Rain Effect
« Reply #5 on: June 20, 2019, 11:22:12 pm »
bplus.
Love the effect.
Is it possible to achieve scalable text without using map-triangle?
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #6 on: June 21, 2019, 12:24:30 am »
bplus.
Love the effect.
Is it possible to achieve scalable text without using map-triangle?

Yes draw text in isolation capture image and use stretch/shrink powers of _PUTIMAGE
Code: QB64: [Select]
  1. _TITLE "Text sub tests" 'B+ started 2019-03-25
  2.  
  3. CONST xmax = 1200
  4. CONST ymax = 700
  5.  
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 100, 40
  8. COLOR _RGB32(0, 0, 255)
  9. PRINT "Hello World"
  10. 'test& = _NEWIMAGE(xmax, ymax, 32)
  11. 'DEST test&
  12. y = ymax
  13. FOR i = 1 TO 60 STEP .5
  14.     CLS
  15.     y = y - 60 / i
  16.     cText xmax / 2, y, 240 / i, _RGB32(255, 0, 0), "So how is this looking?"
  17.     _DISPLAY
  18.     _LIMIT 30
  19. '_DEST 0
  20. '_PUTIMAGE , test&, 0
  21. PRINT "OK, blue?"
  22.  
  23. SUB Text (x, y, textHeight, K AS _UNSIGNED LONG, txt$)
  24.     fg = _DEFAULTCOLOR
  25.     'screen snapshot
  26.     cur& = _DEST
  27.     I& = _NEWIMAGE(8 * LEN(txt$), 16, 32)
  28.     _DEST I&
  29.     COLOR K, _RGBA32(0, 0, 0, 0)
  30.     _PRINTSTRING (0, 0), txt$
  31.     mult = textHeight / 16
  32.     xlen = LEN(txt$) * 8 * mult
  33.     _PUTIMAGE (x, y)-STEP(xlen, textHeight), I&, cur&
  34.     COLOR fg
  35.     _FREEIMAGE I&
  36.  
  37. SUB cText (x, y, textHeight, K AS _UNSIGNED LONG, txt$)
  38.     fg = _DEFAULTCOLOR
  39.     'screen snapshot
  40.     cur& = _DEST
  41.     I& = _NEWIMAGE(8 * LEN(txt$), 16, 32)
  42.     _DEST I&
  43.     COLOR K, _RGBA32(0, 0, 0, 0)
  44.     _PRINTSTRING (0, 0), txt$
  45.     mult = textHeight / 16
  46.     xlen = LEN(txt$) * 8 * mult
  47.     _PUTIMAGE (x - .5 * xlen, y - .5 * textHeight)-STEP(xlen, textHeight), I&, cur&
  48.     COLOR fg
  49.     _FREEIMAGE I&
  50.  
  51.  
« Last Edit: June 21, 2019, 12:25:59 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Matrix Digital Rain Effect
« Reply #7 on: June 21, 2019, 01:15:25 am »
I see I hadn't posted my final rain, it has better 3D effect because of ratio small drops to large:
Code: QB64: [Select]
  1. _TITLE "Matrix Rain 4" 'B+ started 2019-03-16
  2. ' from Matrix Rain 2019-03-14
  3. ' or QB64 Purple Rain!
  4.  
  5. '>>> Save this file as: Matrix Rain 4.bas, so the program can load the strings from it.  <<<
  6.  
  7. '2019-03-15 This will attempt to spin the drops as they fall
  8. '2019-03-16  Don't need no damn Character Set.DAT file!!!
  9. '2019-03-16 Ijust want to see the vertical code strings dangle and twist.
  10.  
  11. '2019-03-19 Matrix Rain 4
  12. ' + added randWeight to weight the random sizes chosen so many more on small side than large
  13. ' + draw letters on a transparent background so the background of the letter does not cover
  14. '   the drops behind it.
  15.  
  16.  
  17. CONST xmax = 1280
  18. CONST ymax = 740
  19. CONST nDrops = 500
  20. TYPE dropType
  21.     x AS SINGLE
  22.     sz AS SINGLE
  23.     curY AS INTEGER
  24.     dxs AS SINGLE 'direction and change of spin some small fraction of 1, +-1/3, +-1/4, +-1/5...
  25.  
  26. SCREEN _NEWIMAGE(xmax, ymax, 32)
  27. _SCREENMOVE 80, 0 'for snap shot
  28. '_FULLSCREEN 'as screen saver
  29.  
  30. REDIM SHARED fileStrings$(1000) 'container for these program lines that will be dangling
  31. OPEN "Matrix Rain 4.bas" FOR INPUT AS #1
  32.     LINE INPUT #1, fs$
  33.     IF LEN(LTRIM$(fs$)) <> 0 THEN 'less empty spaces
  34.         fileStrings$(i) = LTRIM$(fs$)
  35.         i = i + 1
  36.     END IF
  37. REDIM _PRESERVE fileStrings$(i - 1)
  38. ' check loading
  39. 'FOR i = 0 TO UBOUND(fileStrings$)
  40. '    PRINT i, fileStrings$(i)
  41. 'NEXT
  42. 'END
  43.  
  44. 'setup drops
  45. DIM SHARED drop(nDrops) AS dropType
  46. DIM SHARED s$(nDrops)
  47.  
  48. FOR i = 0 TO nDrops
  49.     newDrop i, 1
  50.  
  51. WHILE _KEYDOWN(27) = 0
  52.     CLS
  53.     FOR i = 0 TO nDrops
  54.         drawDrop (i)
  55.         drop(i).curY = drop(i).curY + 1
  56.         IF drop(i).curY > LEN(s$(i)) THEN newDrop i, 0
  57.     NEXT
  58.     _DISPLAY
  59.     _LIMIT 25
  60.  
  61. SUB newDrop (i, start)
  62.     drop(i).x = RND * xmax 'set location
  63.     drop(i).sz = randWeight(.3, 5, 3) 'set size  weighted on small sizes
  64.     'length of text string can fit on screen
  65.     charLength = ymax \ (drop(i).sz * 16) + 1 'from size determine how many chars fit on screen
  66.     randLine = INT(RND * UBOUND(fileStrings$)) 'pick a random program line
  67.     s$(i) = MID$(fileStrings$(randLine), 1, charLength) 'here is text string to dangle
  68.     WHILE LEN(s$(i)) < charLength
  69.         IF randLine + 1 > UBOUND(fileStrings$) THEN randLine = 0 ELSE randLine = randLine + 1
  70.         s$(i) = MID$(s$(i) + " : " + fileStrings$(randLine), 1, charLength)
  71.     WEND
  72.     IF start <> 0 THEN drop(i).curY = INT(RND * (charLength)) + 1 ELSE drop(i).curY = 1 'flat and readable at curY
  73.     drop(i).dxs = 1 / (INT(RND * 7) + 3) 'change of spin rate +-1/3, +-1/4, ... +-1/9
  74.     IF RND < .5 THEN drop(i).dxs = -drop(i).dxs
  75.  
  76. SUB drawDrop (i)
  77.     FOR j = 1 TO drop(i).curY
  78.         d = drop(i).curY - j
  79.         IF d = 0 THEN
  80.             c~& = _RGBA32(255, 100, 255, 225)
  81.         ELSEIF d = 1 THEN
  82.             c~& = _RGBA32(255, 50, 255, 205)
  83.         ELSEIF d = 2 THEN
  84.             c~& = _RGBA32(255, 25, 255, 180)
  85.         ELSEIF d >= 3 THEN
  86.             c~& = _RGBA32(255, 0, 255, 190 - d * 5)
  87.         END IF
  88.         rot = 1: dir = -1
  89.         FOR k = 0 TO d
  90.             rot = rot + drop(i).dxs * dir
  91.             IF rot > 1 THEN dir = -1 * dir: rot = 1 + drop(i).dxs * dir
  92.             IF rot < -1 THEN dir = dir * -1: rot = -1 + drop(i).dxs * dir
  93.         NEXT
  94.         drwChar MID$(s$(i), j, 1), c~&, drop(i).x + 4 * drop(i).sz, drop(i).sz * 16 * (j - 1) + 8 * drop(i).sz, rot * drop(i).sz, drop(i).sz, 0
  95.     NEXT
  96.  
  97. SUB drwChar (char$, c AS _UNSIGNED LONG, midX, midY, xScale, yScale, Rotation) 'what ever the present color is set at
  98.     I& = _NEWIMAGE(8, 16, 32)
  99.     _DEST I&
  100.     COLOR c, _RGBA32(0, 0, 0, 0)
  101.     _PRINTSTRING (0, 0), char$
  102.     _DEST 0
  103.     RotoZoom2 midX, midY, I&, xScale, yScale, Rotation
  104.     _FREEIMAGE I&
  105.  
  106. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
  107.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  108.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  109.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  110.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  111.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  112.     FOR i& = 0 TO 3
  113.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  114.         px(i&) = x2&: py(i&) = y2&
  115.     NEXT
  116.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  117.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  118.  
  119. FUNCTION randWeight (manyValue, fewValue, power)
  120.     randWeight = manyValue + RND ^ power * (fewValue - manyValue)
  121.  
  122.  
Matrix Rain 4.PNG