Exercise 01 – Box array

This is a small exercise to test what you just have learned… Lets create an array of boxes and add some random height values to them…

To use the random command in maxscript you do
myValue = random 1 200 –this creates a random value between 1 and 200

—– Start of script

--Start of script
delete $Exercise01* --this is for testing purpose

--It is always good practice to store variables
NmbrOfCopies = 10 --how many copies to make
DistanceBetweenBoxes = 50.0

for x = 1 to  NmbrOfCopies do (
mybox = box name:"Exercise01"
mybox.pos = [x * DistanceBetweenBoxes,0,0]
mybox.height = random 10.0 170.0
)

Here is a different version of the script that does X and Y copies and also changes the color of the boxes depending on distance from the camera…

Btw you need to create a target-cam for this to work!

--Start of script
delete $Exercise01* --this is for testing purpose

--It is always good practice to store variables
NmbrOfCopies = 30 --how many copies to make
DistanceBetweenBoxes = 50.0

--you need a camera in the scene
myCam = $camera001
distanceFromCam = 2100.0

for x = 1 to  NmbrOfCopies do (
	for y = 1 to NmbrOfCopies do (

	DoABox = random 0 1
		if 	DoABox == 1 then (
	mybox = box name:"Exercise01"
	mybox.pos = [x * DistanceBetweenBoxes, y * DistanceBetweenBoxes,0]
	mybox.height = random 10.0 170.0
	theMod = (taper())
	theMod.amount = random 0.1 -.5
	addModifier myBox theMod 

		if (distance myCam.pos myBox.pos) > distanceFromCam then (
				mybox.wirecolor = [255,0,0]
			) else
			(
				mybox.wirecolor = [0,255,0]
			)
	)
	)
)