Thursday, May 8, 2014

Lab 3 - project

Problem: Grimm exercises. - Click here for detailed pdf instructions

Part 1:

The fantasy characters in Grimm stories want to change their public image (which is slovenly, overweight, and aggressive). They want to become more physically fit and friendly characters. With this in mind, Sam (Ogre) and Bill (Troll) are starting an exercise class for the Grimm community. Create an animation where Sam and Bill demonstrate knee bend exercises.
Initial Scene: In the Scene Editor, create an initial scene. Your scene doesn’t have to look exactly like the one shown below. However, it must have two fantasy characters, Sam (Ogre) and Bill (Troll) in an appropriate setting. Save the world as GrimmExercise.

Algorithm:

Of course, the Ogre and Troll classes do not have a knee bend procedural method. So, you will need to write your own kneeBend procedure for each class.
Decomposition: Start by decomposing the procedure into simple steps. Below is an example procedural decomposition, using the Ogre’s joint structure. This procedure is a bit more complicated than you might expect. This is because a knee bend is actually a combination of bending both knees and lifting both arms upward (for balance). In this example, the numbers specifying the amount of rotation for the joints is arbitrary. You may wish to experiment with other amounts to obtain a more realistic animation of a knee bend, although these amounts work fairly well.

Do in order
Sam knee bend
Bill knee bend
Do together
Sam knee bend
Bill knee bend

Implementation: Create and test the program code for a kneeBend procedure in the Ogre class. HINT: This procedure has two basic parts – one part to bend the knees and one part to straighten up. You can take advantage of this in creating the code. Create the first do together code block for the downward knee bend and then hold down the ctrl key (alt on Mac) to drag a copy below to make the second code block. Then, in the second code block, reverse the motion (for example, change move down to move up) for each statement.
Be sure to document and save your project before going on.

Part 2: Using the clipboard to duplicate code
At this point in the project code, Sam (an instance of the Ogre class) has a kneeBend procedure. But, Bill (an instance of the Troll class) does not. One way to create a kneeBend procedure for the Troll class is to use the clipboard to copy and paste the code from the Ogre class to the Troll class. The screen grabs on the next page illustrate the process of using the clipboard for copy and paste of an entire procedure.

(Step 1). In the procedure, if you have not already done so, add a Do in order block to enclose the two Do together blocks. Then, hold down the crtl key (alt on the Mac) and drag the entire Do in order block to the clipboard.

Do in order
//bend knees down

Do together
Entire body move down 0.125
Right and left hips turn backward 0.125
Right and left ankles turn forward 0.25
Right and left foot turn backward 0.15
Right shoulder turn left 0.25
Left shoulder turn right 0.25
//return to original position

Do together
Entire body move up 0.125 m
Right and left hips turn forward 0.125
Right and left ankles turn backward 0.25
Right and left foot turn forward 0.15
Right shoulder turn right 0.25
Left shoulder turn left 0.25

(Step 2). Create a new kneeBend procedure in the Troll class.

(Step 3). Paste the code for the kneeBend procedure into the Troll class kneeBend editor tab by dragging the code out of the clipboard onto the new procedure tab.

Now that both Ogre and Troll classes have a kneeBend procedure, complete the program as described in the algorithm at the beginning of this assignment.

Be sure to document and save the GrimmExercise project.

Friday, April 25, 2014

Alice - Lesson 3

  • Once you complete all of Lesson 2 Assignments, see me to get the Lesson 2 Chapter Test.
  • Lesson 3 Lecture:
Problem:  A penguin is bowling on the arctic ice cap. The penguin swaggers forward to push a bowling ball towards a bowling pin, knocking the pin over.  Surprisingly, the pin stands upright and then pushes the bowling ball back at the penguin. The penguin is knocked over.

Algorithm:  This is the problem we used as our classroom demo example for illustrating how to write a procedure.  The algorithm (slightly revised) is shown here:

Do in order
     penguin move forward (toward the ball)
     penguin swagger
     penguin push the ball (to bump into the pin)
     pin falls over
     pin responds (stands upright and pushes the ball back to the penguin)
     penguin falls over
 
 







Initial Scene: Download the file named PenguinBowlingWarmUp.a3p and open the project in Alice 3. Also, the Penguin class has swagger and pushObject procedures, as we demonstrated in class.
1.  Complete implementation of the PenguinBowling project.
Write procedures: Your task in this warmup exercise is to complete the animation by writing the following procedural methods:
                   1)  For the Pin class, fallOver, where the pin falls over backward
                   2)  For the Pin class, pushObject, where the pin stands up and pushes the ball back to the penguin
                   3)  For the Penguin class, fallOver, where the penguin falls over backward
Reminder:  Be sure to document each procedure, as illustrated in classroom demos.
Test:  Test each procedural method as you write it and revise, if needed. 
Save:  When you have completed the animation, save this project as PenguinBowlingComplete

Friday, April 11, 2014

Section 2 Lesson 3: Chapter Summary & Projects

