Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using MEL language : Write a MEL script that visualizes (simulates) the Peevish Postman Problem: British puzzle maker H. E. Dudeney concocted an interesting puzzle

Using MEL language :

Write a MEL script that visualizes (simulates) the Peevish Postman Problem:

British puzzle maker H. E. Dudeney concocted an interesting puzzle about a bored postman called the Peevish Postman Problem. According to Dudeney, the postman worked in a small post office with consecutive letter boxes numbered 1 to 100. Each box was equipped with a door that could be opened and closed.

Late one evening the postman made a pass through the boxes and opened every door. Still bored, he walked back to the beginning and made a second pass, this time visiting boxes 2, 4, 6, , 100. Since those doors were now open, he closed them. On the third pass he visited boxes 3, 6, 9, 12, , 99 and if a door was open he closed it, and if the door was closed he opened it. He continued to make passes through the boxes and always followed the same rule: On each pass i from 1 to 100, he visited only boxes that were multiples of i, and changed the state of each door he visited. After making 100 passes at the doors, he surveyed the results and was surprised by the pattern of doors that he saw.

Part 1: Making Boxes by Scripting

We can visualize the post office boxes in Maya as a MEL script as follows:

Declare/initialize variables for two colors (e.g., $color1 and $color2); each color requires three float values (one for red, one for green, and one for blue). Note that you can either declare six float variables, or two vector variables for the two colors. Each float value must be between 0 and 1. Each of the three values for each vector must be between 0 and 1.

Declare an array of strings named $boxes.

Create a 10x10 grid of polyCubes:

Start from a negative X position (e.g., $xValue variable starting at -15) and a negative Z position (e.g., $zValue variable starting at -15)

Use a pair of nested for loops, each looping from 0 to 9 (e.g., $index1 for outer loop, $index2 for inner loop:In the outer loop:

Execute the inner loop

increment Z by a small amount (e.g., zValue = zValue + 3;)

In the inner loop:

make a polyCube with a sequentially-numbered name (e.g., "box1")

add the name to the $boxes array; e.g., $boxes[$index2] = $name, where $index2 is 0 for the first box, 1 for the second box, etc., and $name is the next sequentially-numbered box name. So, $boxes[0] is set to "box1", $boxes[1] is set to "box2", etc.

move the polyCube to the current X and Z positiosn (MEL command is move -a $xValue 0 $zValue)

color the polyCube with the first color variable from step 1 using the MEL polyColorPerVertex command:

if each color is three float variables: polyColorPerVertex -r $red -g $green -b $blue -a 1 -cdo; if each color is a vector variable: polyColorPerVertex -r $color1.x -g $color1.y -b $color1.z -a 1 -cdo;

add an bool keyable attribute named state with:

a minimum value of 0

a maximum value of 1

a default value of 0

increment X by a small amount (e.g., $xValue = $xValue + 3;

Part 2: Opening and Closing Post Boxes

We can visualize the postman opening and closing post office boxes in Maya as a MEL script as follows:

Using a pair of nested loops, simulate the postman opening and closing mailboxes:

In the outer loop, repeat 100 times from 1 to 100 to simulate the passes he makes over the mailboxes.

In the inner loop, start from the current pass number, then repeat to 100 by increments of the current pass number. During each repetition of the inner loop, check the state of the box. To get the value of the state attribute for an object, you will have to create and then eval a string representing the getAttr command (e.g., eval("getAttr " + $boxes[$number] + ".state");).

if the state is 0: change the object color to the second color from part 1, and change the state to 1 To set the value of the state attribute for an object, you will have to create and then eval a string representing the setAttr command (e.g., eval("setAttr " + $boxes[$number] + ".state 1");)

otherwise: change the object color to the first color from part 1, and change the state to 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

What is coherence, and how is it achieved?

Answered: 1 week ago