Results 1 to 8 of 8

Thread: How do I change color value to create a rainbow?

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,665

    How do I change color value to create a rainbow?

    What I'm trying to accomplish is creating a "Reputation" Bar with a range of 0-100 that changes color depending on the value.

    On the bad end (0) I want a dark, brooding color or a bright (YOU DIED!) kind of color. So maybe a dark maroon or a bright red or something like that.

    On the good end (100) I want something happy and cheerful like a bright green or blue or something.

    I'm pretty for-sure that color values don't work anything like I want them to.

    So what I'm trying to do is something like this.

    It works at the ends but it doesn't work in the middle where everything turns dark and muddy.

    I've tried various combinations of colors using the Color Constants (vbRed, vbBlue, etc.).

    Usually vbCyan as GOOD_COLOR and vbRed as BAD_COLOR.

    No matter what combination I choose, the middle doesn't work.

    So ultimately, it's not this I want to fix. I just want to accomplish the thing where I achieve a nice blend between the two colors. But it's not a blend. It's a solid color. The color should be part of a nice blend is what I'm saying.

    Code:
    Private Sub UpdateReputationBar
    Const GOOD_COLOR As Long = &HFF00& ' A green color.
    Const BAD_COLOR as Long = &H8080FF ' A red color.
    
    
    linReputation.BorderColor = BAD_COLOR + (((GOOD_COLOR - BAD_COLOR) * Player.Reputation) / REPUTATION_CAP)
    
    
    End Sub

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,074

    Re: How do I change color value to create a rainbow?

    You have to split the color value in the individual R,G,B components.
    Then use the scaling algorithm on one or more of the components.

  3. #3

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,665

    Re: How do I change color value to create a rainbow?

    Thanks. I have no idea how to do that though. Guess I'll ask my friends at The Googles again.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,074

    Re: How do I change color value to create a rainbow?

    Example
    Code:
    lngColor = &H00C0FFFF&
     
    Red = (lngColor And &HFF)
    Green = (lngColor And &HFFFF&) / &H100
    Blue = (lngColor And &HFFFFFF) / &H10000

  5. #5

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,665

    Re: How do I change color value to create a rainbow?

    OK, but then my problem is I have no idea what to do with that?

    Just divide all the colors by the ratio in my original post and put them back together? I obviously don't do color manipulation.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,074

    Re: How do I change color value to create a rainbow?

    First define what your left and right most color will be.
    Then you can use a gradient to go from color Left to color Right.

    Check this sample (and the rest of the posts in the thread)
    https://www.vbforums.com/showthread....=1#post5542027

  7. #7

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,665

    Re: How do I change color value to create a rainbow?

    Thank you very much.

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,074

    Re: How do I change color value to create a rainbow?

    And if you want multiple colors, like red - yellow - green, then you have to use 2 gradients
    red - yellow and then yellow - green

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