Chapter Summary & Projects
Section 2 Lesson 3: Using Procedures


Click here for Assignment as a Word Doc

Objectives

                   Toggle and describe the visual difference between the scene editor and code editor
                   Correlate storyboard statements with program execution tasks
                   Identify the correct procedure to move an object in a scene
                   Use procedures to move objects in a scene
                   Add Java programming procedures to the code editor
                   Demonstrate how procedure values can be altered
                   Add a control statement to the code editor
                   Use random numbers to randomize motion 

Vocabulary

Directions: Identify the vocabulary word for each definition below.


1.  An object's sense of direction.

2.  Program code executed once to define a single movement for an object in a scene.

3.  Tells Alice 3 how to implement the instructions in a program.

4.  A list of instructions that are required to accomplish a task.

5.  A piece of program code that defines how the object should execute a task.

6.  Sequence of numbers generated by a computer with no pattern in their sequence.

7.  Describes how to perform the procedure.

8.  Tell the objects in the animation how to perform tasks.



Go for it!

1.    (10 points) Create an animation with the correct procedures, directions, and distances based on the following scenario: A camel starts at the back left corner of the scene (the viewer's left), walks towards the camera 3 meters, then walks towards a rock 2 meters, stops for 2 seconds, then turns to the left 0.5 meters and walks forward 10 meters. Ensure that the animation works as intended at run-time, and debug if necessary.

2.    (10 points) Create an animation with the correct procedures, directions, and distances based on the following scenario: A ship starts at the back left corner of the scene (viewer's left), moves toward the camera 5 meters, then turns 1 meter to the right while simultaneously moving forward 10 meters. Ensure that the animation works as intended at run-time, and debug if necessary.

3.    (5 points) Add an object to a scene. Use a procedure to position the object so that it is 8 meters right, 1 meter above, and 15 meters in front of the center of the virtual world.

4.    (5 points) Add a tortoise and a hare to a scene in the grass template. Using the “drag and drop” method and handle styles, do the following:
a.    Drag and drop the objects so that the tortoise is to the left of the hare.
b.    Move the hare so it faces the back of the scene.
c.    Resize the tortoise so it is two times larger than the hare.
d.    Make the hare appear to lie down on the grass.

6(15 points) Create an animation for the following scenario: Five playing cards simultaneously move, turn, and roll in order. Create a new procedure for this motion. Run the animation, then alter the distance and duration argument values in the procedure and run the animation again to see how the playing card's movements change.

.    (15 points) Create an animation that uses the roll procedure to make three penguins appear to roll from the back to the front of the scene simultaneously. Hint: The penguins must be positioned on their side in the scene editor to achieve this motion. Once you make all three penguins roll, change the number of rolls to a random number between 1 and 5.

((5 points each classmate) With a classmate, conduct a peer review of your animation's code for one of your completed animations. Discuss what procedures and arguments you used, and what worked and didn't work

    I reviews the work of ______________________, and determined that ______________________________________________________.

8.    (5 points) In an animation scene, use five procedures that you have not yet used before. In your journal, create an entry entitled “New Procedures”. List the procedures you used, and describe how each instructed the objects to move.

9.    (10 bonus points) Create an animation for the following scenario: Place a teacup on top of a tea plate (MyProps class folder). Have the tea cup and tea plate turn simultaneously in opposite directions. Run the animation.  


Wednesday, April 9, 2014

Rotation and Randomization

Compare turn and roll procedures

Object movement


Object movement is egocentric – objects move relative to the direction they currently face.
An object can move in six directions:
  • Up
  • Down
  • Forward
  • Backward
  • Right
  • Left

Examples of rotation procedures


ProcedureDescription
Turn
Rotates objects left, right, forward, and backward on their center point.
Roll
Rolls objects left and right on their center point.

Comparison of turn and roll procedures


The object turns right and left on its center point using a vertical axis:
Turn 1
The object rolls right and left on its center point using a horizontal axis:
Roll 1
Some objects have moveable sub-parts that can turn and roll.
The pocketwatch has moveable hour and minute hands that can roll on the clock's center point:
Clock 1

Demo: Comparing different ways objects can turn and roll
Watch this video to see a comparison of turn and roll procedures.


Program objects to rotate

Object rotation


Steps to program an object to rotate:
  1. Select the instance of the object to rotate.

    Select Yeti
  2. Drag a turn or roll procedure to the Code editor.

    Select Turn
  3. Select a value for the direction argument.
  4. Select a value for the amount argument (1.0=one full turn or roll).

    Turn Arguments

Turn and roll procedures


ProcedureDescription
Turn
Rotates objects left, right, forward, and backward on their center point.
Roll
Rolls objects left and right on their center point.
Note: The key to successful rotation is knowing the center point of an object.

Demo: Programming objects to rotate
Watch this video to learn how to program objects to rotate in Alice 3.
Try It: Program an object to rotate
Download:
The Try it activity below requires that you start with the project file that was saved in the previous topic. Download this Alice 3 project file if you did not complete the previous topic's Try it activity.

Instructions:
  1. Open the WhiteRabbitProject file that you saved in the previous topic, or download the project file above.
  2. Program the White Rabbit to do one complete turn to the left.
  3. After a short delay, have the rabbit circle around the hedge and return to the same spot.
  4. Save the project.

Tuesday, April 8, 2014

3.3 - 3.5 Editing Arguments

Edit arguments

Arguments

Arguments are selected after the procedure is dropped onto the Code editor.
Argument types may include:
  • Direction
  • Amount
  • Duration
  • Text
Argument

The argument menu offers default argument values or, if none of the defaults are suitable, a custom option so that you can specify a more accurate argument value.

Terminology
An argument is a value used by the procedure to perform a precise task. A procedure may require one or more arguments that tell it precisely how to perform a task. Some examples of Alice 3 arguments are: object direction, direction amount, distance, and time duration.

Edit arguments


A procedure’s arguments may be edited or further defined to control object movement and timing.
An argument defines the degree to which an action is performed by the procedure.
Three Arguments

Steps to edit arguments


  1. Next to the argument’s value, click the arrow to display the menu of values.
  2. Select a new value.
  3. Use the Custom Decimal Number option to specify a value that differs from the default list of values.
Edit Arguments

Arguments as placeholders


When a procedure is dropped into the Code editor, all argument values must be specified even if you are unsure of the perfect value to use to perform the task. In those instances, you will select an argument value simply as a placeholder value that you will later replace.

For example, you may want an object to move forward but you're not sure how far. You can select a placeholder value of 2 meters, run the animation, determine that a larger number is needed, and then edit the value to something larger. You can also specify a placeholder value that will be replaced with a function or a variable. These techniques are described in another topic.

Demo: Editing arguments in procedures
Watch this video to learn how to edit the arguments in a procedure in Alice 3.
Try it: Edit arguments in a procedure
Download:
The Try it activity below requires that you start with the project file that was saved in the previous topic. Download this Alice 3 project file if you did not complete the previous topic's Try it activity.

Instructions:
  1. Open the WhiteRabbitProject file that you saved in the previous topic, or download the project file above.
  2. Edit the arguments in the move procedures so that the White Rabbit moves 1 meter to the left and then .25 meters to the right.
  3. Save the project.

Reorder, edit and delete

Steps to reorder programming statements


  1. Click the handle of the programming statement.
  2. Drag the programming statement to its new position.
  3. Drop the programming statement in its new position.
Note that a green position indicator line will appear to help you align the programming statement in the desired position.
Reorder

Edit programming statements


Use the drop-down lists to edit the values of the arguments in a programming statement.
Edit Arguments

Delete programming statements


Right-click programming statements to delete them.
Delete

Demo: Reordering, editing, copying, and deleting programming statements
Watch this video to learn quick ways to modify your code.

Test and debug

Edit and test the program


Run the animation to test it, and the edit the code as necessary. It may take several cycles of testing and editing to get the animation to run as desired.
Click Run2

Testing and debugging


Testing and Debugging is the process of running the animation many times, adjusting the control statements, procedures, and arguments after each execution to verify that the animation executes as expected.
Save often while debugging your program. 
Debug
You can insert temporary programming statements into your code to help with debugging. For example, if the baby yeti above is supposed to turn towards the hole in the ice, but he doesn't, you can insert a Say procedure just before the Turn procedure and click Play.
If the yeti Says something but still doesn't move, you know that the animation is at least reaching the Move procedure, so the problem lies within the procedure itself. However, if the yeti does not Say something, you know that the Move procedure is not the problem because the animation is not even reaching the procedure.
This is a simple example, but when working with complex animations where randomization or hidden movements are occurring, you may need to employ a debugging method such as this to help pinpoint the problem.

Demo: Testing and debugging the program
Watch this video to see an example of the testing and debugging process.
Try it: Test and debug the program
Download:
The Try it activity below requires that you start with the project file that was saved in the previous topic. Download this Alice 3 project file if you did not complete the previous topic's Try it activity.

Instructions:
  1. Open the WhiteRabbitProject file that you saved in the previous topic, or download the project file above.
  2. Test, edit, and debug the program so that the White Rabbit moves more gently using the animation style Begin and End Gently.
  3. Save the project.
Try it: Reorder, copy, edit and delete programming statements
Download:
The Try it activity below requires that you start with the project file that was saved in the previous topic. Download this Alice 3 project file if you did not complete the previous topic's Try it activity.

Instructions:
  1. Open the WhiteRabbitProject file that you saved in the previous topic, or download the project file above.
  2. Reorder the "Move" programming statements so that the White Rabbit moves right 1 meter, and then moves left 1 meter.
  3. Copy and edit programming statements so that the White Rabbit moves right .5 meters and then left 2 meters, and then right 1 meter.
  4. Delete a programming statement so that the White Rabbit no longer says "hello".
  5. Save the project.