Hi Matadem,
re:
> lets say I have 5 objects
> the first is white and the last one is black.....is there a way to get the shades in between
> That the next one is 20% darker and so on until it becomes black?
Paste this in as the "Command" part of a shortcut key:
code:
script:
/* Set color to gradient between first and last selected objects */
var start_r = 255;
var start_g = 255;
var start_b = 255;
var end_r = 0;
var end_g = 0;
var end_b = 0;
var objs = moi.geometryDatabase.getSelectedObjects();
if ( objs.length >= 2 )
{
var start_obj = objs.item(0);
var end_obj = objs.item( objs.length-1 );
var styles = moi.geometryDatabase.getObjectStyles();
var start_color = styles.item( start_obj.styleIndex ).color;
var end_color = styles.item( end_obj.styleIndex ).color;
start_r = ((start_color >> 16) & 0xFF);
start_g = ((start_color >> 8) & 0xFF);
start_b = ((start_color >> 0) & 0xFF);
end_r = ((end_color >> 16) & 0xFF);
end_g = ((end_color >> 8) & 0xFF);
end_b = ((end_color >> 0) & 0xFF);
}
function Lerp( t, low, high )
{
return low + ((high - low) * t);
}
function GetStyle( r, g, b )
{
var styles = moi.geometryDatabase.getObjectStyles();
for ( var i = 0; i < styles.length; ++i )
{
var style = styles.item(i);
this_r = ((style.color >> 16) & 0xFF);
this_g = ((style.color >> 8) & 0xFF);
this_b = ((style.color >> 0) & 0xFF);
if ( this_r == r && this_g == g && this_b == b )
{
return style;
}
}
return moi.geometryDatabase.addStyle( '', (r << 16) | (g << 8) | (b << 0) );
}
for ( var i = 0; i < objs.length; ++i )
{
var t = i / (objs.length-1);
var r = Math.round( Lerp( t, start_r, end_r ) );
var g = Math.round( Lerp( t, start_g, end_g ) );
var b = Math.round( Lerp( t, start_b, end_b ) );
if ( r == 0 && g == 0 && b == 0 )
{
r = 1;
}
var style = GetStyle( r, g, b );
var obj = objs.item(i);
obj.styleIndex = style.index;
}
- Michael
|