Snippets Collections
global proc radioOptions()
{
	string $win = `window`;
	rowColumnLayout -nc 1;
	string $radioButtons = `radioButtonGrp -l "Select One" -nrb 4 -labelArray4 "One" "2" "C" "fourth" -vr -cw 1 80 -cw 2 200 -sl 1`;
	button -l "Click" -c ("radioResult "+$radioButtons);
	showWindow $win;
}

proc radioResult(string $radioButtons)
{
	int $selection = `radioButtonGrp -q -sl $radioButtons`;

	if ($selection == 2)
	{
		print "it's 2\n";
	}
	else
	{
		print "it's not 2\n";
	}
}
global proc radioDemo()
{
	string $win = `window`;
	rowColumnLayout -nc 1;
	string $radioButtonsName = `radioButtonGrp -nrb 4 -label "LABEL" -la4 "first" "second" "third" "fourth" -vr -sl 3 -cw 1 75`;
	button -label "CLICK HERE" -c ("printSelection "+$radioButtonsName);
	showWindow $win;
}
proc printSelection(string $radioButtonsName)
{
	int $selection = `radioButtonGrp -q -sl $radioButtonsName`;
	print ($selection+"\n");
}
global proc windowUsefulDemo()
{
	string $win = `window -t "Make Colourful Cubes" -wh 600 100`;
	rowColumnLayout -nc 1 -cw 1 600;
	string $amountSlider = `intSliderGrp -l "How Many?" -f 1 -cw 1 80`;
	string $colourSlider = `colorSliderGrp -l "What Colour?" -rgb 0.572002 0.838 0.069554 -cw 1 80`;
	button -l "Create" -c ("createCubes "+$amountSlider+" "+$colourSlider); // send the slider names
	button -l "Close" -c ("deleteUI -wnd "+$win); 
	showWindow $win;
}

proc createCubes(string $amountSlider, string $colourSlider) // makeCubes expects the slider names (as strings)
{
	int $num = `intSliderGrp -q -v $amountSlider`; // query the value from the intSliderGrp
	float $col[] = `colorSliderGrp -q -rgb $colourSlider`; // query the colour from the colorSliderGrp

	string $allCubes[];

	for ($c=0;$c<$num;$c++) // queried int value used here
	{
		string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		$allCubes[$c] = $cubeName[0];
	}

	string $mat = `shadingNode -asShader blinn`;
	string $sg = `sets -renderable true -noSurfaceShader true -empty -name ($mat+"SG")`;
	connectAttr -f ($mat+".outColor") ($sg+".surfaceShader");
	setAttr ($mat+".color") -type double3 $col[0] $col[1] $col[2]; // queried colour used here


	select -r $allCubes;
	string $groupName = `group`;
	select -r $groupName;
	sets -e -forceElement $sg;
}
global proc windowDoStuff()
{
	string $win = `window -t "Do Stuff" -wh 600 100`;
	rowColumnLayout -nc 1 -cw 1 600;
	string $intSlide = `intSliderGrp -l "How many?" -f 1`; // get the name of the intSlider
	button -l "Click" -c ("doStuff "+$intSlide); // send the name to the "doStuff" procedure
	showWindow $win;
}

proc doStuff(string $intSlide) // doStuff is expecting the name as an input as a string
{
	polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
	print "HEY GUYS\n";
	print ($intSlide+"\n");
	int $queriedValue = `intSliderGrp -q -v $intSlide`; // get the value from the slider
	print ($queriedValue+"\n");
}
global proc windowDemo()
{
	string $win = `window -t "Demonstration Window" -wh 900 300 -bgc 0.0745215 0.5 0.0575`;
	frameLayout -collapsable 0 -labelVisible 0 ;
		rowColumnLayout -nc 2 -cw 1 450 -cw 2 450 -rs 1 50;
			intSliderGrp -l "First Slider" -f 1 -cw 1 75 -cw 2 50 -min 1 -max 50 -v 25 -fmx 100000;
			floatSliderGrp -label "Second Slider" -f 1;
			checkBoxGrp -label "CLICK?" ;
			colorSliderGrp -label "Colour" -rgb 1 0 0;
			button -l "Create" -bgc 1 0.045 0.669426;
			button -l "Close" -bgc 1 0.461533 0;
		setParent ..;
		rowColumnLayout -nc 1 -cw 1 900;
			floatSliderGrp -label "Wide Slider" -f 1;
			floatSliderGrp -label "Next Wide Slider" -f 1;
	showWindow $win;
}

