Syntax for random listing of rgb colors rather than Hex

231
2
02-03-2013 02:00 AM
NicolaiSteinø
Occasional Contributor
Hi,

When using listRandom() for colors, I can only make it work when formatting color names in Hex, not in rgb. For instance, this syntax will work:

attr facadeColor = listRandom("#AA9977;#999999;#BBBBBB;#CCBB99")

but will not:

attr facadeColor = listRandom("0.5,0.4,0.3;0.8,0.7,0.6;1,0.9,0.8")

What do I do wrong?

Regards,

Nic
0 Kudos
2 Replies
MatthiasBuehler1
Frequent Contributor II
Hi !

1] your list is a string list. so your values are basically text, not numbers.

so for each color channel value, you must 'cast' each value first into a float value by using float(). the other way around it's str().

2] BUT :

I'd rather do that thingy like this :

colorFunction (xyz) =
    33% : # color 1
        case xyz == "x" : 0.3
        case xyz == "y" : 0.3
        else                 : 0.3
    33% : # color 2
        case xyz == "x" : 0.4
        case xyz == "y" : 0.4
        else                 : 0.4
     else : # color 3
        case xyz == "x" : 0.5
        case xyz == "y" : 0.5
        else                 : 0.5

Lot -->
    color((colorFunction ("x")),(colorFunction ("y")),(colorFunction ("z")))


Didn't test the code. May contain errors.
0 Kudos
MatthiasBuehler1
Frequent Contributor II
btw ..

A very important note is that :

Lot -->
    color ( rand(1), rand(1), rand(1) )


Creates a very large amount of different materials which may kill any 3d application in which you try to import the 3d model after export. So NEVER use random colors .

Rather use (or similar) :

const color1Value = rand(1)
0 Kudos