is a color

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

is a color

Post by Zax » Wed Apr 10, 2024 11:45 am

I'm a little confused about the results of "is a color" in LC 9.6.11
According to the inline dictionary example, "red" is indeed a color but I have doubts about the relevance of 4520 for example.
In my opinion, 4520 is more of an integer.

returns YES

Code: Select all

if 4520 is a color then put "YES" else put "NO"
if "4520" is a color then put "YES" else put "NO"
if 0 is a color then put "YES" else put "NO"
if "0" is a color then put "YES" else put "NO"
returns NO

Code: Select all

if "" is a color then put "YES" else put "NO"

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: is a color

Post by richmond62 » Wed Apr 10, 2024 11:51 am

Maybe colours have numbers assigned to them.

Mind you 4250 does NOT look like an rgb code.
Last edited by richmond62 on Wed Apr 10, 2024 8:02 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: is a color

Post by Klaus » Wed Apr 10, 2024 12:08 pm

Code: Select all

set the backcolor of btn 1 to 4520
Results in BLACK, RGB 0,0,0

Code: Select all

set the backcolor of btn 1 to 0815
Results in BLACK, RGB 0,0,0

However:

Code: Select all

set the backcolor of btn 1 to 125889963
Results in WHITE, RGB 255,255,255

Obiously LC treats all (not RGB or Hex) numbers < XXX as BLACK and
all numbers >= XXX to white. But what might the value of XXX be? :-D

Best

Klaus

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: is a color

Post by Zax » Wed Apr 10, 2024 12:37 pm

I suppose it's for vanilla Hypercard compatibility: what is not white is black :P 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: is a color

Post by dunbarx » Wed Apr 10, 2024 1:52 pm

Now I am confused. The dictionary states:
Colors can be referred to by color name, HTML -style specification, or as three comma-separated numbers between zero and 255 (one for each of red, blue, and green).
so "red" would do here, as would "222,111,000"
Where do we get the idea that an integer belongs to any of the above criteria?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: is a color

Post by richmond62 » Wed Apr 10, 2024 1:57 pm

Where do we get the idea that an integer belongs to any of the above criteria?
I didn't get that idea.

But the proof of the pudding is in the eating.

Doing something like this:

Code: Select all

on mouseDown
   set the backGroundColor of grc "xyz" to 231
end mouseDown
ends up with this:
-
Screenshot 2024-04-10 at 15.59.53.png
-

interestingly enough this:

Code: Select all

on mouseDown
   set the backGroundColor of grc "xyz" to 200, 45
end mouseDown
throws a bluey.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: is a color

Post by bn » Wed Apr 10, 2024 10:18 pm

richmond62 wrote:
Wed Apr 10, 2024 1:57 pm

Code: Select all

on mouseDown
   set the backGroundColor of grc "xyz" to 231
end mouseDown
The other day I stumbled across this hidden feature.
You can indicate a color as a single digit from 0 to 255
Probably a remnant of 256 color monitors.

Code: Select all

on mouseUp
   local tHeight, tWidth, tName, tColorCounter
   reset the templateGraphic
   set the rect of the templateGraphic to 0,0,10,10
   set the style of the templateGraphic to "Rectangle"
   set the opaque of the templateGraphic to true
   put 10 into tHeight
   put 10 into tWidth
   put 0 into tColorCounter
   repeat with i = 0 to 15
      repeat with j = 0 to 15
         put "g" & tColorCounter into tName
         create graphic tName
         set the backgroundcolor of graphic tName to tColorCounter
         add 1 to tColorCounter
         set the left of graphic tName to j * tWidth
         set the top of graphic tName to i * tHeight
      end repeat
   end repeat
end mouseUp
gives you a 16 by 16 color table with colors from 0 to 255

Kind regards
Bernd

Edit: see also
export image [with metadata metadata] to {file filePath | container} as {gif | png} with colorCount color [optimized] palette

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: is a color

Post by dunbarx » Thu Apr 11, 2024 2:38 pm

All.

I opened another thread here, "Strange Colors", which should have been an extension of this thread. It was due to an error I made as regards another forum.

Perhaps these two can be joined together?

Craig

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: is a color

Post by Zax » Thu Apr 11, 2024 3:27 pm

I understand a color can be defined as a single digit from 0 to 255 but but I still think that the "is a color" test returning true for an integer is not very useful and can even lead to errors.
Or else, a sort of “is an RGB color” test should be implemented.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: is a color

Post by richmond62 » Thu Apr 11, 2024 3:48 pm

If the "is a color" test returned 'Yes' for numbers only between 0 and 255/6 that might make a bit more sense.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: is a color

Post by dunbarx » Thu Apr 11, 2024 4:29 pm

No.

Simply update the dictionary to include that format as a valid reference. Then the "is a" no longer causes angst.

What the integers refer to is another story since only a tiny fraction of colors (255 out of sixteen million) are included, and there seems little method to them. Bernd is likely correct in stating that it is a forgotten leftover from early days.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: is a color

Post by richmond62 » Thu Apr 11, 2024 4:56 pm

SShot 2024-04-11 at 12.09.15.png
-
Seemingly pretty random.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: is a color

Post by dunbarx » Thu Apr 11, 2024 5:26 pm

Richmond.
Seemingly pretty random.
No, look at your display again. There is a pattern that repeats, sort of, every 36 integer values. My stack output shows this, and your color display does as well, just graphically. Find the "white" squares. You can see six groups in succession, even though those groups are not quite the same. And after 216, the start of the seventh group, all bets are off, the sequences go off the rails.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: is a color

Post by richmond62 » Thu Apr 11, 2024 7:03 pm

It would be interesting to know the numbers and colours way back when we all thought that sixteen squared was a vast number.

And, Yes, there is a sort of periodicity visible in my snapshot.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: is a color

Post by dunbarx » Thu Apr 11, 2024 7:16 pm

Richmond.

The real question is "why 36"? It really does not matter, since a mapping is a mapping, but there seems no binary pattern involved.

Craig

Post Reply