windowDemo
global proc deformerDemo()
{
	string $cyl[] = `polyCylinder -r 1 -h 100 -sx 20 -sy 50 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	string $bend[] = `nonLinear -type bend`;
	// Result: bend1 bend1Handle
	expression -s ($bend[0]+".curvature = sin(time*4)*180;")  -o $bend[0] -ae 1 -uc all ;



}
global proc ifCubeAndSphere()
{
	string $cube[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
	string $sphere[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
	xform -t 5 0 0 $sphere[0];
	expression -s ($cube[0]+".translateY = noise(time*3)*10;")  -o $cube[0] -ae 1 -uc all ;
	expression -s ("if ("+$cube[0]+".translateY <0)\n{\n\t"
						 +$sphere[0]+".translateZ = sin(time*4)*5;\n\t"
						 +$sphere[0]+".translateY = 0;\n\n}\nelse\n{\n\t"
						 +$sphere[0]+".translateY = sin(time*4)*5;\n\t"
						 +$sphere[0]+".translateZ = 0;\n\n}")  -o $sphere[0] -ae 1 -uc all  ;

}
global proc ifExpression()
{
	polyGear -sides 16 -radius 1 -internalRadius 0.3 -height 1 -heightDivisions 10 -gearSpacing 0.6 -gearOffset 0.2 -gearTip 0.5 -gearMiddle 1.2 -twist 0 -taper 1;
	string $gear[] = `ls -sl`;


	string $mat = `shadingNode -asShader blinn`;
	string $sg = `sets -renderable true -noSurfaceShader true -empty -name ($mat+"SG")`;
	connectAttr -f ($mat+".outColor") ($sg+".surfaceShader");

	select -r $gear[0] ;
	sets -e -forceElement $sg;

	expression -s ($gear[0]+".translateY = noise(time*4)*8;\n\nif ("+$gear[0]+".translateY <0)\n{\n\t"+$mat+".colorR = 0.644999;\n\t"+$mat+".colorG = 1;\n\t"+$mat+".colorB = 0.077;\n}\nelse\n{\n\t"+$mat+".colorR = 0.729425;\n\t"+$mat+".colorG = 0.0427638;\n\t"+$mat+".colorB = 0.668304;\n}") -ae 1 -uc all ;

}
global proc turtle2021()
{
	string $shell[] = `polySphere -r 3 -sx 8 -sy 8 -ax 0 1 0 -cuv 2 -ch 1`;
	select -r ($shell[0]+".vtx[0:31]") ($shell[0]+".vtx[56]") ;
	scale -r -ocp 1 1e-05 1 ;
	string $head[] = `polyCube -w 1.5 -h 1.5 -d 1.5 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
	xform -t 0 0.5 3.375 $head[0];
	
	string $feet[];
	for ($f=0;$f<4;$f++)
	{
		string $foot[] = `polyPyramid -w 3 -ns 4 -sh 1 -sc 0 -ax 0 1 0 -cuv 3 -ch 1`;
		xform -t -2.63 0 2.63 -ro 45 0 90 -s 0.188 1 0.25 $foot[0];
		xform -ws -piv 0 0 0 $foot[0];
		makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;
		xform -ro 0 ($f*90) 0 $foot[0];
		$feet[$f] = $foot[0];
	}
	select -r $feet $head[0] $shell[0];
	string $turtGrp = `group`;

	string $mat = `shadingNode -asShader blinn`;
	string $matSG = `sets -renderable true -noSurfaceShader true -empty -name ($mat+"SG")`;
	connectAttr -f ($mat+".outColor") ($matSG+".surfaceShader");
	select -r $turtGrp ;
	sets -e -forceElement $matSG;
	setAttr ($mat+".color") -type double3 0 0.178 0.0273853 ;

	string $ground[] = `polyPlane -w 100 -h 100 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1`;
	string $loc[] = `spaceLocator -p 0 1.5 0`;
	select -r $shell[0] $loc[0];
	parentConstraint -mo -weight 1;

	xform -t 0 54 0 -ro 32 5 -25 $turtGrp;
	select -r $turtGrp;
	rigidBody -active -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0.6 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio none ;
	select -r $ground[0] ;
	rigidBody -passive -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0.6 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio none ;
	string $grav[] = `gravity -pos 0 0 0 -m 9.8 -att 0 -dx 0 -dy -1 -dz 0  -mxd -1  -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 `;
	connectDynamic -f $grav[0] $turtGrp;


	expression -s ("if ("+$loc[0]+".translateY < 4)\n{\nsetAttr \""+$mat+".color\" -type double3 1 0 0 ;\n}\nelse\n{\nsetAttr \""+$mat+".color\" -type double3 0 0.178 0.0273853 ;\n}")  -o $mat -ae 1 -uc all  ;

}
/********************************************************

	De-select a precentage of the selected Items

	Brian Samuels


********************************************************/

