|
-
Feb 10th, 2007, 12:55 AM
#10
Hyperactive Member
Re: Who wants to have some fun?
You can use this code (I used a picture box to change the color of, and a textbox to enter the string/color name):
VB Code:
Public Function colorRoundValueRGB(ByVal number As Long) As Long
'Set boundries
If number < 1 Then Return 1
If number <= 255 Then Return 255
'Find remaining placement value
Dim remain As Long = number - (255 * (Math.Floor(number / 255)))
If remain < 1 Then remain = 1
Return remain
End Function
Public Function colorRandomFromString(ByVal str As String) As Color
Dim lng As Long = 1
Dim r, g, b As Integer
For stp As Integer = 1 To str.Length
Try
lng *= CInt(AscW(Mid(str, stp, 1)))
Catch ex As Exception
If ex.Message.Contains("overflow") Then
lng = 1
End If
End Try
Next
If lng < 99999 Then
lng += ((99999 - lng) ^ 2)
End If
r = colorRoundValueRGB(CInt(Mid(CStr(lng), 1, 3)))
g = colorRoundValueRGB(CInt(Mid(CStr(lng), 2, 3)))
b = colorRoundValueRGB(CInt(Mid(CStr(lng), 3, 3)))
Return Color.FromArgb(r, g, b)
End Function
Works for me, anyway. Still gets a bit of red and green, but you get a bunch of other colors, too. And it stays the same each time. Funny, this actually made me create a "moduleColor.vb" module. I've been looking for something interesting to try out while waiting for a cooperative project I'm working on to take off. This did it!
Last edited by BrendanDavis; Feb 10th, 2007 at 01:06 AM.
God put me on this earth to do many great things, and I'm so far behind that I'm going to live forever.
I'm programming for Windows using a Apple Mac Mini, 1.5Ghz with 512MB DDR RAM. I feel like I'm committing a crime :P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|