Results 1 to 12 of 12

Thread: Who wants to have some fun?

Threaded View

  1. #10
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    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:
    1. Public Function colorRoundValueRGB(ByVal number As Long) As Long
    2.  
    3.         'Set boundries
    4.         If number < 1 Then Return 1
    5.         If number <= 255 Then Return 255
    6.  
    7.         'Find remaining placement value
    8.         Dim remain As Long = number - (255 * (Math.Floor(number / 255)))
    9.  
    10.         If remain < 1 Then remain = 1
    11.  
    12.         Return remain
    13.  
    14.     End Function
    15.  
    16.     Public Function colorRandomFromString(ByVal str As String) As Color
    17.  
    18.         Dim lng As Long = 1
    19.         Dim r, g, b As Integer
    20.  
    21.         For stp As Integer = 1 To str.Length
    22.             Try
    23.                 lng *= CInt(AscW(Mid(str, stp, 1)))
    24.             Catch ex As Exception
    25.                 If ex.Message.Contains("overflow") Then
    26.                     lng = 1
    27.                 End If
    28.             End Try
    29.         Next
    30.  
    31.         If lng < 99999 Then
    32.             lng += ((99999 - lng) ^ 2)
    33.         End If
    34.  
    35.         r = colorRoundValueRGB(CInt(Mid(CStr(lng), 1, 3)))
    36.         g = colorRoundValueRGB(CInt(Mid(CStr(lng), 2, 3)))
    37.         b = colorRoundValueRGB(CInt(Mid(CStr(lng), 3, 3)))
    38.  
    39.         Return Color.FromArgb(r, g, b)
    40.  
    41.     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
  •  



Click Here to Expand Forum to Full Width