global proc selPercent(int $percent)
{

string $selected[] = `ls -sl -fl`;
string $sel;
int $rnd;
	for($sel in $selected)
	{
		$rnd = `rand 0 100`;
		if($rnd> $percent)
		{
			select -d $sel;

		}
	}

}

global proc colourDemo()
{
////////////////////  SOLID COLOUR /////////////////////
	string $sphere1[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
	xform -t -5 0 0 $sphere1[0];

	// Create material
	string $mat1 = `shadingNode -asShader blinn`;
	// Result: blinn1 // 
	string $sg1 = `sets -renderable true -noSurfaceShader true -empty -name ($mat1+"SG")`;
	// Result: blinn1SG // 
	connectAttr -f ($mat1+".outColor") ($sg1+".surfaceShader");
	// Result: Connected blinn1.outColor to blinn1SG.surfaceShader. // 

	// Select sphere and assign the material
	select -r $sphere1[0] ;
	sets -e -forceElement $sg1;

	// Set the colour to stunning lime green
	setAttr ($mat1+".color") -type double3 0.644999 1 0.077 ;

///////////////////// RANDOM SOLID COLOUR ///////////////

	string $sphere2[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;

	string $mat2 = `shadingNode -asShader phong`;
	string $sg2 = `sets -renderable true -noSurfaceShader true -empty -name ($mat2+"SG")`;
	connectAttr -f ($mat2+".outColor") ($sg2+".surfaceShader");

	select -r $sphere2[0] ;
	sets -e -forceElement $sg2;

	// Generate postive random numbers between 0 and 1
	float $randCol[] = abs(sphrand(1));

	setAttr ($mat2+".color") -type double3 $randCol[0] $randCol[1] $randCol[2];

///////////////// ANIMATED COLOUR WITH EXPRESSION /////////////////////////////

	string $sphere3[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
	xform -t 5 0 0 $sphere3[0];

	string $mat3 = `shadingNode -asShader lambert`;
	string $sg3 = `sets -renderable true -noSurfaceShader true -empty -name ($mat3+"SG")`;
	connectAttr -f ($mat3+".outColor") ($sg3+".surfaceShader");

	select -r $sphere3[0] ;
	sets -e -forceElement $sg3;


	expression -s ($mat3+".colorR = abs(noise(time));\n"
				  +$mat3+".colorG = abs(noise(time*2));\n"
				  +$mat3+".colorB = abs(sin(time*3));")  -o $mat3 -ae 1 -uc all  ;


}
/***********************************************************
tooManyCatsAnim.mel  

Creates user-specified number of cats, in a group of a
user-specified radius.


USAGE: tooManyCatsAnim <int numberOfCats> <float groupRadius>
***********************************************************/

global proc tooManyCatsAnim(int $num, float $radius)
{
	string $groupList[0]; // declare an array to save the names of all the cat groups

	for ($i=0;$i<$num;$i++) // loop to create the cats
	{
		// create and position body
		string $body[] = `polyCylinder -r 1 -h 4 -sx 10 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
		xform -ro 90 0 0 -t 0 2.5 0 $body[0];
		// select the CVs on the front of the body and scale and move them
		select -r ($body[0]+".vtx[10:19]") ($body[0]+".vtx[21]") ;
		scale -r -p -5.96046e-008cm 2.5cm 2cm 0.725606 0.725606 0.725606 ;
		move -r -os -wd 0 0 0.215202 ;
		//create and position head
		string $head[] = `polyPyramid -w 1 -ns 4 -sh 1 -sc 0 -ax 0 1 0 -cuv 3 -ch 1`;
		xform -t 0 3.8 2.8 -ro 90 0 45 -s 1.6 2.3 1.6 $head[0];
		// create and position ears
		string $ear1[] = `polyCone -r 1 -h 2 -sx 6 -sy 1 -sz 0 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
		string $ear2[] = `polyCone -r 1 -h 2 -sx 6 -sy 1 -sz 0 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
		xform -t -0.45 4.85 2.2 -ro 0 0 12.8 -s 0.3 0.55 0.16 $ear1[0];
		xform -t 0.45 4.85 2.2 -ro 0 0 -12.8 -s 0.3 0.55 0.16 $ear2[0];

		parent $ear1[0] $ear2[0] $head[0];
		parent $head[0] $body[0];
		select -r $body[0];
		makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;

		xform -ws -piv 0 3 2 $head[0];
		float $headFreq = rand(2,4);
		float $headRange = rand(10,30);
		float $bodyFreq = rand(4,7);
		float $bodyBounce = rand(0.1,0.3);
		expression -s ($head[0]+".rotateY = noise(time*"+$headFreq+")*"+$headRange+";") -ae 1 -uc all;
		expression -s ($body[0]+".translateY = abs(sin(time*"+$bodyFreq+"))*"+$bodyBounce) -ae 1 -uc all;

		// create tail
		string $tail[] = `polyCylinder -r 0.15 -h 3.5 -sx 8 -sy 16 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
		// move the pivot point to the bottom, so it bends from the bum
		xform -ws -piv 0 -1.75 0 $tail[0];		
		xform -t 0 4.96 -1.78 $tail[0];

		// deformer variables
		float $curv = rand(50,180); // random curvature for the BEND deformer
		float $wavelength = rand(2,5); // random wavelength for the SINE deformer
		float $amp = rand(0.1,0.3); // random amplitude for the SINE deformer
		float $yrot = rand(-360,360); // random Y rotation
		float $freq = rand(2,5); // time multiplier


		if ($i%2==1) // if the loop counter is ODD, add a bend to the tail
		{
			string $bend[] = `nonLinear -type bend  -lowBound 0 -highBound 1 -curvature 0`;
			expression -s ($bend[0]+".curvature = sin(time*"+$freq+")*"+$curv) -ae 1 -uc all;

			xform -ro 0 $yrot 0 $bend[1];
			parent $bend[1] $tail[0];
			parent $tail[0] $body[0];
		}
		else if ($i%2==0) // if the loop counter is EVEN, add a sine to the tail
		{
			string $sine[] = `nonLinear -type sine -lowBound -1 -highBound 1 -amplitude $amp -wavelength $wavelength -dropoff 1 -offset 0`;
			expression -s ($sine[0]+".offset = -time*"+$freq) -ae 1 -uc all ;

			xform -ro 0 $yrot 0 $sine[1];
			parent $sine[1] $tail[0];
			parent $tail[0] $body[0];
		}
		float $tailAngle = rand(-50,0);
		xform -ro $tailAngle 0 0 $tail[0];

		string $legs[]; // declare an array to save all the names of the legs
		for ($r=0;$r<4;$r++) // loop to create the legs, and gather their names
		{
			string $leg[] = `polyCube -w 0.5 -h 2 -d 0.5 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
			xform -ws -piv 0 1 0 $leg[0]; // set the pivot points, so they bend from the shoulders/hips
			float $legFreq = rand(2,6);
			float $legRadius = rand(5,30);
			int $flip = rand(2);
			if ($flip == 0)
			{
				$legFreq = -$legFreq;
			}
			expression -s ($leg[0]+".rotateX = sin(time*"+$legFreq+")*"+$legRadius+";\n"+$leg[0]+".rotateZ = cos(time*"+$legFreq+")*"+$legRadius+";") -ae 1 -uc all;
			$legs[$r] = $leg[0];
		}
		// move the legs
		xform -t 0.5 0.5 1.5 $legs[0];
		xform -t 0.5 0.5 -1.5 $legs[1];
		xform -t -0.5 0.5 1.5 $legs[2];
		xform -t -0.5 0.5 -1.5 $legs[3];

		// group all the parts together
		select -r $body[0] $legs;
		string $groupName = `group`;

		// position variables
		float $trans[] = sphrand($radius);
		xform -t $trans[0] 0 $trans[2];

		// rotation variables
		float $rotationOffset = rand(-360,360);
		float $noiseAmt = rand(20,60);
		float $timeMult = rand(3);

		expression -s ($groupName+".rotateY = noise(time*"+$timeMult+")*"+$noiseAmt+"+"+$rotationOffset+";") -ae 1 -uc all;
		select -cl;
	}


}
/******************************************************
walkingFella.mel

Makes a guy who walks via animation expressions. 
User may choose clothing accessories.

USAGE: walkingFella <int hat> <int bowtie>
******************************************************/

global proc walkingFella(int $hatSel, int $btieSel)
{
	// Create all the Man's geo
	string $head[] = `polySphere -r 1 -sx 8 -sy 8 -ax 0 1 0 -cuv 2 -ch 1`;
	xform -t 0 8 0 $head[0];
	string $body[] = `polyCube -w 3 -h 3 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
	xform -t 0 5.3 0 $body[0];
	select -r ($body[0]+".vtx[0:1]") ($body[0]+".vtx[6:7]") ;
	scale -r -p 0cm 3.8cm 0cm 0.744391 1 1 ;
	string $leg1[] = `polyCylinder -r 0.4 -h 3.5 -sx 8 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t -0.5 1.8 0 $leg1[0];
	xform -ws -piv -0.5 3.55 0 $leg1[0];
	string $leg2[] = `polyCylinder -r 0.4 -h 3.5 -sx 8 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t 0.5 1.8 0 $leg2[0];
	xform -ws -piv 0.5 3.55 0 $leg2[0];
	string $arm1[] = `polyCylinder -r 0.3 -h 3 -sx 8 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t -1.6 5.1 0 $arm1[0];
	xform -ws -piv -1.6 6.6 0 $arm1[0];
	string $arm2[] = `polyCylinder -r 0.3 -h 3 -sx 8 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t 1.6 5.1 0 $arm2[0];
	xform -ws -piv 1.6 6.6 0 $arm2[0];

	// Add expressions
	expression -s ($leg1[0]+".rotateX = sin(time*4)*45;") -ae 1 -uc all ;
	expression -s ($leg2[0]+".rotateX = -sin(time*4)*45;") -ae 1 -uc all ;
	expression -s ($arm1[0]+".rotateX = -sin(time*4)*20;") -ae 1 -uc all ;
	expression -s ($arm2[0]+".rotateX = sin(time*4)*20;") -ae 1 -uc all ;

	// Create a group for the head. If Hat is selected, the hat will be parented.
	select -r $head[0];
	string $headGroup = `group`;
	xform -ws -piv 0 7 0 $headGroup;
	// Create a group for the body, in case bowtie is selected.
	select -r $body[0];
	string $bodyGroup = `group`;

	// Optional Hat creation

	if ($hatSel == 1)
	{
		string $hat[] = `polyCylinder -r 0.75 -h 1.5 -sx 12 -sy 2 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
		xform -t 0 9.5 0 $hat[0];
		select -r ($hat[0]+".e[12:23]");
		xform -r -t 0 -0.398477 0;
		string $extrude1[] = `polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -pvx 0 -pvy 8.925761506 -pvz 0 -divisions 1 -twist 0 -taper 1 -off 0 -thickness 0 -smoothingAngle 30 ($hat[0]+".f[0:11]")`;
		setAttr ($extrude1[0]+".localTranslate") -type double3 0 0 0.422521 ;
		parent $hat[0] $headGroup;

		string $hatShad = `shadingNode -asShader blinn`;
		sets -renderable true -noSurfaceShader true -empty -name ($hatShad+"SG");
		connectAttr -f ($hatShad+".outColor") ($hatShad+"SG.surfaceShader");

		// Create a ramp to make a red ribbon around the hat.
		string $rampTex = `shadingNode -asTexture ramp`;
		string $p2dt = `shadingNode -asUtility place2dTexture`;
		connectAttr ($p2dt+".outUV") ($rampTex+".uv");
		connectAttr ($p2dt+".outUvFilterSize") ($rampTex+".uvFilterSize");
		connectAttr -f ($rampTex+".outColor") ($hatShad+".color");
		// Adjust the ramp settings
		setAttr ($rampTex+".interpolation") 0;
		setAttr ($rampTex+".colorEntryList[0].position") 0.510836;
		setAttr ($rampTex+".colorEntryList[1].position") 0.569659;
		setAttr ($rampTex+".colorEntryList[2].position") 0;
		setAttr ($rampTex+".colorEntryList[0].color") -type double3 0.551 0 0;
		setAttr ($rampTex+".colorEntryList[1].color") -type double3 0 0 0;
		setAttr ($rampTex+".colorEntryList[2].color") -type double3 0 0 0;

		select -r $hat[0];
		sets -e -forceElement ($hatShad+"SG");

	}
	// Optional Bowtie

	if ($btieSel == 1)
	{
		string $bowtie[] = `polyCube -w 1 -h 0.5 -d 0.2 -sx 2 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		select -r ($bowtie[0]+".e[12]") ($bowtie[0]+".e[18]") ;
		scale -r -p 0cm 0cm 0cm 1 0.251157 1 ;
		xform -t 0 6.5 0.7 $bowtie[0];
		parent $bowtie[0] $bodyGroup;
		// Add red bowtie shader
		string $btShad = `shadingNode -asShader blinn`;
		sets -renderable true -noSurfaceShader true -empty -name ($btShad+"SG");
		connectAttr -f ($btShad+".outColor") ($btShad+"SG.surfaceShader");
		setAttr ($btShad+".color") -type double3 0.551 0 0 ;
		select -r $bowtie[0];
		sets -e -forceElement ($btShad+"SG");

	}

	// Add expression to the Head / Hat.
	expression -s ($headGroup+".translateY = abs(sin(time*4))*0.2;\n"
				  +$headGroup+".rotateZ = sin(time*4)*10;") -ae 1 -uc all ;
	
	// Group body, head and arms. Add expression.
	select -r $headGroup $bodyGroup $arm1[0] $arm2[0];
	string $bodyGroupAnim = `group`;
	expression -s ($bodyGroupAnim+".translateY = abs(sin(time*4)*0.1);\n"
				  +$bodyGroupAnim+".rotateY = sin(time*4)*10;") -ae 1 -uc all ;

	select -r $leg1[0] $leg2[0] $bodyGroupAnim;
	group -n "walkingFella";
	select -cl;

}
global proc makeCarPivotAnimGroup()
{
	string $car[] = `polyCube -w 1 -h 0.7 -d 3 -sx 1 -sy 1 -sz 3 -ax 0 1 0 -cuv 4 -ch 1`;

	string $extrude[] = `polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -pvx 0 -pvy 0.349999994 -pvz 0 -divisions 1 -twist 0 -taper 1 -off 0 -thickness 0 -smoothingAngle 30 ($car[0]+".f[2]")`;
	// Result: polyExtrudeFace1 // 
	setAttr ($extrude[0]+".localTranslate") -type double3 0 0 0.62778 ;

	string $wheels1[] = `polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t 0.013 -0.301 0.854 -ro 0 0 90 -s 0.449 0.695 0.449 $wheels1[0];
	string $wheels2[] = `polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	xform -t 0.013 -0.301 -0.854 -ro 0 0 90 -s 0.449 0.695 0.449 $wheels2[0];

	select -r $car[0] $wheels1[0] $wheels2[0];
	string $groupName = `group`;

	xform -t -10 0 0 $groupName;
	xform -ws -piv 0 0 0 $groupName;

	expression -s ($groupName+".rotateY = frame*5")  -o $groupName -ae 1 -uc all ;

}
makeCarPivotAnimGroup;
global proc splode(int $num, float $speed)
{

	for ($p=0;$p<$num;$p++)
	{
		float $randTrans[] = sphrand($speed);
		string $cube[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		expression -s ($cube[0]+".translateX = time*"+$randTrans[0]+";\n"
					  +$cube[0]+".translateY = time*"+$randTrans[1]+";\n"
					  +$cube[0]+".translateZ = time*"+$randTrans[2]+";")  -o $cube[0] -ae 1 -uc all  ;
	}
}
/*******************************************************
ballBounceRand.mel 
Creates a line of bouncing balls.

USAGE: ballBounceRand <int numberOfBalls>
********************************************************/
global proc ballBounceRand(int $num)
{
	string $allBalls[];

	for ($x=0;$x<$num;$x++)
	{
		float $freq = rand(3,5); // random frequency
		float $height = rand(5,20); // random height
		string $ball[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
		xform -t ($x*3) 0 0 $ball[0]; // use counter to spread the ball out on the X axis 
		expression -s ($ball[0]+".translateY = abs(sin(time*"+$freq+")*"+$height+");\n"
					  +$ball[0]+".translateZ = time*4;")  -o $ball[0] -ae 1 -uc all ;
		$allBalls[$x] = $ball[0];	
	}

	select -r $allBalls;
	group;
}
global proc counterDemo()
{
	for ($i=0;$i<10;$i++)
	{
		string $cube[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		xform -t ($i*2) $i 0 $cube[0];
	}

}
global proc ballBounce()
{
	string $ball[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
	expression -s ($ball[0]+".translateY = abs(sin(time*4)*10);\n"
				  +$ball[0]+".translateZ = time*4;")  -o $ball[0] -ae 1 -uc all ;

}
global proc makeCar()
{
	string $car[] = `polyCube -w 1 -h 1 -d 3 -sx 1 -sy 1 -sz 3 -ax 0 1 0 -cuv 4 -ch 1`;
	string $extr[] = `polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -pvx 0 -pvy 0.5 -pvz 0 -divisions 1 -twist 0 -taper 1 -off 0 -thickness 0 -smoothingAngle 30 ($car[0]+".f[2]")`;
	// Result: polyExtrudeFace1 // 
	setAttr ($extr[0]+".localTranslate") -type double3 0 0 0.715981 ;

}
global proc moveCVs()
{
	string $cyl[] = `polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
	select -r ($cyl[0]+".vtx[20:21]") ($cyl[0]+".vtx[37:39]") ;
	move -r 0 0.876853 0 ;

}
/*********************************************************
makeCubes.mel
Creates a cloud of cubes

USAGE: makeCubes <int numberOfCubes> <float radiusOfCloud>
*********************************************************/
global proc makeCubes(int $numCubes, float $radius)
{
	string $allCubes[]; // declare an array to save the names of the cubes

	for ($c=0;$c<$numCubes;$c++)
	{
		string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;

		float $randTrans[] = sphrand($radius);
		float $randRot[] = sphrand(360);
		float $randScale[] = abs(sphrand(5));

		xform -t $randTrans[0] $randTrans[1] $randTrans[2] 
		      -ro $randRot[0] $randRot[1] $randRot[2]
		      -s $randScale[0] $randScale[1] $randScale[2]
		       $cubeName[0];
		$allCubes[$c] = $cubeName[0]; // use the counter to gather the names
									  // of each new cube and save it in a list
	}
	select -r $allCubes; // select all the new cubes and group them
	group;
}

/*		You can also use rand to generate random number like this:
		float $randX = rand(5);
		float $randY = rand(5);
		float $randZ = rand(5);
*/
global proc forInDemo()
{
	string $nameList[] = {"Kelly","Sam","Chiharu","Liam","May","Jeremy"};

	for ($person in $nameList)
	{
		print ($person+" loves scripting.\n");
	}

	print "DONE!";
}
global proc ifLogicTest()
{
	int $randNum = rand(10.9999);
	print ($randNum+"\n");

	if ((($randNum == 3) || ($randNum == 5)) || ($randNum == 7))
	{
		polyPlane -w 1 -h 1 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1;

	}

}
/***************************************************************
ifShapes.mel			Kelly Bechtle-Woods  12/04/2022

Generates random numbers and creates shapes depending on the result

USAGE: ifShapes
****************************************************************/
global proc ifShapes()
{
	int $randNum = rand(10.9999);
	print ($randNum+"\n");

	if ($randNum < 2) // True if 0 or 1
	{
		polyCone -r 1 -h 2 -sx 20 -sy 1 -sz 0 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1;
	}
	else if ($randNum == 2) // True if 2
	{
		polyTorus -r 1 -sr 0.5 -tw 0 -sx 20 -sy 20 -ax 0 1 0 -cuv 1 -ch 1;
	}
	else if ($randNum > 8) // True if 9 or 10
	{
		polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
	}
	else if (($randNum > 2) && ($randNum < 9))  // True if 3, 4, 5, 6, 7, 8
	{
		polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;
	}
	else
	{
		print "nothing.";
	}

	print "DONE!";
}
global proc cubeGenerator ()
{
    int $randNum = rand(5);
    print ($randNum+"\n");

    for($i = 0; $i < 10; $i++) 
    {
        string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1 -n "cube"`;
        float $randScale[] = abs(sphrand(5));
        xform -s $randScale[0] $randScale[1] $randScale[2] $cubeName[0];
    }
    
}
// Random Shape
global proc shapeGen()
{
    int $randShape = rand(2.9999);
    print("You got shape number: " + $randShape + "!\n");

    if ($randShape == 0)
    {
        int $numCubes = 5;
        float $radius;
        string $allCubes[]; // declare string array that stores the names of the cubes in the array 
    
        for ($cu = 0; $cu < $numCubes ; $cu++) // initialisation / condition / iteration
        {
            string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		    $allCubes[$cu] = $cubeName[0]; // use the counter to gather the names
				    					        // of each new cube and save it in a list
    	}
	    select -r $allCubes; // select all the new cubes and group them
	    group;
    }      
    else if ($randShape == 1) 
    {
        int $numSpheres = 5;
        string $allSpheres[];
      
        for ($sp = 0; $sp < $numSpheres; $sp++)
        {
          string $sphereName[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1`;
          $allSpheres[$sp] = $sphereName[0];
        }
        select -r $allSpheres;
        group;
    }
    else if ($randShape == 2)
    {
        int $numCones = 5;
        string $allCones[];
        
        for ($co = 0; $co < $numCones; $co++)
        {
           string $coneName[] = `polyCone -r 1 -h 2 -sx 20 -sy 1 -sz 0 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1`;
           $allCones[$co] = $coneName[0];
        }
        select -r $allCones;
        group;
    }
}
string $cubeName[] = `polyCube`;

float $randX = rand(20);
float $randY = rand(1,20);
float $randZ = rand(20);
float $randRot[] = sphrand(360);
float $randWidth = rand(8);
float $randHeight = rand(8);

xform -t $randX $randY $randZ
      -ro $randRot[0] $randRot[1] $randRot[2]
       $cubeName[0];

setAttr "polyCube1.width" $randWidth;
setAttr "polyCube1.height" $randHeight;

//WORKING

global proc gamble (int $numGamble)

{
   
    global int $money;
   
    print ("in order to win, you must roll an even number\n"); 
    print("You rolled "+$numGamble+" times!");
    for ($g=0; $g<$numGamble;$g++)
    {
    print ("You have rolled " +$randNum+"\n");
    int $randNum = rand(1,12);
if (($randNum == 2) || ($randNum == 4) || ($randNum == 6) || ($randNum == 8) || ($randNum == 10) || ($randNum == 12))
{
    $money = ($money + rand(5,10));
    print ("Winner winner chicken dinner!\n");
    print ("Balance: $"+$money+"\n");  
}
else
{
    $money = ($money - rand(5,10));
    print ("Sorry, you lost\n");
    print ("Balance: $"+$money+"\n");
}
}
}
global proc balance ()
{
    global int $money;
    print ("You have $"+$money);
}


global int $money;

if ($money<=0)
{
    print ("Warning! you are bankrupt and we highly recommend not gambling any further to avoid debt.");
}
string $name;
float $height;
string $hairColour;
$height = "167.5";
$name = "Thomas Balinski";
$hairColour = "Red";
print ("Hello, my name is " + $name + " and I recently dyed my hair " + $hairColour + ". I am also " + $height + " centimiters tall.");


string $name = "chompy";
string $pet[3] = {"turtle", "capybara", "cat"};
print ("I have a pet and his name is " + $name + ". He is a " + $pet[1] + ". He also has a friend who is a " + $pet[0] + ".");


global proc fashion(string $top, string $pants, string $shoes)
{
    print ("I'm wearing a snazzy " + $top + " to go with my cool " + $pants + " that perfectly match my " + $shoes + ".");
}
fashion("red silk shirt","blue jeans","sweyd boots");

global proc candy(string $type, string $reason, float $cost)
{
    print ("my favorite type of candy would have to be " + $type + " because " + $reason + ". It costs " + $cost + " dollars to buy 5 of them");
}
candy("Zombie Chews", "they are very sour", "3.5");
string $myChar = "Mista White";
int $age = "51";
float $money = "5";
print ("Yo! " + $myChar + "! Where is my share, where is my " + $money + " million");
global proc superPerson (string $adj, string $noun, string $eyeCol) 
{ 
  print ("Hello "+ $adj +" "+ $noun +"!\n");
  print "Welcome to the database of Supers, please allow a retina scan for verification\n";
  print("\n...");
  print ("\n\n...");
  print ("\n\n...verification complete...\n");
  print ("\n Access granted, your "+$eyeCol+" eyes look lovely today, "+$adj+" "+$noun+"!");
} 
superPerson ("Vermillion", "Prison", "blue"); 
global proc helloRandom2()
{
	string $nameList[] = {"Kelly","Sam","Chiharu","Liam","May","Jeremy"};
	int $namePicker = rand(5.99999);
	int $num = rand(10,60);
	string $itemList[] = {"cats","dogs","fish","guinea pigs","frogs","donkeys","bottles of lotion","sheep","snakes","jar of pickles"};
	int $itemPicker = rand(9.999999);

	print ("Hello "+$nameList[$namePicker]+"!\n");
	print ("You have "+$num+" "+$itemList[$itemPicker]+".\n");
	print ("That's too many "+$itemList[$itemPicker]+".");
}
global proc helloRandom()
{
	string $nameList[] = {"Kelly","Sam","Chiharu","Liam","May","Jeremy"};
	int $num = rand(10,60);
	int $namePicker = rand(5.99999);

	print ("Hello "+$nameList[$namePicker]+"!\n");
	print ("You have "+$num+" cats.\n");
	print "That's too many cats.";
}
global proc helloInput(string $name,int $num)
{
	print ("Hello "+$name+"!\n");
	print ("You have "+$num+" cats.\n");
}
global proc helloWorld(string $name)
{
	print ("Hello "+$name+"!");
}
star

Tue Jul 02 2024 00:50:37 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:50:05 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:49:28 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:48:42 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:48:00 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:40:54 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:40:26 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:39:37 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:38:58 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:38:26 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:37:32 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:27:32 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:26:38 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:25:35 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:22:59 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:22:06 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:20:55 GMT+0000 (Coordinated Universal Time)

#mel
star

Tue Jul 02 2024 00:19:55 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 03:32:05 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 03:31:30 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 02:31:26 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 02:30:08 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 02:29:11 GMT+0000 (Coordinated Universal Time)

#mel
star

Thu Jun 27 2024 02:25:36 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 23:57:53 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 23:57:05 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 23:55:47 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 22:11:58 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 22:10:32 GMT+0000 (Coordinated Universal Time)

#mel
star

Wed Jun 26 2024 22:08:04 GMT+0000 (Coordinated Universal Time)

#mel
star

Mon Jun 24 2024 03:38:13 GMT+0000 (Coordinated Universal Time)

#mel
star

Mon Jun 24 2024 03:36:50 GMT+0000 (Coordinated Universal Time)

#mel
star

Mon Jun 24 2024 03:34:20 GMT+0000 (Coordinated Universal Time)

#mel
star

Fri Jun 14 2024 04:21:49 GMT+0000 (Coordinated Universal Time)

#mel

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension