Escolar Documentos
Profissional Documentos
Cultura Documentos
Objectives
This lesson covers the following objectives:
Use functional decomposition to write a scenario and
storyboard
Complete an animation
Test an animation
Reposition objects at runtime
Plan a presentation of a completed animation project
Animations
An animation is a sequence of actions that simulate
movement. Use Alice 3 to program what the animation
should do, and Alice 3 will render the animation for you.
Rendering is a process where the software program converts
your code into the animation that you see. Alice 3 renders the
animation based on the instructions provided by the
programmer.
Step 2:
Develop a Solution
Step 3:
Implement the
Solution
Step 4:
Test and Revise the
Solution
Step 3:
Program the
Animation
Step 4:
Run the Animation
Step 2:
Design a
Storyboard
Scenario Type
Scenario
Animation
Teach a concept.
Memorizing chemistry
symbols is difficult.
Simulate or demonstrate a
process.
A demonstration shows
how to change a tire on a
virtual car.
Play a game.
Storyboard Formats
Develop your visual and textual storyboards using a
variety of formats.
Examples:
Draw them on paper with a pencil.
Create them using digital tools such as a word
processor, drawing software, or presentation program.
Write a textual storyboard within Alice 3 in the Code
editor using comments to organize the steps in your
program.
10
Visual Storyboards
The visual storyboard helps a reader understand:
The scene components.
How the initial scene will be set up.
The moving and non-moving objects in a scene.
The actions that will take place.
If there are any user interactions that occur during the
animation execution.
11
12
Textual Storyboards
Textual storyboards help a reader understand the actions
that will take place during the animation.
The moving and non-moving objects can be identified
based on the action statements, but would need further
description for another programmer to implement an initial
scene as originally imagined by the author of the
storyboard.
In computing, a textual storyboard is called an algorithm: a list of
actions to perform a task or solve a problem.
13
15
Storyboard Components
Textual storyboards should contain the objects listed in the table
below to support the program development of the animation.
16
Component
Definition
Examples
Scene
Objects
Moving or non-moving
characters that you program to
move and act.
Actions
User Interactions
Keyboard commands or
mouse clicks to make
objects move
Design Specifications
True
Boy leaves
phone on
bench
Girl does
nothing
Boy stops,
turns around,
comes back to
bench, says
Thank you
Boy keeps
walking
End
17
False
18
19
Animation Checklist
During the animation development process, use this
checklist to ensure that your animation meets all
animation principles.
20
21
Declared procedures
Functions
Movement procedures
Random numbers
Math expressions
Variables
Keyboard controls
22
Debugging Tasks
Test and debug the animation frequently as it is
developed. Use some of the following debugging
techniques:
Adjust the direction, distance, and duration that objects
move.
Adjust math calculations that help refine the distance or
duration that objects move.
Refine instructions in the code that do not work as
intended.
Resolve errors created by the programmer.
23
24
26
27
28
29
30
Group Presentations
If you will be making your presentation with a group, here
are some steps your group can follow to make sure all
group members have a part in preparing and delivering
the presentation.
Include all group members in all steps of the
presentation planning.
Divide presentation tasks equally among group
members.
Practice the presentation as a group, and give each
other constructive feedback before the presentation
delivery.
31
Summary
In this lesson, you should have learned how to:
Use functional decomposition to write a scenario and
storyboard
Complete an animation
Test an animation
Reposition objects at runtime
Plan a presentation of a completed animation project
32
33
Objectives
This lesson covers the following objectives:
Describe the purpose for using Alice 3 to learn Java
Check system requirements needed for the course
Install necessary software for the course
34
What is Alice 3?
Alice 3 is an integrated development environment (IDE)
that helps you quickly and easily learn the basics of
computer programming using characters that interact in a
virtual 3D world. It was created by Carnegie Mellon
University.
The best part about Alice 3 is that you learn to program
without even realizing it, and its fun!
35
36
Three-Dimensional Objects
Alice 3 uses three-dimensional (3D) objects that
programmers can drag-and-drop into a scene to create a
virtual world.
37
Virtual World
You will use Alice 3 and your imagination to create a virtual
world.
Your virtual world will contain the following 3D objects:
The Setting: stationary objects (trees, rocks, or buildings).
Actors: objects that move (people, animals, or vehicles).
The Background: a template onto which you place both
setting and actor objects.
38
39
40
Alice 3 Animations
The programming instructions in an Alice 3 project can be
run to create an animation.
An animation is a series of independent still images that, when
viewed rapidly one-after-another, creates the illusion of
movement.
41
42
Summary
Alice is a programming environment that makes it easy
and fun to create an animation for telling a story, playing
an interactive game, or sharing a video on the web.
44
45
System Requirements
Ensure that your system meets the minimum system requirements for
running Alice 3.
46
System Component
Minimum Requirement
Processor
Pentium 4 or higher
Operating System
Browsers
Memory
1 GB
System Requirements
47
(continued)
System Component
Minimum Requirement
Graphics
Sound Card
Required
Software
48
49
51
52
53
55
56
57
58
Summary
In this lesson, you should have learned how to:
Describe the purpose for using Alice 3 to learn Java
Check system requirements needed for the course
Install necessary software for the course
59
60
Objectives
This lesson covers the following objectives:
Identify scene components
Create and save a new project
Add an object to a scene
Communicate the value of saving multiple versions of a
scene
Code a simple programming instruction
Use the copy and undo command
Understand the value of testing and debugging
61
Initial Scene
An initial scene is the starting point of your animation. It
has three components:
A background template which provides the sky, ground,
and light.
Non-moving scenery objects which provide the setting.
Moving objects which provide the action.
The initial scene is the first scene of an animation where you
select the background template and position the objects.
62
63
Ocean floor is a
template.
64
65
66
67
68
70
71
Scene Editor
In the Scene editor, you can:
Select objects from the gallery to add to the scene.
Position objects in the scene using the Handles palette.
Edit an object's properties using the Properties panel.
Access the Code editor to add programming statements.
Run the animation after the programming statements are
added to the Code editor.
72
73
Gallery
The gallery is a collection of three-dimensional objects
that you can insert into the scene.
The gallery is organized using tabs.
To find objects, browse the gallery tabs or use the
Search Gallery feature to search by keyword.
Breadcrumb menus display as you select classes.
74
Gallery Tabs
The gallery has five tabs:
75
Tab
Function
Search Gallery
Shapes/Text
Select a Class
The Class Hierarchy tab groups objects by mobility type
(biped, flyer, prop, quadruped, swimmer).
A class contains the instructions that define the appearance and
movement of an object. All objects within a class have common
properties. The class provides instructions to Alice 3 for creating
and displaying the object when it is added to your scene.
76
Class Example
Classes can contain sub-classes. Consider the example
below.
The chicken class is a sub-class of the Flyer class.
There are two chicken sub-classes in the gallery.
Every chicken added to a scene inherits the properties
that all Flyer objects have in common: two legs, two
wings, the ability to fly, etc.
77
78
79
Code Editor
Click the Edit Code button to display the Code editor. The
Code editor is where you add the programming
instructions to program your animation.
80
Methods Panel
The Procedures tab, located within the Methods Panel in
the Code editor, displays pre-defined methods for the
selected instance, as well as methods defined for the
class of objects.
A procedure is a piece of program
code that defines how the object
should execute a task. Alice 3 has
a set of procedures for each
class; however, users can create
or "declare" new procedures.
81
82
83
84
85
86
87
88
89
Undo an Action
Undo an action using the Undo option on the Edit menu,
or the keyboard shortcut CTRL + Z.
90
91
92
93
94
Summary
In this lesson, you should have learned how to:
Identify scene components
Create and save a new project
Add an object to a scene
Communicate the value of saving multiple versions of a
scene
Code a simple programming instruction
Use the copy and undo commands
Understand the value of testing and debugging
95
96
Objectives
This lesson covers the following objectives:
Open a saved version of a project
Add multiple objects to a scene
Describe the difference between precise positioning and
drag-and-drop (or imprecise) positioning
Use a one-shot procedure to precisely position an object
in a scene
97
Objectives (continued)
This lesson covers the following objectives:
Edit properties of an object in the Scene editor
Describe three-dimensional positioning axes
Position the sub-parts of an object in the Scene editor
98
99
10
0
10
1
10
2
10
3
Object Orientation
Objects (and their sub-parts) move relative to their own
orientation, or sense of direction.
An object that is facing toward the back of the scene,
programmed to move forward 2 meters, moves 2 meters
further toward the back of the scene.
10
4
10
5
10
6
One-Shot Procedures
Precise / Imprecise Positioning
One-shot procedures:
Are used to make scene adjustments and position
objects.
Are not executed when the Run button is selected to
play the animation.
A procedure is a set of instructions, or programmed code, for
how the object should perform a task. One-shot procedures
are available in the Scene editor. They are the same as the
procedures in the Code editor; however, they only execute
one time to re-position the object, unlike in the Code editor
where they will execute every time the Run button is clicked to
play the animation.
10
7
10
8
OR
1. Select the one shots procedure menu in the Properties panel.
2. Select procedures.
10
9
11
0
Positioning Example
Precise / Imprecise Positioning
Sometimes it is convenient to have many instances
positioned in the center of the scene. For example:
If you want to put several yetis on a floating ice floe, add
the ice floe and yetis to the center of the scene first.
Move them with one-shot procedures as opposed to
trying to drag-and-drop them into the correct location on
top of the floating ice floe.
11
1
Position Property
Precise / Imprecise Positioning
The Position property tells you where the object is
positioned in the scene on the x, y, and z axes.
11
2
11
3
11
4
Description
Default
Rotation
Translation
Resize
11
5
Note: If you select a very large object in the scene, and then
select the Resize handle, the positioning arrow that helps you
resize the object may appear off of the screen. If this
happens, select the Resize handle and then use the scrolling
button on your mouse to resize the object.
11
6
Modifying Properties
Properties can be modified during scene setup and
during animation execution. For example:
Change the Opacity property of an instance to 0 during
scene setup to make it disappear.
Create a programming statement to set the Opacity
property of the instance to 1 so the instance reappears
in the scene during execution of the animation.
11
7
11
8
11
9
12
0
Summary
In this lesson, you should have learned how to:
Open a saved version of a project
Add multiple objects to a scene
Describe the difference between precise positioning and
drag-and-drop (or imprecise) positioning
Use a one-shot procedure to precisely position an object
in a scene
12
1
Summary
(continued)
12
2
12
3
Objectives
This lesson covers the following objectives:
Toggle between, and describe the visual differences
between, the Scene editor and the Code editor
Locate and describe the purpose of the methods panel
and the procedures tab
Use procedures to move objects
Add Java programming procedures to the Code editor
12
4
Objectives
(continued)
12
5
12
6
Select Instance
First, select the instance that you
want to program; this will insure that
you are creating a programming
instruction for the correct instance.
You can select an instance by
clicking on the instance in the small
scene window or by using the
instance pull down menu below the
small scene window.
12
7
Methods Panel
The methods panel contains two tabs:
Procedures: All pre-defined procedures for an object.
Functions: All pre-defined functions for an object.
12
8
Procedures Tab
The Procedures tab displays pre-defined procedures for
the selected instance, as well as procedures of your own
that you define.
A Procedure is a piece of
program code that defines how
the object should execute a task.
Alice 3 has a set of procedures
for each class; however, users
can create (declare) new
procedures of their own.
12
9
Functions Tab
The Functions tab displays pre-defined functions for the
selected instance, as well as functions of your own that
you define.
A Function computes and
answers a question about an
object, such as, What is its width
or height?, or What is its
distance from another object?
Alice 3 has a set of functions for
each class; however, users can
declare new functions of their
own.
13
0
13
1
Control Structures
At the bottom of the myFirstMethod tab you will find the
Alice control structures.
13
2
13
3
13
4
13
5
Object Movement
Object movement is egocentric: Objects move based on
the direction they face.
An object can move in six directions:
Up
Down
Forward
Backward
Right
Left
13
6
13
7
Procedure
Description
Move
Move Toward
Move To
Moves the object from its current position to the center point
of the target object.
Moves the object from its current position to the center point
of the target object and adjusts the objects orientation to
match the orientation of the target object.
Delay
Say
13
8
Procedure
Description
Turn
Roll
Arguments
Arguments are selected after the procedure is dropped
onto the Code editor. Argument types may include:
Object
Direction
Direction amount
Time duration
Text
An argument is a value that the procedure uses to complete its
task. A computer program uses arguments to tell it how to
implement the procedure.
13
9
Argument Menu
The argument menu offers default argument values to
select from. If none of the defaults are suitable, select the
Custom DecimalNumber option so that you can specify
a more accurate argument value.
14
0
14
1
Arguments as Placeholders
When a procedure is dropped into the Code editor, all
argument values must be specified. There will be times
that you select an argument value as a temporary
placeholder value that will be replaced later.
For example, you may want an object to move forward but
you are not sure how far. You can select a placeholder
value of 2 meters, run the animation, determine that a
different value is needed, and then edit the value. You can
also specify a placeholder value that you will replace later
with a function or a variable.
14
2
*Note: A green position indicator line will appear to help you align the
programming statement in the desired position.
14
3
14
4
14
5
14
6
14
7
14
9
15
0
15
1
Programming Comments
Including programming comments in an animation helps
humans understand the flow of the programming.
Comments:
Describe the intention of the programming instructions.
Do not affect the functionality of the program because
they are ignored during its execution.
Are typically placed above the block of programming
statements that it describes.
Are often written first, in large programs, as an outline of
the programming instructions.
15
2
15
3
15
4
Summary
In this lesson, you should have learned how to:
Toggle between and describe the visual differences
between the Scene editor and Code editor
Locate and describe the purpose of the methods panel
and procedures tab
Use procedures to move objects
Add Java programming procedures to the Code editor
15
5
Summary
(continued)
15
6
15
7
Objectives
This lesson covers the following objectives:
Correlate storyboard statements with program execution
tasks
Add a control statement to the Code Editor
Use random numbers to randomize motion
15
8
16
0
16
1
Storyboard Action
Programming Instructions
Do in order
Do together
16
2
Object Movement
Object movement is egocentric: Objects move based on
the direction they face.
An object can move in six directions:
Up
Down
Forward
Backward
Right
Left
16
3
16
4
Procedure
Description
Turn
Roll
16
5
16
6
Control Statements
Control Statements define how programming statements
are executed in the program. myFirstMethod is created
with a default Do in order control statement. Within it, all
programming statements execute sequentially by default.
16
8
Procedure
Description
Do in order
Do together
Count
While
16
9
17
0
Sub-Part Rotation
Some objects have moveable sub-parts.
For example, the baby Yetis head can turn or roll.
Rotation can be applied to an entire object, or select
sub-parts of the object.
An object's head displays rings that show its range of
motion.
17
3
Random Numbers
Random numbers are numbers generated by the
computer with no predictable pattern to their sequence.
Random numbers are generated within a given range of
numbers.
Computers may require random numbers for:
Security: for example, randomly generated passwords.
Simulation: for example, earth science modeling
(e.g., erosion over time).
17
5
17
6
17
7
17
8
17
9
Summary
In this lesson, you should have learned how to:
Correlate storyboard statements with program execution
tasks
Add a control statement to the Code Editor
Use random numbers to randomize motion
18
0
18
1
Declare Procedures
Objectives
This lesson covers the following objectives:
Describe when to implement procedural abstraction
Demonstrate how to declare a procedure
Identify and use procedural abstraction techniques to
simplify animation development
18
2
Declare Procedures
Inherited Characteristics
Lets examine how a Dalmatian inherits its characteristics:
Characteristics of the Dog class (the parent class or
superclass) include four legs, two eyes, fur, and the
ability to bark.
Characteristics of the Dalmatian breed class (the child
class or subclass, which is a subset of the dog class)
include white fur, black spots, and other characteristics.
Dog Class
(Superclass)
Dalmatian Class
(Subclass)
18
3
Declare Procedures
Class Inheritance
Just like animals in the real world, objects in the
programming world inherit the characteristics of their
class, including all of the class's methods (procedures
and functions).
For example, all objects within the quadruped class in
Alice inherit the quadruped characteristics of four legs, a
head, a body, etc. Within this quadruped superclass,
subclasses exist for dogs, cats, wolves, lions, cows, etc.
Each subclass adds characteristics that more specifically
identify the objects within it.
18
4
Declare Procedures
Inheritance
When a Dalmatian object is created, it inherits
procedures, functions, and properties from the
quadruped class and the Dalmatian subclass that you
can view in the Code editor.
Inheritance means that each subclass
object inherits the methods and properties
of its superclass.
18
5
Declare Procedures
18
6
Declare Procedures
myFirstMethod Tab
The myFirstMethod tab is displayed by default when the
Code editor is opened.
18
7
Declare Procedures
Class Hierarchy
Click the class hierarchy drop-down menu to the left of
the myFirstMethod tab (indicated by a down-pointing
arrow) to view the list of classes and subclasses in your
animation.
18
8
Declare Procedures
18
9
Declare Procedures
Procedural Abstraction
Review the existing code or the textual storyboard to
identify and plan the methods that you need to declare in
your program.
19
0
Declare Procedures
19
1
Declare Procedures
19
2
Declare Procedures
19
3
Declare Procedures
19
4
Declare Procedures
19
5
Declare Procedures
Bird flies
19
6
Do together:
Declare Procedures
19
7
Declare Procedures
4. A new tab with the name of the procedure will open. Write the
code for the procedure. Add the new procedure to myFirstMethod
right away so that when you test the animation in myFirstMethod,
you are also testing the animation in the new procedure.
19
8
Declare Procedures
19
9
Declare Procedures
20
0
Declare Procedures
Declare Procedures
20
2
Declare Procedures
20
3
Declare Procedures
Declare Procedures
20
5
Declare Procedures
20
6
Declare Procedures
Declare Procedures
Summary
In this lesson, you should have learned how to:
Compare and define an animation and a scenario
Use functional decomposition to write a storyboard
Flowchart a storyboard
Describe inheritance and how traits are passed from
superclasses to subclasses
20
8
Declare Procedures
Summary
(continued)
20
9
21
0
Objectives
This lesson covers the following objectives:
Define multiple control statements to control animation
timing
Create an animation that uses a control statement to
control animation timing
Recognize programming constructs to invoke
simultaneous movement
21
1
Arguments
The arguments of a procedure may be edited or further
defined to control object movement and timing.
Examples of Alice 3 arguments include:
Object
Direction
Direction amount
Time duration
A computer program requires arguments to tell it how to
implement the procedure.
21
2
Arguments Display
Below are examples of arguments in a procedure.
21
3
21
4
21
5
Simultaneous Movements
To create simultaneous movements for an object, use the
Do together control statement.
Control Statement
Do In Order
Do Together
21
6
Description
Default control statement in Code editor.
Executes procedures in sequential order.
Executes procedures simultaneously.
Used for simultaneous movements such as walking and
sitting motions.
21
7
21
8
Programming Instructions
Left hip turns forward
Whole body moves forward
Left hip turns backward
Do Together
Do Together
22
0
22
1
setVehicle Procedure
The setVehicle procedure employs the concept of a rider
object and a vehicle object.
The rider object is selected when the setVehicle
procedure is used to specify the vehicle for the rider.
Then, when the vehicle object is programmed to move,
the rider object will automatically move with it.
Examples:
Person rides a camel or horse.
Camera follows a helicopter to shoot the scene from the
helicopters point of view.
22
2
22
3
22
4
22
5
22
6
Summary
In this lesson, you should have learned how to:
Define multiple control statements to control animation
timing
Create an animation that uses a control statement to
control animation timing
Recognize programming constructs to invoke
simultaneous movement
22
7
22
8
Use Functions
Objectives
This lesson covers the following objectives:
Use functions to control movement based on a return
value
22
9
Use Functions
Functions
Functions:
Are used to ask questions about properties of an object.
Are similar to procedures except that they return a value
of a particular type.
Can be used to compute a value.
Functions answer questions about an object, such as its height,
width, depth, and even its distance to another object.
23
0
Use Functions
Use Functions
Functions Tab
The Functions tab is in the methods panel. Select the
object from the Instance menu, and then view its
functions.
23
2
Use Functions
23
3
Use Functions
23
4
Use Functions
5. From the Functions tab, drag the getDistanceTo tile onto the
highlighted distance value.
6. Select the target object.
23
5
Use Functions
23
6
Use Functions
23
7
Use Functions
Avoid Collisions
You can enhance function calls using the math operators
(+) addition, (-) subtraction, (*) multiplication, and (/)
division.
For example, you can reduce the distance an object will
move to avoid a collision.
23
8
Use Functions
Rock
X = Get distance from lioness to rock
Y = Get width of rock
Z = X (Y / 2)
23
9
Use Functions
Rock
X = Get distance from lioness to rock
Y = Get width of rock
24
0
Use Functions
Lioness
Rock
X = Get distance from lioness to rock
Y = Get width of rock
24
1
Use Functions
2. Select Math.
3. Select the getDistanceTo subtraction option.
4. Select the distance amount.
5. Run the animation to test how the object moves at runtime.
24
2
Use Functions
24
3
Use Functions
Use Functions
Lion
Rock
Distance from lioness to rock
Lioness depth
24
5
Use Functions
Lioness
Rock
Distance from lioness to rock
Lioness depth
24
6
Use Functions
2. Run the animation to test how the object moves at runtime. Adjust
with additional math calculations if necessary.
24
7
Use Functions
Summary
In this lesson, you should have learned how to:
Use functions to control movement based on a return
value
24
8
24
9
Objectives
This lesson covers the following objectives:
Use the IF control structure to effect execution of
instructions
Use the WHILE control structure to create a conditional
loop for repetitive behavior
25
0
Control Structures
Control structures are pre-defined statements that
determine the order in which programming instructions
are executed.
You should be familiar with the Do together and Do in
order control structures from previous topics.
25
1
25
2
25
3
25
4
25
5
25
6
25
7
IF Control Structure
The IF control structure requires a condition of true or
false when the structure is dragged into the program.
This initial condition is a placeholder. You will need to
establish the condition to be evaluated.
25
8
25
9
26
0
26
1
26
2
If it rains
today, then
Do this: Wear
sweater
Do this: Wear
raincoat
End
26
3
False
If cat
collides with
dog
Do this: Cat
continues to
walk
Do this: Cat
says, Excuse
me!
End
26
4
False
4. Insert the procedures that will execute if the condition is true (IF)
and those that will execute if the condition is false (ELSE).
5. Run the animation to test the conditional behavior. Debug as
necessary.
26
5
26
6
Conditional Execution
The use of conditional control structures allows two types
of loops:
Conditional loop: Stops when a condition is true.
Example: The propeller of a helicopter turns while the
helicopter is moving or flying. If the helicopter stops, then
the propeller stops turning.
26
7
WHILE Statement
The WHILE statement performs conditional loops.
While a condition is true, the programming instructions
within the loop are executed.
Once the condition is no longer true, program execution
will skip the WHILE condition and continue with the
programming instruction that follows the WHILE loop.
The WHILE control statement will perform instructions while a
condition is true; otherwise it will bypass the instructions.
26
8
While the
Queen is
collision-free
Queen stops
and turns
around
Queen moves
forward
End
26
9
False
27
0
27
1
27
2
Summary
In this lesson, you should have learned how to:
Use the IF and WHILE Control Structures to control
movement based on a return value
27
3
27
4
Use Expressions
Objectives
This lesson covers the following objectives:
Create an expression to perform a math operation
Interpret a math expression
27
5
Use Expressions
Using Expressions
Expressions are a combination of values that, when
arranged correctly, result in a final value.
Expressions are typically used in Alice 3 to solve timing
and distance problems in your programs.
Example: 2 + 2 = 4
Two values (2, 2) and the operator (+) result in the final
value (4).
27
6
Use Expressions
Expressions in Alice 3
Expressions are created in Alice 3 using the following
built-in math operators:
Add (+)
Subtract (-)
Multiply (*)
Divide (/)
27
7
Use Expressions
27
8
Use Expressions
27
9
Use Expressions
28
0
Use Expressions
Distance Problem
The problem: A person object moves to the center of the
boulder, rather than near it.
This is because the getDistanceTo function calculates
the distance from the center of the person object to the
center of the target object (boulder).
We need to reduce the distance the person object
moves so it does not collide with the boulder.
A math calculation is used to reduce the distance the
person object moves.
28
1
Use Expressions
28
2
Use Expressions
3. From the cascading menu, select the target object to which the
object should move.
28
3
Use Expressions
Use Expressions
Expression Example
This expression reduces the distance that the person
travels so the person does not collide with the boulder.
This was tested and debugged several times until the
correct expression was achieved.
28
5
Use Expressions
28
6
Use Expressions
28
7
Use Expressions
28
8
Use Expressions
Interpret an Expression
To understand a programming statement that includes an
expression, you often need to interpret the expression. To
interpret an expression you can:
Read it from left to right.
Recognize the instances specified in the expression and
describe what each one does.
28
9
Use Expressions
Expression Example
Examine the visual associated with this expression. The
adult and baby penguin instances are moving towards the
cave. Will they go inside?
29
0
Use Expressions
Interpretation of an Expression
This expression tells us the following:
The adult penguin moves forward towards the cave.
The distance between the adult penguin and cave is
determined by the getDistanceTo function.
The distance traveled is reduced by half the width of the
cave.
The width of the cave is determined by the getWidth
function.
29
1
Use Expressions
Use Expressions
29
3
Use Expressions
Summary
In this lesson, you should have learned how to:
Create an expression to perform a math operation
Interpret a math expression
29
4
29
5
Use Variables
Objectives
This lesson covers the following objectives:
Understand variables and how they are used in
programming
29
6
Use Variables
Variables
At times, programmers need to store information, and
then use that information in animations or in games. For
example:
The number of times a procedure should be executed.
An object's properties, such as size and color.
A variable is a place in memory where data of a specific type
can be stored for later retrieval and use by your program. Each
variable is given a unique name to make it easy to find and
reference. Once a variable is declared it can be used to store
and retrieve data.
29
7
Use Variables
Variables Example
Below are the variables and their values for a wolf
instance.
Grey color
29
8
1.0 opacity
Use Variables
Boolean values
(true or false)
TextString
List of objects
29
9
(Hello World!)
Use Variables
Object Properties
Object properties are variables that store information
about the object, such as color, width, height, and depth.
Width Variable
Width
30
0
Use Variables
Boolean
Classes
30
1
Description
Perform arithmetic and set the value of a procedure's arguments.
TextString
Other
Use Variables
Declaring Variables
To declare (or create) a variable is to give a variable a
name and to define the type of data the variable will
contain. Variables are declared in the Code editor. They
are useful because they allow you to:
Assign the same value to multiple procedures, such as a
distance to move.
Simultaneously update the value of all arguments in a
program that reference the variable.
Pass information from one procedure to another.
Simplify programming statements using many functions
and math expressions.
30
2
Use Variables
Initializing Variables
To initialize a variable is to assign it a value. Variables are
initialized in the Code editor at the same time that they are
declared; this is its initial (first assigned) value.
Variable values can be changed as often as you like.
The word initialize means assign a value to.
30
3
Use Variables
Variable Example
A "Spins" variable is declared and initialized to a whole
number with an initial value of 3. This variable is dragged
into the distance argument of each bunny's turn
procedure. Each bunny spins three times. If the initialized
value of "Spins" is changed to 4, all of the procedures will
spin based on the value of the variable, which is now 4.
30
4
Use Variables
4. Note that the preview of the variable, above the thin line, displays
the variable settings.
30
5
Use Variables
30
6
Use Variables
30
7
Use Variables
(continued)
30
8
Use Variables
30
9
Use Variables
31
0
Use Variables
31
1
Use Variables
31
2
Use Variables
31
3
Use Variables
31
4
Use Variables
31
5
Use Variables
Relational Operators
Notice the use of relational operators in the IF statement.
Use Variables
31
7
Relational Operator
Description
<
Less than
>
Greater than
==
Equal to
Not equal to
Use Variables
Summary
In this lesson, you should have learned how to:
Understand variables and how they are used in
programming
31
8
31
9
Objectives
This lesson covers the following objectives:
Use keyboard controls to manipulate an animation
32
0
Event Handling
When an animation is playing, a computer program is
running. Many computer programs request user
interaction. These interactive programs allow a user to
influence the order of actions that occur in the program.
To program this type of interactivity into an animation, you
create event listeners that look for and respond to the
interactivity (the user input events) of the user.
What Is An Event?
An event is any action initiated by the user that is
designed to influence the programs execution during play.
Events may include:
pressing any key on the keyboard
clicking a mouse button
moving a joystick
touching the screen (on touch-enabled devices)
32
2
32
3
Keyboard Controls
Inserting keyboard controls into a program allows the user
to control one or more objects while the animation is
running.
The user can press a key on the keyboard, or click the
mouse, to control the next programming action.
32
4
Keyboard Controls
With keyboard controls, you can:
Create scenes where the user controls an object that
interacts with other objects.
Create animations that execute conditionally, based on a
key press or mouse click.
Create games where the user is required to control an
object to win the game.
32
5
32
6
Event Listeners
Event listeners are procedures in the Scene class that
listen for keyboard input while the animation is running.
Keyboard keys can be programmed to:
Move an object up or down when certain keys are
pressed.
Move an object forward, backward, left, and right using
the arrow keys.
Make an object perform an action, such as speak or
disappear.
32
7
32
8
32
9
33
0
Keyboard Listeners
Keyboard listeners:
Are found in the Add Event Listener drop-down menu.
Listen for, and react to, a keyboard keystroke that you
specify.
33
1
33
2
Data Type
Description
addKeyPressListener()
addArrowKeyPressListener()
addNumberKeyPressListener()
addObjectMoverFor(???)
33
3
33
4
33
5
33
6
33
7
33
9
34
0
34
1
34
2
Summary
In this lesson, you should have learned how to:
Use keyboard controls to manipulate an animation
34
3
Contact Us
Send your queries to Oracle Academy Instructor:
academy-apac-instr_sg@oracle.com
34
4