Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The script creates a given number of random objects, and creates random positions within in a volume of 10 m x 10 m x 10 m, scales, and colours:

 

Code Block
languagepy
import random
 
numOfObjects = 10
maxPosition  = 5.0
 
for i in range(0,10):
	randomObject = random.randint(1,4)
	randomScale  = random.uniform(0.5, 1.5)
 
	if (randomObject == 1): newObject = scene.addSphere(3)
	if (randomObject == 2): newObject = scene.addCapsule()
	if (randomObject == 3): newObject = scene.addCube()
	if (randomObject == 4): newObject = scene.addCone(10)
 
	posX = random.uniform(-maxPosition, maxPosition)
	posY = random.uniform(-maxPosition, maxPosition)
	posZ = random.uniform(-maxPosition, maxPosition)
 
	colR = random.randint(0,255)
	colG = random.randint(0,255)
	colB = random.randint(0,255)
 
	newObject.setParameter("Position", Vector.new(posX, posY, posZ))
	newObject.setParameter("Scale", Vector.new(1.0, 1.0, 1.0).scale(randomScale))
	newObject.setParameter("Color", Vector.new(colR, colG, colB))