question

Anna Lisa Dierking avatar image
1 Like"
Anna Lisa Dierking asked Joerg Vogel answered

Colors used with Color.ByNumber

Hi,

in the screenshot below you can see a Queue with 10,000 boxes in it. I used the Color.ByNumber(item.Number) function to color the boxes with item.number being a counter label.

Is there any reason why the color pattern looks like this with all the yellow and blue? Would it be possible to have more variety?

FlexSim 17.1.4
color changecolor palette
colorarray.png (638.5 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matt Long avatar image
4 Likes"
Matt Long answered Jeff Nordgren edited

@Anna Lisa Dierking

This is actually a bug that was introduced with the new Color class. We'll get this fixed for the next bug fix release. It should look more like this:


colorbynumber.png (315.9 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sam Stubbs avatar image
3 Likes"
Sam Stubbs answered Mischa Spelt commented

If you look at the Color.ByNumber entry in the User Manual it explains this phenomenon:

Returns a color by a uniquely identifying number.

item.color = Color.byNumber(item.labelVal);

The number passed in refers to an index in the standard colors spectrum, as follows:

1 - red
2 - green
3 - blue
4 - yellow
5 - orange
6 - purple
7 - lime
8 - pink
9 - gray
10 - teal
11 - aqua
12 - brown
13 - light blue
14 - silver
15 - white
16 - gold

For numbers above 16, a unique color will generated based on an algorithm.

IF you want unique colors for each of your item types beyond 16, I'd recommend that something like assigning those colors/item Types in a GlobalTable, and then assign your items' Types and colors based on the table.

· 9
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Anna Lisa Dierking avatar image Anna Lisa Dierking commented ·

@Sam Stubbs

"For numbers above 16, a unique color will generated based on an algorithm."

In the screenshot, you can see the colors generated by the numbers 1 up to 10,000. Beyond 16 (up to 10,000) all the colors generated are in the blue and yellow spectrum.

So do I need to use a different command to generate for example a light green, dark red or light pink?

And where/how do I find the Color.ByNumber entry in the User Manual?

0 Likes 0 ·
Jeff Nordgren avatar image Jeff Nordgren Anna Lisa Dierking commented ·

@Anna Lisa Dierking

You can find it in the User Manual under FlexSim Coding>FlexScript Class Reference>Color, Then down at the bottom of the page by clicking on byNumber.

Could it be that your flowitems are so small that the individual colors can't show on the monitor? I can't tell from your graphic exactly what it is showing. How many are there in the queue? The graphic itself doesn't tell me a lot. How are you using the Color byNumber command?

0 Likes 0 ·
Anna Lisa Dierking avatar image Anna Lisa Dierking Jeff Nordgren commented ·

Thanks for the directions.

The picture shows 10,000 boxes in a queue from the bird's perspective.

I attached a model this time. Every second a new item enters the queue with a label "Number" (a counter so that box 1 has the label value 1; box 2 has the label value 2 and so on) and color according to Color.ByNumber(item.Number).

colorarray.fsm

0 Likes 0 ·
colorarray.fsm (13.7 KiB)
Show more comments
Anna Lisa Dierking avatar image Anna Lisa Dierking commented ·

@Jörg Vogel Thanks for showing your approach.

I was just a little disappointed in the Color.ByNumber command because the random unique color generated based on the algorithm does not really look that unique to me.

0 Likes 0 ·
Sam Stubbs avatar image Sam Stubbs ♦ Anna Lisa Dierking commented ·

Yeah, I haven't used it on things beyond 16 very much so I don't know. Like I said, a common thing I've seen is to have a table with a row for each item type. With one column that the item or part number, and another that has a color in it. Then you just assign the item color by a Table lookup.

0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt Anna Lisa Dierking commented ·

I just wanted to point out that the problem is, for the most part, with human perception and not with the algorithm. I actually made a table of the first 500 colors and there are no exact duplicates in there, so the algorithm does actually generate unique colors. The problem is that our eye is quite bad in distinguishing between similar shades of the same color. For example, color index 379 (RGB 134, 134, 74) and 455 (148, 148, 52) have quite different RGB values but if you put them side by side they look quite similar. I think even when you did it manually you'd be hard pressed to come up with, say, 20 to 30 really clearly distinct colors; not even mentioning that the color-generating algorithm has some limitations: for example you don't want it to generate colors that are too light or too dark which is restricting the color space you can use even further. So not to say that the algorithm cannot be better, just to put it into perspective how hard it is to find one to generate a well-distinguishable yet unique palette.

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

Your own bynumber method consists of the approach to create a string array. The string contains the function to create a color out of its color components.

Each time you need a color of your colors you execute a string of the array.

Global variable array myColor

Color(0.1, 0.0, 0.9)

Color(0.0, 0.0, 0.5)

Set a color by number of myColor

item.color = executestring(myColor[1]);
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.