PDA

View Full Version : randomize RGB values from array list?


Luddy
06-25-2007, 08:14 AM
I'm trying to randomize a ball's color using only 3 set RGB values. How would I use "rand" in a loop to do this? Thanks-

//---
//rgb(1 0 0) //Red
//rgb(0 1 0) //Green
//rgb(0 0 1) //Blue
//setAttr ($shader + ".color") -type double3 $randomSet;
//rand
//---
sphere -n ball;

string $shader = `shadingNode -n ballColor -asShader blinn`;
setAttr ($shader + ".color") -type double3 0 1 0;
setAttr ($shader + ".eccentricity") 0.25;
setAttr ($shader + ".specularRollOff") 0.75;
string $shadingGroup = ($shader + "SG");
sets -renderable true -noSurfaceShader true -empty -name $shadingGroup;
defaultNavigation -connectToExisting -source $shader -destination $shadingGroup;

isoparmB
06-26-2007, 04:22 AM
This will create a new ball with a random colored shader every time you execute it. string $randColor[] = string $randColor[] = {"1 0 0", "0 1 0", "0 0 1"};
int $colorIndex = rand(0,3);

string $ball[] = `sphere -n "ball#"`;

string $shader = `shadingNode -n "ballColor#" -asShader blinn`;
eval ("setAttr " + $shader + ".color -type double3 " + $randColor[$colorIndex]);
setAttr ($shader + ".eccentricity") 0.25;
setAttr ($shader + ".specularRollOff") 0.75;
string $shadingGroup = ($shader + "SG");
sets -renderable true -noSurfaceShader true -empty -name $shadingGroup;
defaultNavigation -connectToExisting -source $shader -destination $shadingGroup;
select -r $ball[0];
sets -e -forceElement $shadingGroup;

Luddy
06-26-2007, 09:58 AM
Thanks, I actually wanted preset Shaders. Then apply a random preset shader to object faces. Got it to work after a while. :thumbsup:

kyrga
06-27-2007, 07:24 PM
Sorry to hijak your thread, but how would I do the same thing, except make it not random? For example, if I wanted them to be red, then green, then blue, then just repeat that pattern?

CGTalk Moderation
06-27-2007, 07:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.