|
-
May 21st, 2024, 02:49 AM
#1
Thread Starter
PowerPoster
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
-
May 21st, 2024, 03:04 AM
#2
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.
-
May 21st, 2024, 03:06 AM
#3
Thread Starter
PowerPoster
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.
-
May 21st, 2024, 03:10 AM
#4
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
-
May 21st, 2024, 03:11 AM
#5
Thread Starter
PowerPoster
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.
-
May 21st, 2024, 04:36 AM
#6
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
-
May 21st, 2024, 04:38 AM
#7
Thread Starter
PowerPoster
Re: How do I change color value to create a rainbow?
-
May 21st, 2024, 05:01 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|