Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Public Class Colour
- Public id As Char
- Public r As Integer
- Public g As Integer
- Public b As Integer
- Public Sub New(i As Char, red As Integer, green As Integer, blue As Integer)
- id = i
- If (r > 255 Or r < 0 Or g > 255 Or g < 0 Or b > 255 Or b < 0) Then
- Throw New ArgumentOutOfRangeException("r, g and b values must all be 0-255")
- End If
- r = red
- g = green
- b = blue
- End Sub
- Public Function getRed()
- Return r
- End Function
- Public Function getGreen()
- Return g
- End Function
- Public Function getBlue()
- Return b
- End Function
- Public Function getId()
- Return id
- End Function
- Public Function getColor()
- Return Color.FromArgb(r, g, b)
- End Function
- Public Function diff(c As Color)
- Dim rd = Math.Abs(r - c.R)
- Dim gd = Math.Abs(g - c.G)
- Dim bd = Math.Abs(b - c.B)
- Dim d = rd + gd + bd
- Dim s As String = "Comparing colour of (R:" & r & " G:" & g & " B:" & b & ") to colour of (R:" & c.R & " G:" & c.G & " B:" & c.B & ") produced rd of " & rd & ", gd of " & gd & " and bd of " & bd & " for a total diff of " & d
- 'System.Console.WriteLine(s)
- Return d
- End Function
- End Class
- Public zero As Colour = New Colour("0"c, 0, 0, 0)
- Public cola As Colour = New Colour("a"c, 9, 216, 157)
- Public colb As Colour = New Colour("b"c, 19, 177, 59)
- Public colc As Colour = New Colour("c"c, 29, 137, 216)
- Public cold As Colour = New Colour("d"c, 39, 98, 118)
- Public cole As Colour = New Colour("e"c, 49, 59, 19)
- Public colf As Colour = New Colour("f"c, 59, 19, 177)
- Public colg As Colour = New Colour("g"c, 68, 236, 78)
- Public colh As Colour = New Colour("h"c, 78, 196, 236)
- Public coli As Colour = New Colour("i"c, 88, 157, 137)
- Public colj As Colour = New Colour("j"c, 98, 118, 39)
- Public colk As Colour = New Colour("k"c, 108, 78, 196)
- Public coll As Colour = New Colour("l"c, 118, 39, 98)
- Public colm As Colour = New Colour("m"c, 128, 0, 0)
- Public coln As Colour = New Colour("n"c, 137, 216, 157)
- Public colo As Colour = New Colour("o"c, 147, 177, 59)
- Public colp As Colour = New Colour("p"c, 157, 137, 216)
- Public colq As Colour = New Colour("q"c, 167, 98, 118)
- Public colr As Colour = New Colour("r"c, 177, 59, 19)
- Public cols As Colour = New Colour("s"c, 187, 19, 177)
- Public colt As Colour = New Colour("t"c, 196, 236, 78)
- Public colu As Colour = New Colour("u"c, 206, 196, 236)
- Public colv As Colour = New Colour("v"c, 216, 157, 137)
- Public colw As Colour = New Colour("w"c, 226, 118, 39)
- Public colx As Colour = New Colour("x"c, 236, 78, 196)
- Public coly As Colour = New Colour("y"c, 246, 39, 98)
- Public colz As Colour = New Colour("z"c, 255, 255, 255)
- Dim cs() As Colour = {zero, cola, colb, colc, cold, cole, colf, colg, colh, coli, colj, colk, coll, colm, coln, colo, colp, colq, colr, cols, colt, colu, colv, colw, colx, coly, colz}
- Public str As String = ""
- Public dlg As OpenFileDialog = New OpenFileDialog()
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn.Click
- dlg.ShowDialog()
- If (dlg.FileName <> "") Then
- dlg.FileName = dlg.FileName.ToLower()
- If (dlg.FileName.EndsWith(".bmp") Or dlg.FileName.EndsWith(".jpg") Or dlg.FileName.EndsWith(".jpeg") Or dlg.FileName.EndsWith(".gif") Or dlg.FileName.EndsWith(".png") Or dlg.FileName.EndsWith(".tiff")) Then
- img.Image = Image.FromFile(dlg.FileName)
- Dim i As Bitmap = img.Image
- If (i.Width <> i.Height) Then
- MessageBox.Show("Image is not square, will not work properly with !songtopic. You may continue, but command won't produce desired image")
- ElseIf (i.Width > 44 Or i.Height > 44) Then
- MessageBox.Show("Image is too large to be sent via discord! You may continue, but command will be unusable (Command limit is 44x)")
- End If
- End If
- End If
- calc()
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.Text = "!songtopic-inator"
- dlg.Title = "Open Image"
- dlg.Filter = "Supported Image Files|*.bmp;*.jpg;*.jpeg;*.gif;*.png;*.tiff"
- img.SizeMode = PictureBoxSizeMode.Zoom
- End Sub
- Private Sub tick_Tick(sender As Object, e As EventArgs) Handles tick.Tick
- 'calc()
- End Sub
- Private Sub whitecb_CheckedChanged(sender As Object, e As EventArgs) Handles whitecb.CheckedChanged
- calc()
- End Sub
- Public Sub calc()
- str = ""
- If (dlg.FileName <> "") Then
- dlg.FileName = dlg.FileName.ToLower()
- If (dlg.FileName.EndsWith(".bmp") Or dlg.FileName.EndsWith(".jpg") Or dlg.FileName.EndsWith(".jpeg") Or dlg.FileName.EndsWith(".gif") Or dlg.FileName.EndsWith(".png") Or dlg.FileName.EndsWith(".tiff")) Then
- img.Image = Image.FromFile(dlg.FileName)
- Dim i As Bitmap = img.Image
- lbl.Text = i.Size.ToString()
- For y As Integer = 0 To i.Height - 1
- System.Console.WriteLine("y: " & y)
- For x As Integer = 0 To i.Width - 1
- Dim d = 255 + 255 + 255
- Dim c As Colour = zero
- If (i.GetPixel(x, y).A = 0) Then
- If (whitecb.Checked) Then
- c = colz
- Else
- c = zero
- End If
- Else
- For Each col In cs
- Dim nd = col.diff(i.GetPixel(x, y))
- 'System.Console.WriteLine("x: " & x & " y: " & y & " testing colour " & col.getId() & " returned diff of " & nd)
- If (nd < d) Then
- d = nd
- c = col
- End If
- Next
- End If
- 'System.Console.WriteLine("x: " & x & " y: " & y & " colour " & c.getId() & " passed with a diff of " & d)
- str = String.Concat(str, c.getId())
- 'System.Console.WriteLine(str)
- Next
- Next
- test.Text = "!songtopic " & str
- Else
- MessageBox.Show("File selected is not an image or is an unsupported file format.")
- dlg.ShowDialog()
- End If
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement