; Matrix code by Mike Connor
Global time
Global oldtime
Global newtime
Const fps = 20
Global fps_set = fps
Global maxtrails = 4000
Graphics 800,600,32
Global matrix1=LoadImage("Images/pic.bmp")
Global code=LoadAnimImage("Images/code.bmp",12,12,0,400)
MaskImage code,255,0,255
Dim graphic(100,66,50)
SeedRnd MilliSecs()
SetBuffer BackBuffer()
Global small = LoadFont("mCode",12,False,False,False)
Global med = LoadFont("mCode",12,False,False,False)
Global large = LoadFont("mCode",12,False,False,False)
Global pictureon = 0
; Define types
Type snippet
Field x,y,size
End Type
Type trail
Field x,y,bright,size,char,count,hold
End Type
Type xline
Field pos,length,start,life,count
End Type
Global mode
mode = 1
ReadBitMap()
While Not KeyDown(1)
If MouseDown(2) Then mode = 2
If MouseDown(1) Then mode = 1
; Clear screen
Cls
; Redraw everything
ReDrawSnippets()
If MouseDown(3) Then SaveBuffer(FrontBuffer(),"screenshot"+Rand(1,1000)+".bmp")
; Wait time
HandleFPS()
; Special effects!
SpecialEffects()
; Update everytning
UpDateSnippets()
; go again!
Wend
Function ReDrawSnippets()
For a.snippet = Each snippet
Color 255,255,255
If a\size = small Then Color 200,200,200
Select a\size
Case 1
SetFont small
Case 2
SetFont med
Case 3
SetFont large
End Select
DrawImage code,a\x*12,a\y*12,Rand(0,19)
Next
For b.trail = Each trail
Select b\size
Case 1
SetFont small
Case 2
SetFont med
Case 3
SetFont large
End Select
Color 0,b\bright,0
DrawImage code,b\x*12,b\y*12,19+b\char+(b\bright*20)
Next
Flip
End Function
Function UpDateSnippets()
; Random X-lines
a = Rand (1,50)
If a = 1
ff.xline = New xline
ff\pos = Rand (1,40)
ff\length = Rand (10,60)
ff\start = Rand(1,50)
ff\life = Rand (5,200)
End If
a = Rand (1,500)
If a = 1
ffl = Rand (0, 35)
strt = Rand (1,60)
lfe = Rand (5,200)
For b = 1 To Rand (2,20)
ff.xline = New xline
ff\pos = ffl + b
ff\length = Rand (5,30)
ff\start = srt+Rand(-10,10)
ff\life = lfe
Next
End If
For lar.xline = Each xline
lar\count = lar\count + 1
If lar\count > lar\life Then Delete lar
Next
;If pictureon = 1 Then g = 3 Else g = 1
;For a = 1 To g
h.snippet = New snippet
h\x = Rand (0,66)
h\y = 0
h\size= Rand(1,3)
;Next
count = 0
For n.trail = Each trail
If n\hold > 0 Then n\hold = n\hold - 1
count=count+1
a = Rand(1,100)
If a = 1 Then n\char=Rand(1,20)
n\count=n\count+1
If pictureon = 1 Then ddd = 5 Else ddd = 2
If n\count > ddd And n\hold <1
n\count = 0
n\bright = n\bright + 1
If n\bright > 18 Then Delete n
End If
Next
For z.snippet = Each snippet
x.trail = New trail
x\hold = 20
x\char = Rand(1,20)
x\x = z\x
x\y = z\y
For jj.xline = Each xline
If x\y = jj\pos And x\x => jj\start And x\x =< jj\start + jj\length
x\hold = jj\life - jj\count
End If
Next
x\size= z\size
x\bright = 0
If pictureon = 1 Then x\bright = graphic(1,z\x,z\y)
z\y = z\y+1
If z\y > 50 Then Delete z
Next
If count>maxtrails
cnt = count-maxtrails
cnt2=0
For ll.trail = Each trail
cnt2=cnt2+1
If cnt2<cnt
Delete ll
End If
Next
End If
; For z.snippet = Each snippet
;z\bright = graphic(1,z\x,z\y)
;Next
End Function
Function HandleFPS()
oldtime=newtime
newtime=MilliSecs()
time=1000/(newtime-oldtime)
If time<fps Then fps_set=fps_set+2
If time>fps Then fps_set=fps_set-2
a = MilliSecs()
While b<(a+(1000/fps_set))
b=MilliSecs()
Wend
End Function
Function SpecialEffects()
a = GetKey()
If Chr$(a) = "f" Or Chr$(a)="F"
For b.trail = Each trail
b\bright = Rand(1,18)
Next
End If
If Chr$(a) = "p" Or Chr$(a)="P"
pictureon = 1
End If
If Chr$(a) = "o" Or Chr$(a)="O"
pictureon = 0
End If
End Function
Function ReadBitmap()
SetBuffer ImageBuffer(matrix1,0)
For a = 1 To 66
For b = 1 To 50
GetColor a,b
graphic(1,a,b)= ((ColorRed()+ColorGreen()+ColorBlue())/3)*0.07
Next
Next
SetBuffer BackBuffer()
End Function