'matrix.bas ' '"Matrix" style graphic demo using freebasic #Include "fbgfx.bi" #Define screen_w 640 #Define screen_h 480 #Define screen_bpp 32 #Define fade 7 #Define change 3 #Define scroll 3 #Define msgx 25 #Define msgy 18 Const hiddenmsg As String = "When you see it..." Type tmatrix char As UByte msg As Byte 'if part of the message, dont mess with it shade As integer '255 is a bright green, 254-0 shades of green End Type Dim Shared matrix(0 To 79, 0 To 59) As tmatrix Dim Shared tracers(0 To 79) As Integer Dim Shared As Integer x, y, i, j ''BEGIN'' 'set up the screen ScreenRes screen_w, screen_h, screen_bpp, 2 ScreenSet 1, 0 'load the 8x8 character set Width 80, 60 Randomize Timer 'reset our matrix For y = 0 To 59 For x = 0 To 79 With matrix(x, y) .char = CUByte(Rnd * 256) .shade = 0 .msg = 0 End With Next Next 'hide our message in the matrix x = msgx y = msgy For i = 0 To Len(hiddenmsg) matrix(x, y).char = Asc(Mid(hiddenmsg, i+1, 1)) matrix(x, y).msg = 1 x = x + 1 Next 'reset our tracers (to create the same effect seen in the movie) For i = 0 To 79 tracers(i) = Int(Rnd * 60) matrix(i, tracers(i)).shade = 255 Next 'now we loop through the grid and draw it until the user decides to exit Do Cls 'lock the screen first ScreenLock For y = 0 To 59 For x = 0 To 79 With matrix(x, y) j = Int(Rnd * change) If j = 0 And .msg = 0 Then .char = CUByte(Rnd * 256) If .shade = 255 Then Draw String (x Shl 3, y Shl 3), Chr(.char), RGB(192, 255, 192) Else Draw String (x Shl 3, y Shl 3), Chr(.char), RGB(0, .shade+1, 0) EndIf .shade -= (Int(Rnd * fade) + 1) If .shade < 0 Then .shade = 0 End With Next Next ScreenUnLock 'draw a frame ScreenCopy 1, 0 Sleep 50, 1 'loop through the tracers and move them downwards For i = 0 To 79 j = Int(Rnd * scroll) If j > 0 Then tracers(i) += 1 If tracers(i) > 59 Then tracers(i) = 0 EndIf matrix(i, tracers(i)).shade = 255 Next Loop Until MultiKey(fb.sc_escape) ''END''