PDA

View Full Version : [mel]rnd rotate 'y', but with snapping?


Sorath
01-19-2011, 01:32 PM
hey peeps.

I made this.. maybe someone could use that..
now I need to actually rotate by steps like, 90degree steps.
Any Idea anyone?

string $sel[] = `ls -sl`; print $sel;
float $yran = 0;
for($i = 0; $i < size ($sel); $i++){
$yran = rand(0.2, 260);
rotate 0 ($yran) 0 $sel[$i];
}


thanks bastian

pixelranger
01-19-2011, 01:53 PM
You could add a multiplier (example with step size of 30 degrees):


string $sel[] = `ls -sl`; print $sel;
float $yran = 0;
float $step = 30;
for($i = 0; $i < size ($sel); $i++){
$yran = floor(rand(0, 10) + 0.5) * $step;
rotate 0 ($yran) 0 $sel[$i];
}

Sorath
01-19-2011, 02:04 PM
you're my hero, thx!
the floor thing is nice.. was also searching for a round thing for some time :)

denisT
01-19-2011, 02:52 PM
... was also searching for a round thing for some time


global proc float roundFloat (float $f, float $precision)
{
$f /= $precision;
float $f1 = floor($f);
float $f2 = ceil($f);
float $v = (($f - $f1) > ($f2 - $f)) ? $f2 : $f1;
return ($v*$precision);
}
roundFloat 72 90
// Result:90//
roundFloat 72 30
// Result:60//

Sorath
01-19-2011, 03:02 PM
wohoo! thx denis.

CGTalk Moderation
01-19-2011, 03:02 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.