21 Aug Computer Science Homework(Python)
This work should be working on Blender
Part 1: Creating the Monkey Head Grid
First, make sure you include the following at the top of your script file:
import bpy
from math import *
def selectAll():
# select objects by type
for o in bpy.data.objects:
if o.type == ‘MESH’:
o.select = True
else:
o.select = False
return
def clearAll():
selectAll()
bpy.ops.object.delete()
return
Then, write a Python function that, given an integer n, creates a n×n grid of monkey head objects:
- First, set two of the three axes (e.g., x and y) at –n, and the third axis to 0
- Use a pair of nested loops, each looping n times
- Inside the inner loop:
- create a monkey head (bpy.ops.mesh.primitive_monkey_add)
- move it to (x,y,z)
- set up the location of the next head by incrementing one of the axes
- for example, if you are creating the grid on the x and y axes, x = x + 3
- Inside the outer loop
- after each completion of the inner loop (creating a row of heads), increment the other axis by 3 and reset the first axis to –n
- for example, if you are creating the grid on the x and y axes, y = y + 3 and x = –n
- after each completion of the inner loop (creating a row of heads), increment the other axis by 3 and reset the first axis to –n
Test your function by first clearing the 3-D view (i.e., by calling the clearAll function), then calling your function with the value 10.
Part 2: Rotating the Monkey Heads
Once your function from Part 1 is working, write another Python function to simulate the Peevish Postman Problem by rotating the monkey heads:
- Select all of the monkey heads as a list variable, using bpy.context.selected_objects
- Set n to the size of your heads list (i.e., use the len() function)
- Set a rotation variable to 180 degrees in radians (use the function math.radians(180))
- De-select all of the objects:
for obj in bpy.data.objects:
obj.select = False - Again use a pair of nested loops:
- In the outer loop, loop from 1 to n (for example, loop i from 1 to n)
- In the inner loop, loop from the current value of i to n by increments of i (for example, loop j from i to n in increments of i)
- Inside, the inner loop, rotate the head at index j-1 by the rotation on the third axis
- for example, if you created the grid on the x and y axes, rotate by the rotation on the z axis:
heads[j-1].rotation_euler.z += rotation
- for example, if you created the grid on the x and y axes, rotate by the rotation on the z axis:
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Wridemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
