Page 1 of 2

is a color

Posted: Wed Feb 14, 2018 2:38 am
by gmccarthy
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?

Re: is a color

Posted: Wed Feb 14, 2018 3:41 am
by bogs
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.

Re: is a color

Posted: Wed Feb 14, 2018 10:13 am
by FourthWorld
What happens if you attempt to set the color of an object to that value?

Re: is a color

Posted: Wed Feb 14, 2018 10:51 am
by richmond62
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.

Re: is a color

Posted: Wed Feb 14, 2018 11:15 am
by gmccarthy
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.

Re: is a color

Posted: Wed Feb 14, 2018 4:33 pm
by [-hh]
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.

Re: is a color

Posted: Wed Feb 14, 2018 5:40 pm
by bogs
Makes sense to me. Sure glad you could explain it, cause I know I wouldn't have been able to.

Re: is a color

Posted: Wed Feb 14, 2018 6:43 pm
by richmond62
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)

Re: is a color

Posted: Wed Feb 14, 2018 7:26 pm
by [-hh]
@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).]

Re: is a color

Posted: Wed Feb 14, 2018 9:19 pm
by bogs
[-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

Re: is a color

Posted: Wed Feb 14, 2018 9:31 pm
by gmccarthy
hh, could you add something about that to the dictionary?

Re: is a color

Posted: Thu Feb 15, 2018 6:48 pm
by richmond62
hh, could you add something about that to the dictionary?
Red wine or whacky baccy?

Re: is a color

Posted: Thu Feb 15, 2018 8:13 pm
by bogs
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

Re: is a color

Posted: Fri Feb 16, 2018 3:24 am
by mwieder
Schrodinger's glass is half-empty *and* half-full until the winefunction collapses.

Re: is a color

Posted: Fri Feb 16, 2018 4:42 am
by bogs
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: