Ronald Fong Zebra Ramp

Quick colors in Maya Ramp

It’s very time-consuming to manually create many ramp entries in Maya’s ramp node, so I wrote a little script.
This simple function can be useful to create a procedural circular brushed metal texture where we want a hundred alternating colors.

//Author: Ronald Fong
//Date: 03 June 2018
global proc rf_zebraRamp(int $count) {
    $ramp = `ls -sl`;
    //Clear existing entries    
    int $entries = `getAttr -size ($ramp[0] + ".colorEntryList")`;
    for ($i=0; $i<$entries; $i++) {
        removeMultiInstance -break true ($ramp[0] + ".colorEntryList[" + $i + "]");
    }
    
    //Set alternate colors
    $currCol = 0; //Initialize current color
    for ($i=1; $i<$count+1; $i++) {
        $div = 1.0 / $count;
        $currDiv = $div * $i;
        $prevCol = `getAttr ($ramp[0] + ".colorEntryList[" + ($i-1) + "].color")`;
        setAttr ($ramp[0] + ".colorEntryList[" + ($i-1) + "].color") -type double3 $prevCol[0] $prevCol[0] $prevCol[0]; //Flush previous color
        if ($prevCol[0] == 0) {
            $currCol = 1;
        }
        else if ($prevCol[0] == 1) {
            $currCol = 0;
        }
        //print ($div + " " + $i + " " + $prevCol[0] + "\n");
        setAttr ($ramp[0] + ".colorEntryList[" + $i + "].color") -type double3 $currCol $currCol $currCol;
        setAttr ($ramp[0] + ".colorEntryList[" + $i + "].position") $currDiv;
    }
}
rf_zebraRamp("10");
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *