George's Pizza Shop
Our buddy George gave me an idea for demoing the next two topics I wanted to bring up. For loops and the Random Function. First run this...
There isnt anything special about the above code, I just drew a curve and revolved it, made a cylander and duplicated it 49 times. I did this with echo all commands on and used the important bits from the script editor.
First lets get random.
There is a way to setAttr for an object randomly. Its called the rand command, here is an example. Make a poly cube and then run this...
The rand -10 10 allows you to set the attribute to any value between those two. Pretty sneaky sis.
Anyway lets get to the for loop. Now if you look at the above code theres a nasty little bit of for loopery happening here
We address what that means later. There is a much easier way to do a for loop. Maya has a for in loop. We are going to use that to move about all 50 peperonis randomly. Heres how it goes.
So the for in loop is pretty sassy, its saying in english "For each one of you in ths array... do something". You can declare the $each variable, although you do not need to.
{
curve -name pizzaCurve -d 3 -p 0 0.0310559 0 -p -4.875776 0.0621118 0 -p -10.093168 0.0621118 0 -p -14.813665 0 0 -p -19.906832 0.0621118 0 -p -20.900621 1.987578 0 -p -19.968944 4.875776 0 -p -18.074534 3.136646 0 -p -17.919255 2.018634 0 -p -14.875776 2.049689 0 -p -10 2 0 -p -5 2 0 -p 0 2 0 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 10 -k 10 ;
revolve -n pizzaGEO -ch 1 -po 0 -rn 0 -ssw 0 -esw 360 -ut 0 -tol 0.01 -degree 3 -s 8 -ulp 1 -ax 0 1 0 "pizzaCurve";
DeleteHistory pizzGEO;
delete pizzaCurve;
polyCylinder -name pepperoni_geo -r 1 -h 0.25 -sx 8 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;
setAttr pepperoni_geo.ty 2.25;
duplicate -rr;
for ($i=1; $i<50; ++$i)
duplicate -rr -st;
;
}
There isnt anything special about the above code, I just drew a curve and revolved it, made a cylander and duplicated it 49 times. I did this with echo all commands on and used the important bits from the script editor.
First lets get random.
There is a way to setAttr for an object randomly. Its called the rand command, here is an example. Make a poly cube and then run this...
{
int $random = `rand -10 10`;
setAttr "pCube1.translateX" $random;
}
The rand -10 10 allows you to set the attribute to any value between those two. Pretty sneaky sis.
Anyway lets get to the for loop. Now if you look at the above code theres a nasty little bit of for loopery happening here
for ($i=1; $i<50; ++$i) .We address what that means later. There is a much easier way to do a for loop. Maya has a for in loop. We are going to use that to move about all 50 peperonis randomly. Heres how it goes.
{
select -r "pepperoni_*";
string $peps[] = `ls -sl -exactType transform`;
for ($each in $peps)
{
float $randomX = `rand -15 15`;
float $randomZ = `rand -15 15`;
setAttr ($each + ".tx") $randomX;
setAttr ($each + ".tz") $randomZ;
}
}
So the for in loop is pretty sassy, its saying in english "For each one of you in ths array... do something". You can declare the $each variable, although you do not need to.

5 Comments:
Chad -
You are such a damn sexy man. Did you know that, with the evaluators (``), you can drop them right into a command? For example:
int $random = `rand -10 10`;
setAttr "pCube1.translateX" $random;
Can be done with:
setAttr "pCube1.translateX" `rand -10 10`;
And good times will be had by all!
By
Johnh, at Friday, April 08, 2005 2:16:00 PM
Sweet sassy molassy. I didn't even think about sticking the rand command right up in that B. Thanks John. Where's my book!?!?
Cheers,
Chad
By
Chad, at Monday, April 11, 2005 8:11:00 PM
you two are such 16 year old girls some times.. your book is on the way:)
By
bclark, at Friday, April 15, 2005 11:35:00 AM
I got the book! Now if I only had time to read it... Things will settle down a bit next week, and I'll hopefully have a review up by Monday the 25th.
By
Chad, at Sunday, April 17, 2005 8:21:00 AM
Haha! that's too cool man.
mmmm... pizzaaaa...
By
George, at Monday, April 18, 2005 10:33:00 AM
Post a Comment
Links to this post:
Create a Link
<< Home