Results 1 to 15 of 15

Thread: Matrix Effect

Threaded View

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Matrix Effect

    I was browsing YouTube today and I came across this video that shows a sort of matrix effect made in a C# console application.

    The link to the code is in the description, so I followed the link, copied and pasted the code it into an online C# to VB converter. I had to make a few changes, but I was able to get it to work in VB just fine and thought to share it with everyone.

    Enjoy!

    VB.NET Code:
    1. Module Module1
    2.     Sub Main()
    3.         Console.Title = "Matrix Effect"
    4.         Console.ForegroundColor = ConsoleColor.DarkGreen
    5.         Console.WindowLeft = InlineAssignHelper(0, 0)
    6.         Console.WindowHeight = InlineAssignHelper(Console.BufferHeight, Console.LargestWindowHeight)
    7.         Console.WindowWidth = InlineAssignHelper(Console.BufferWidth, Console.LargestWindowWidth)
    8.  
    9.         Console.CursorVisible = False
    10.         Dim width As Integer, height As Integer
    11.         Dim y As Integer()
    12.         Dim l As Integer()
    13.         Initialize(width, height, y, l)
    14.         Dim ms As Integer
    15.         While True
    16.             Dim t1 As DateTime = DateTime.Now
    17.             MatrixStep(width, height, y, l)
    18.             ms = 10 - CInt(Math.Truncate(CType(DateTime.Now - t1, TimeSpan).TotalMilliseconds))
    19.             If ms > 0 Then
    20.                 System.Threading.Thread.Sleep(ms)
    21.             End If
    22.             If Console.KeyAvailable Then
    23.                 If Console.ReadKey().Key = ConsoleKey.F5 Then
    24.                     Initialize(width, height, y, l)
    25.                 End If
    26.             End If
    27.         End While
    28.     End Sub
    29.  
    30.     Dim thistime As Boolean = False
    31.  
    32.     Private Sub MatrixStep(ByVal width As Integer, ByVal height As Integer, ByVal y As Integer(), ByVal l As Integer())
    33.         Dim x As Integer
    34.         thistime = Not thistime
    35.         For x = 0 To width - 1
    36.             If x Mod 11 = 10 Then
    37.                 If Not thistime Then
    38.                     Continue For
    39.                 End If
    40.                 Console.ForegroundColor = ConsoleColor.White
    41.             Else
    42.                 Console.ForegroundColor = ConsoleColor.DarkGreen
    43.                 Console.SetCursorPosition(x, inBoxY(y(x) - 2 - ((l(x) \ 40) * 2), height))
    44.                 Console.Write(R)
    45.                 Console.ForegroundColor = ConsoleColor.Green
    46.             End If
    47.             Console.SetCursorPosition(x, y(x))
    48.             Console.Write(R)
    49.             y(x) = inBoxY(y(x) + 1, height)
    50.             Console.SetCursorPosition(x, inBoxY(y(x) - l(x), height))
    51.             Console.Write(" "c)
    52.         Next
    53.     End Sub
    54.  
    55.     Private Sub Initialize(ByRef width As Integer, ByRef height As Integer, ByRef y As Integer(), ByRef l As Integer())
    56.         Dim h1 As Integer
    57.         Dim h2 As Integer = (InlineAssignHelper(h1, (InlineAssignHelper(height, Console.WindowHeight)) \ 2)) \ 2
    58.         width = Console.WindowWidth - 1
    59.         y = New Integer(width - 1) {}
    60.         l = New Integer(width - 1) {}
    61.         Dim x As Integer
    62.         Console.Clear()
    63.         For x = 0 To width - 1
    64.             y(x) = m_r.[Next](height)
    65.             l(x) = m_r.[Next](h2 * (If((x Mod 11 <> 10), 2, 1)), h1 * (If((x Mod 11 <> 10), 2, 1)))
    66.         Next
    67.     End Sub
    68.  
    69.     Dim m_r As New Random()
    70.     Private ReadOnly Property R() As Char
    71.         Get
    72.             Dim t As Integer = m_r.[Next](10)
    73.             If t <= 2 Then
    74.                 Return ChrW(CInt(AscW("0"c)) + m_r.[Next](10))
    75.             ElseIf t <= 4 Then
    76.                 Return ChrW(CInt(AscW("a"c)) + m_r.[Next](27))
    77.             ElseIf t <= 6 Then
    78.                 Return ChrW(CInt(AscW("A"c) + m_r.[Next](27)))
    79.             Else
    80.                 Return ChrW(m_r.[Next](32, 255))
    81.             End If
    82.         End Get
    83.     End Property
    84.  
    85.     Public Function inBoxY(ByVal n As Integer, ByVal height As Integer) As Integer
    86.         n = n Mod height
    87.         If n < 0 Then
    88.             Return n + height
    89.         Else
    90.             Return n
    91.         End If
    92.     End Function
    93.     Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    94.         target = value
    95.         Return value
    96.     End Function
    97.  
    98. End Module

    *Edit:

    I forgot to mention that when the app is opened, it expands completely, but the top left is offset for some reason. Also, resizing the window to make it smaller or clicking the maximize button for the console screws it up.
    Last edited by weirddemon; Mar 27th, 2011 at 12:13 AM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width