is a color

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

gmccarthy
Posts: 62
Joined: Sat Feb 17, 2007 4:56 am
Location: Australia

is a color

Post by gmccarthy » Wed Feb 14, 2018 2:38 am

It tried testing input for "is a color"
I found "255,255,1000" returns true.
It this expected?
Should rgb colors return true when they have a value that is out of range, such as >255 for in individual value?
gmcrev

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: is a color

Post by bogs » Wed Feb 14, 2018 3:41 am

You might want to look at this lesson. In particular,
if pColorName is an RGB triplet, the function just returns that triplet, so we don't try to make sure that pColorName is a color name, just that it's some sort of valid color reference.
I suspect that 3 separated values = some sort of valid color reference.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: is a color

Post by FourthWorld » Wed Feb 14, 2018 10:13 am

What happens if you attempt to set the color of an object to that value?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: is a color

Post by richmond62 » Wed Feb 14, 2018 10:51 am

If one does something like this:

set the backGroundColor of graphic "MyShape" to 255,255,1000

it sets the backGroundColor of graphic "MyShape" to 255,255,235

for the rather obvious reason that 1000 - (3 x 255) = 235

This does not, however, explain why one ended up with 255,255,1000 in the first place.

gmccarthy
Posts: 62
Joined: Sat Feb 17, 2007 4:56 am
Location: Australia

Re: is a color

Post by gmccarthy » Wed Feb 14, 2018 11:15 am

I was testing to see if I need to do any custom validation for an input field for a color and just added a 0 to the end value, expecting it to be invalid.
Who was to know that "is a color" would allow rgb values out of range.
Further to that who would know that setting a backcolor to an rgb value that was out of range would work since it seems to do an automatic mod 255 on each numeric rgb value.

If someone knows exactly what is happening it would be nice to add this knowledge to the dictionary wherever RGBcolor parameters are mentioned.

A similar thing happens with dateitems which makes it very useful when performing numeric additions to individual values within RGB color and dateitems such that there is no need to worry about going out of range since it is taken care of automatically.
gmcrev

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: is a color

Post by [-hh] » Wed Feb 14, 2018 4:33 pm

Obviously we have:

Each comma delimited-list of three integers is a color.

This has its own logic:
The following color setting algorithm is used by LC for each input integer, making any input of three integers to a color.

If abs(<integer>) > 255 then it is taken modulo 255.
If the result or <integer> is negative then 255 is added.


Example.
"500,-1000,-1" is converted to the valid color "245,20,254" because
1. 500 mod 255 = 245,
2. -1000 mod 255 = -235 and -235 + 255=20,
3. -1 + 255 =254.

This may not be the conversion you want because you obviously think of
the cutting method min(255, max(0, <integer>)),
which would convert "500,-1000,-1" to "255,0,0".

But the LC modulo method makes also sense for some color handling procedures.
And the handling of negative integers in range [-255,-1] by adding 255 makes the same good sense as counting chars from the end of a string by using negative integers.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: is a color

Post by bogs » Wed Feb 14, 2018 5:40 pm

Makes sense to me. Sure glad you could explain it, cause I know I wouldn't have been able to.
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: is a color

Post by richmond62 » Wed Feb 14, 2018 6:43 pm

Sure glad you could explain it
I'm just glad I had a glass of rather decent red wine to hand when I read that posting 8)

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: is a color

Post by [-hh] » Wed Feb 14, 2018 7:26 pm

@Richmond.
A glass of wine is also for me good for thinking about colors ...
What was the fill of the glass after reading: 50% or -50%? Half full or half empty?

[@all.
What's nice with that is that the inverse of a color (r, g, b) is (-r, -g, -b),
where r,g,b are integers in range [0,255] and not equal to zero.
TMHO easier to understand for a child than (255-r, 255-g, 255-b).]
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: is a color

Post by bogs » Wed Feb 14, 2018 9:19 pm

[-hh] wrote:
Wed Feb 14, 2018 7:26 pm
richmond62 wrote:
Wed Feb 14, 2018 6:43 pm
bogs wrote:Sure glad you could explain it
I'm just glad I had a glass of rather decent red wine to hand when I read that posting 8)
@Richmond.
A glass of wine is also for me good for thinking about colors ...
What was the fill of the glass after reading: 50% or -50%? Half full or half empty?
I don't know about his glass, but my hookie was about 50% water and 150% whacky tobaccy
Image
Image

gmccarthy
Posts: 62
Joined: Sat Feb 17, 2007 4:56 am
Location: Australia

Re: is a color

Post by gmccarthy » Wed Feb 14, 2018 9:31 pm

hh, could you add something about that to the dictionary?
gmcrev

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: is a color

Post by richmond62 » Thu Feb 15, 2018 6:48 pm

hh, could you add something about that to the dictionary?
Red wine or whacky baccy?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: is a color

Post by bogs » Thu Feb 15, 2018 8:13 pm

richmond62 wrote:
Thu Feb 15, 2018 6:48 pm
hh, could you add something about that to the dictionary?
Red wine or whacky baccy?
Just picturing the entry in the dictionary under 'whackyTobaccy' made me shoot coffee from my nose Image
Image

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: is a color

Post by mwieder » Fri Feb 16, 2018 3:24 am

Schrodinger's glass is half-empty *and* half-full until the winefunction collapses.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: is a color

Post by bogs » Fri Feb 16, 2018 4:42 am

Is that the one where it doesn't collapse as long as you don't drink...erm...look at the glass? Or was that cats? Maybe I'm confuzzled :roll:
Image

Post Reply

Return to “Talking LiveCode”