Discussion:
Is there a way to find a lighter and darker shade of a RGB color programmatically?
Keith (Gulf Breeze Ortho Lab)
2012-02-15 11:15:58 UTC
Permalink
Hi All,

I have a problem... If a user selects a color and I put it into a variable (as RGB), how can I find a shade that is several shades lighter, and a shade that is several shades darker, also in RGB format?

For example, I put 0,255,64 into myVar. (This color a shade of green.) Programmatically, how can I find a shade that is several shades lighter in green and a shade that is several shades darker in green from this base color?

(By the way... Is there a way in LiveCode to determine the hue of a color and change the value?)

Any help would be most appreciated...

Thanks!

- Boo
Ken Corey
2012-02-15 11:25:16 UTC
Permalink
Post by Keith (Gulf Breeze Ortho Lab)
I have a problem... If a user selects a color and I put it into a variable (as RGB), how can I find a shade that is several shades lighter, and a shade that is several shades darker, also in RGB format?
Here are a few approaches:
http://goo.gl/RrzKD

-Ken
Keith Clarke
2012-02-15 11:26:38 UTC
Permalink
...not sure if this helps but perhaps one way might be to emulate the colour tools palette, by transforming the RGB values to/from HSB and then vary the saturation and/or brightness values.

I guess it depends what you mean by the term 'shade'? And of course, how to transform the values would be a different question! ;-)
Best,
Keith..
Post by Keith (Gulf Breeze Ortho Lab)
Hi All,
I have a problem... If a user selects a color and I put it into a variable (as RGB), how can I find a shade that is several shades lighter, and a shade that is several shades darker, also in RGB format?
For example, I put 0,255,64 into myVar. (This color a shade of green.) Programmatically, how can I find a shade that is several shades lighter in green and a shade that is several shades darker in green from this base color?
(By the way... Is there a way in LiveCode to determine the hue of a color and change the value?)
Any help would be most appreciated...
Thanks!
- Boo
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Paul Hibbert
2012-02-15 12:53:37 UTC
Permalink
Hey Keith,

One site that could help you is Scott Rossi's tactilemedia.com he has some great tutorials and the 'Color Slider' tutorial should give you all the info you need to convert your colour data into HSB (HSL), then you can just compare the brightness values and respond accordingly.

The tutorial page is here; http://www.tactilemedia.com/site_files/software/tutorials.html

Paul
Post by Keith (Gulf Breeze Ortho Lab)
Hi All,
I have a problem... If a user selects a color and I put it into a variable (as RGB), how can I find a shade that is several shades lighter, and a shade that is several shades darker, also in RGB format?
For example, I put 0,255,64 into myVar. (This color a shade of green.) Programmatically, how can I find a shade that is several shades lighter in green and a shade that is several shades darker in green from this base color?
(By the way... Is there a way in LiveCode to determine the hue of a color and change the value?)
Any help would be most appreciated...
Thanks!
- Boo
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Bob Sneidar
2012-02-15 17:07:27 UTC
Permalink
Seems to me you could add 10% to each of the RGB values by multiplying each by 1.1, then round them up. (A roundUp function can be made by div'ing a value by itself, then adding the mod of a value by itself and conditionally adding 1 if the mod is not 0). That would give you the shade lighter. Dividing the values by 1.1 would give you a shade darker. But that is just me conjecturing off the top of my head.

Bob
Post by Keith (Gulf Breeze Ortho Lab)
Hi All,
I have a problem... If a user selects a color and I put it into a variable (as RGB), how can I find a shade that is several shades lighter, and a shade that is several shades darker, also in RGB format?
For example, I put 0,255,64 into myVar. (This color a shade of green.) Programmatically, how can I find a shade that is several shades lighter in green and a shade that is several shades darker in green from this base color?
(By the way... Is there a way in LiveCode to determine the hue of a color and change the value?)
Any help would be most appreciated...
Thanks!
- Boo
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Keith (Gulf Breeze Ortho Lab)
2012-02-15 20:59:41 UTC
Permalink
Thanks Bob and Paul!

FYI: You might want to take a look at the posting (on the forum) by Bernd:

http://forums.runrev.com/phpBB2/viewtopic.php?f=10&t=11100&p=51931#p51931

I appreciate the wonderful help from the LiveCode community!

Sincerely,

- Boo

-----Original Message-----
From: Bob Sneidar
Sent: Wednesday, February 15, 2012 11:07 AM
To: How to use LiveCode
Subject: Re: Is there a way to find a lighter and darker shade of a RGB
colorprogrammatically?

Seems to me you could add 10% to each of the RGB values by multiplying each
by 1.1, then round them up. (A roundUp function can be made by div'ing a
value by itself, then adding the mod of a value by itself and conditionally
adding 1 if the mod is not 0). That would give you the shade lighter.
Dividing the values by 1.1 would give you a shade darker. But that is just
me conjecturing off the top of my head.

Bob
Post by Keith (Gulf Breeze Ortho Lab)
Hi All,
I have a problem... If a user selects a color and I put it into a variable
(as RGB), how can I find a shade that is several shades lighter, and a
shade that is several shades darker, also in RGB format?
For example, I put 0,255,64 into myVar. (This color a shade of green.)
Programmatically, how can I find a shade that is several shades lighter in
green and a shade that is several shades darker in green from this base
color?
(By the way... Is there a way in LiveCode to determine the hue of a color
and change the value?)
Any help would be most appreciated...
Thanks!
- Boo
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Wilhelm Sanke
2012-02-16 19:15:20 UTC
Permalink
On Wed Feb, 2012, Keith (Gulf Breeze Ortho Lab) keith at
Post by Keith (Gulf Breeze Ortho Lab)
Hi All,
I have a problem... If a user selects a color and I put it into a
variable (as RGB), how can I find a shade that is several shades
lighter, and a shade that is several shades darker, also in RGB format?
For example, I put 0,255,64 into myVar. (This color a shade of green.)
Programmatically, how can I find a shade that is several shades
lighter in green and a shade that is several shades darker in green
from this base color?
(By the way... Is there a way in LiveCode to determine the hue of a
color and change the value?)
Any help would be most appreciated...
Thanks!
- Boo
The revcolorchooser stack (in folder Toolsets) contains the old
conversion scripts of Scott Raney "function RGBtoHSV r, g, b" and - the
other way round - "function HSVtoRGB h, s, v" (in group "HSV").

Convert you RGB color to HSV and to darken or brighten, just change the
V-value. For changing the hue values, use H.
Then convert your values back to RGB.
These procedures work rather slowly when you work with whole images and
not a single color.


A much faster solution is using "Quasimondo RGB-to-HSL and HSL-to-RGB
conversions"
<http://quasimondo.com/> and article "Converting RGB to HSL differently".
For brightening and darkening use the "luminance" value L.

Finally you could use my "brighten/darken" button of my old "Imagedata
Toolkit" <http://www.sanke.org/software/ImagedataToolkitPreview3.zip>

Best regards,

Wilhelm Sanke

Loading...