Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import bpy from random import * # variables for object types BOX = 1 BALL1 = 2 BALL2 = 3 DONUT = 4 MONKEY_HEAD =
import bpy from random import * # variables for object types BOX = 1 BALL1 = 2 BALL2 = 3 DONUT = 4 MONKEY_HEAD = 5 def selectAll(): # select objects by type for o in bpy.data.objects: if o.type == 'MESH': o.select = True else: o.select = False # end selectAll def deleteAll(): selectAll() bpy.ops.object.delete() # end deleteAll # ADD YOUR FUNCTIONS BETWEEN THIS LINE ... # 1. function that returns three random integers, # each between -10 and 10 # ADD PYTHON CODE HERE # 2. function that creates a square box of random size # in the range [0.0, 1.0) at the given location (x, y, z) # ADD PYTHON CODE HERE # 3. function that creates a ball (icosphere) of random size # in the range [0.0, 1.0) at the given location (x, y, z) # ADD PYTHON CODE HERE # 4. function that creates a ball (uv sphere) of random size # in the range [0.0, 1.0) at the given location (x, y, z) # ADD PYTHON CODE HERE # 5. function that creates a donut (torus) of random size # in the range [0.0, 1.0) at the given location (x, y, z) # ADD PYTHON CODE HERE # 6. function that creates a monkey head of random size # in the range [0.0, 1.0) at the given location (x, y, z) # ADD PYTHON CODE HERE # ... AND THIS LINE # clear the render space deleteAll() # set the number of things as variable n # ADD PYTHON CODE HERE # create n objects for count in range(n): # set variables x, y, z to three random integers # by calling the function from step 1 # ADD PYTHON CODE HERE # set variable shape to a random integer # between 1 and 5 # ADD PYTHON CODE HERE if shape == BOX: # call function from step 2 with x, y, z # ADD PYTHON CODE HERE elif shape == BALL1: # call function from step 3 with x, y, z # ADD PYTHON CODE HERE elif shape == BALL2: # call function from step 4 with x, y, z # ADD PYTHON CODE HERE elif shape == DONUT: # call function from step 5 with x, y, z # ADD PYTHON CODE HERE elif shape == MONKEY_HEAD: # call function from step 6 with x, y, z # ADD PYTHON CODE HERE # end if # end for loop1. Download the incomplete CPS149 Class_Project 8.txt script (text) file 2. Open the CPS149_Class_Project_8.txt file in a text editor (e.g., NotePad++) Launch Blender 1. Switch to Scripting view 2. Create a new text data block 3. Copy/paste the contents of CPS149_Class_Project_8.txt into this text data block 4. Add the required functions and complete the Python script so that it creates a collection of randomly-sized objects placed in the render space at random When you're done, attach and submit your final Blender (.blend) file below. Notes The pre-defined random() function returns a random number in the range [0.0,1.0) The pre-defined randint (a,b) function returns a random integer i, such that a sisb The following Blender Python expressions create objects: bpy.ops.mesh.primitive_cube_add: creates a cube bpy.ops.mesh.primitive_ico_sphere_add: creates an icosphere o bpy.ops.mesh.primitive uv sphere_add: creates a uv sphere bpy.ops.mesh.primitive torus_ add: creates a torus bpy.ops.mesh.primitive_monkey_add: creates a monkey head To move an object thing to a location (x,y,z): thing(location-(x,y.z) To resize an object to a particular size on all three axes: bpy.ops.transform.resize(value-(size, size, size), constraint_axis-(False, False, False), constraint-orientation= 'GLOBAL. mirror = False, proportional= ' DISABLED', proportional-edit-falloff='SMOOTH. proportional_size-1, snap-False, snap_target-CLOSEST, snap point-(0, 0, 0), snap align-False, snap_ normal-(o, 0, 0). texture_space-False, release_confirm-False) 1. Download the incomplete CPS149 Class_Project 8.txt script (text) file 2. Open the CPS149_Class_Project_8.txt file in a text editor (e.g., NotePad++) Launch Blender 1. Switch to Scripting view 2. Create a new text data block 3. Copy/paste the contents of CPS149_Class_Project_8.txt into this text data block 4. Add the required functions and complete the Python script so that it creates a collection of randomly-sized objects placed in the render space at random When you're done, attach and submit your final Blender (.blend) file below. Notes The pre-defined random() function returns a random number in the range [0.0,1.0) The pre-defined randint (a,b) function returns a random integer i, such that a sisb The following Blender Python expressions create objects: bpy.ops.mesh.primitive_cube_add: creates a cube bpy.ops.mesh.primitive_ico_sphere_add: creates an icosphere o bpy.ops.mesh.primitive uv sphere_add: creates a uv sphere bpy.ops.mesh.primitive torus_ add: creates a torus bpy.ops.mesh.primitive_monkey_add: creates a monkey head To move an object thing to a location (x,y,z): thing(location-(x,y.z) To resize an object to a particular size on all three axes: bpy.ops.transform.resize(value-(size, size, size), constraint_axis-(False, False, False), constraint-orientation= 'GLOBAL. mirror = False, proportional= ' DISABLED', proportional-edit-falloff='SMOOTH. proportional_size-1, snap-False, snap_target-CLOSEST, snap point-(0, 0, 0), snap align-False, snap_ normal-(o, 0, 0). texture_space-False, release_confirm-False)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started