Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class paintutils
- Public Shared Function setBackground(ByVal color As Object) As Object
- Console.BackgroundColor = colour
- Console.Clear()
- Return True
- End Function
- Public Shared Function loadImage(ByVal path As String) As Object
- Dim line As String
- Dim data() As String = {}
- Dim choppedData() As String = {}
- Dim lImage() As Integer = {}
- Try
- If Not My.Computer.FileSystem.FileExists(path) Then
- Error "File does not exist"
- End If
- Using fs As New System.IO.StreamReader(path)
- line = fs.ReadLine()
- While line <> "" Or line <> Nothing
- ReDim Preserve data(data.Length + 2)
- data(data.Length - 2) = line
- data(data.Length - 1) = "|"
- line = fs.ReadLine()
- End While
- End Using
- Catch ex As Exception
- Console.WriteLine(ex.Message)
- End Try
- For i = 1 To data.Length - 1
- Dim lined As String = data(i)
- Try
- If lined = "|" Then
- ReDim Preserve choppedData(choppedData.Length)
- choppedData(choppedData.Length - 1) = "|"
- Else
- For o = 1 To lined.Length
- ReDim Preserve choppedData(choppedData.Length)
- choppedData(choppedData.Length - 1) = lined.Substring(o, 1)
- Next
- End If
- Catch ex As Exception
- End Try
- Next
- For i = 0 To choppedData.Length - 1
- If choppedData(i) <> Nothing Then
- ReDim Preserve lImage(lImage.Length)
- If choppedData(i) = " " Then
- lImage(lImage.Length - 1) = 16
- ElseIf choppedData(i) = "|" Then
- lImage(lImage.Length - 1) = 17
- Else
- lImage(lImage.Length - 1) = Convert.ToInt64(choppedData(i), 16)
- End If
- End If
- Next
- Return lImage
- End Function
- Public Shared Function drawImage(ByVal image As Object, ByVal x As Integer, ByVal y As Integer)
- Dim lines As Integer = 0
- Dim pos As Integer = 0
- If Not IsArray(image) Then
- Error "Array expected"
- End If
- For i = 0 To image.length - 1
- If image(i) <> 17 And image(i) = 16 Then
- pos += 1
- ElseIf image(i) <> 17 Then
- paintutils.drawPixel(x + pos, y + lines, image(i))
- pos += 1
- Else
- pos = 0
- lines += 1
- End If
- Next
- Return True
- End Function
- Public Shared Function drawPixel(ByVal x As Integer, ByVal y As Integer) As Object
- If x < 0 or x > Console.WindowWidth - 1 or y < 0 or x > Console.WindowHeight - 1 Then
- Return False
- Exit Function
- End If
- x = Math.Floor(x)
- y = Math.Floor(y)
- Console.BackgroundColor = ConsoleColor.White
- Console.SetCursorPosition(x - 1, y - 1)
- Console.Write(" ")
- Return True
- End Function
- Public Shared Function drawPixel(ByVal x As Integer, ByVal y As Integer, ByVal colour As Object) As Object
- If x < 0 or x > Console.WindowWidth - 1 or y < 0 or x > Console.WindowHeight - 1 Then
- Return False
- Exit Function
- End If
- x = Math.Floor(x)
- y = Math.Floor(y)
- Console.BackgroundColor = colour
- Console.SetCursorPosition(x, y)
- Console.Write(" ")
- Return True
- End Function
- Public Shared Function drawLine(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y1)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = x2
- End If
- Dim xDiff As Integer = maxX - minX
- Dim yDiff As Integer = maxY - minY
- If xDiff > Math.Abs(yDiff) Then
- Dim y As Integer = minY
- Dim dyy As Decimal = yDiff / xDiff
- For x = minX To maxX
- paintutils.drawPixel(x, Math.Floor(y + 0.5))
- y = y + dyy
- Next
- Else
- Dim x As Integer = minX
- Dim dxx As Decimal = xDiff / yDiff
- If maxY >= minY Then
- For y = minY To maxY
- paintutils.drawPixel(Math.Floor(x + 0.5), y)
- x = x + dxx
- Next
- Else
- For y = minY To maxY Step -1
- paintutils.drawPixel(Math.Floor(x + 0.5), y)
- x = x - dxx
- Next
- End If
- End If
- Return True
- End Function
- Public Shared Function drawLine(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal colour As Object) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y1)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = x2
- End If
- Dim xDiff As Integer = maxX - minX
- Dim yDiff As Integer = maxY - minY
- If xDiff > Math.Abs(yDiff) Then
- Dim y As Integer = minY
- Dim dyy As Decimal = yDiff / xDiff
- For x = minX To maxX
- paintutils.drawPixel(x, Math.Floor(y + 0.5), colour)
- y = y + dyy
- Next
- Else
- Dim x As Integer = minX
- Dim dxx As Decimal = xDiff / yDiff
- If maxY >= minY Then
- For y = minY To maxY
- paintutils.drawPixel(Math.Floor(x + 0.5), y, colour)
- x = x + dxx
- Next
- Else
- For y = minY To maxY Step -1
- paintutils.drawPixel(Math.Floor(x + 0.5), y, colour)
- x = x - dxx
- Next
- End If
- End If
- Return True
- End Function
- Public Shared Function setTextColour(ByVal colour As Object)
- Console.ForegroundColor = colour
- Return True
- End Function
- Public Shared Function setTextColor(ByVal color As Object)
- Console.ForegroundColor = color
- Return True
- End Function
- Public Shared Function setBackgroundColour(ByVal colour As Object) As Object
- Console.BackgroundColor = colour
- Return True
- End Function
- Public Shared Function setBackgroundColor(ByVal color As Object) As Object
- Console.BackgroundColor = color
- Return True
- End Function
- Public Shared Function drawBox(ByVal x1 As Decimal, ByVal y1 As Decimal, ByVal x2 As Decimal, ByVal y2 As Decimal, ByVal colour As Object) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y2, colour)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = y1
- End If
- For x = minX To maxX
- paintutils.drawPixel(x, minY, colour)
- paintutils.drawPixel(x, maxY, colour)
- Next
- If (maxY - minY) >= 2 Then
- For y = (minY + 1) To (maxY - 1)
- paintutils.drawPixel(minX, y, colour)
- paintutils.drawPixel(maxX, y, colour)
- Next
- End If
- Return True
- End Function
- Public Shared Function drawBox(ByVal x1 As Decimal, ByVal y1 As Decimal, ByVal x2 As Decimal, ByVal y2 As Decimal) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y2)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = y1
- End If
- For x = minX To maxX
- paintutils.drawPixel(x, minY)
- paintutils.drawPixel(x, maxY)
- Next
- If (maxY - minY) >= 2 Then
- For y = (minY + 1) To (maxY - 1)
- paintutils.drawPixel(minX, y)
- paintutils.drawPixel(maxX, y)
- Next
- End If
- Return True
- End Function
- Public Shared Function drawFilledBox(ByVal x1 As Decimal, ByVal y1 As Decimal, ByVal x2 As Decimal, ByVal y2 As Decimal, ByVal colour As Object) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y2, colour)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = y1
- End If
- For x = minX To maxX
- For y = minY To maxY
- paintutils.drawPixel(x, y, colour)
- Next
- Next
- Return True
- End Function
- Public Shared Function drawFilledBox(ByVal x1 As Decimal, ByVal y1 As Decimal, ByVal x2 As Decimal, ByVal y2 As Decimal) As Object
- x1 = Math.Floor(x1)
- y1 = Math.Floor(y1)
- x2 = Math.Floor(x2)
- y2 = Math.Floor(y2)
- If x1 = x2 And y1 = y2 Then
- paintutils.drawPixel(x1, y2)
- Return True
- Exit Function
- End If
- Dim minX As Integer = Math.Min(x1, x2)
- Dim minY As Integer
- Dim maxX As Integer
- Dim maxY As Integer
- If minX = x1 Then
- minY = y1
- maxX = x2
- maxY = y2
- Else
- minY = y2
- maxX = x1
- maxY = y1
- End If
- For x = minX To maxX
- For y = minY To maxY
- paintutils.drawPixel(x, y)
- Next
- Next
- Return True
- End Function
- End Class
Add Comment
Please, Sign In to add comment