Sunteți pe pagina 1din 344

Getting Started with Alice

Develop a Complete Animation

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Animations Require Planning


Animations can be complex to plan and develop. You can:
Break the work down into manageable steps to make it
easier to develop your animation.
Employ the process used to solve problems to develop
an animation.
Functional decomposition is the process of taking a complex
problem or process and breaking it down into smaller steps that
are easier to manage.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Functional Decomposition Example


Examine this high-level process:
Consider a math concept that requires many steps.
Identify the high-level steps for the math concept.
Further refine and define the tasks needed for each
high-level step.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Animation Development Process


The process to develop an animation is similar to the problemsolving process. Compare the two processes below.
Problem-Solving Process
Step 1:
Identify the Problem

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

Animation Development Process


Step 1:
Define the Scenario

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Step 2:
Design a
Storyboard

Develop a Complete Animation

Step 1: Define the Scenario


Professional animators begin their process by developing
a scenarioor storythat gives the animation a purpose.
Examples:
Tell a story that presents a problem and a solution.
Teach a concept.
Simulate or demonstrate a process.
Play a game.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Scenario and Animation Examples

Scenario Type

Scenario

Animation

Problem and a solution.

A cat needs help to get


down from a tree.

A firefighter climbs up the


tree to save the cat.

Teach a concept.

Memorizing chemistry
symbols is difficult.

A timed game matches


chemistry symbols with
their definitions.

Simulate or demonstrate a
process.

A car has a flat tire.

A demonstration shows
how to change a tire on a
virtual car.

Play a game.

An airplane must avoid


An interactive game
objects in its path as it flies maneuvers an airplane
through the sky.
around objects in the sky.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Step 2: Design a Storyboard


There are two types of storyboards that are often used to
plan an animation:
Textual: A detailed, ordered list of actions that each
object performs in each scene of the animation.
Visual: A series of illustrated images that represent the
main scenes of the animation.
In computing, a textual storyboard is called an algorithm: a list of
actions to perform a task or solve a problem.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Visual Storyboard Example

Boy and girl sit on a park


bench. The boy walks
away, leaving his phone
behind.

12

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Girl notices the mobile


phone. She thinks, Hey!
That boy forgot his phone!

Girl says out loud Hey! You


forgot your phone! Boy
turns around and walks
back to bench. He says,
Oh! thank you!

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Textual Storyboard Example 1


Program the following actions in order:
Boy and girl sit on a park bench.
Boy stands up and walks away, leaving his phone on the
park bench.
Girl turns to look at the phone.
Girl thinks, Hey! That boy forgot his phone!
Girl says out loud, Hey! You forgot your phone!
Boy stops and turns around.
Boy walks back to the park bench and says, Oh! Thank
you!
14

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Textual Storyboard Example 2


This shows how you can develop your storyboard using
comments in the Code editor of your program. Then, you
can start to develop the animation directly from the
storyboard.

15

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

The place (or world in Alice 3)


where your story occurs.

Park, library, school, home

Objects

Moving or non-moving
characters that you program to
move and act.

Animals, cars, people,


trees

Actions

Instructions for how each object


should act in the scene.

Walk 2 meters, turn left,


say Hello!

User Interactions

Ways in which the user viewing


the animation can manipulate
the objects in the animation.

Keyboard commands or
mouse clicks to make
objects move

Design Specifications

How the objects and scenery


should look in the animation.

Size, position, location,


color

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Storyboard Process Flow


Flowcharting a storyboard helps you organize the flow of
the animation actions and conditions.

True

Boy leaves
phone on
bench

Girl says Hey


you forgot
phone

Girl does
nothing

Boy stops,
turns around,
comes back to
bench, says
Thank you

Boy keeps
walking

End
17

False

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

How Storyboards are Helpful


There are several ways that storyboards aid in program
development:
Textual storyboards can be used to generate program
comment statements and organize program
development.
Storyboards can also help programmers identify
repetitive actions, or actions that may be performed by
more than one object.

18

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Step 3: Program the Animation


After completing the storyboard, the next step is to
program the animation in Alice 3.
As you program the animation, refer to your storyboard
for the animations design specifications.
The code written in Alice 3 provides the instructions for
how the animation should look at run-time.

19

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Animation Checklist
During the animation development process, use this
checklist to ensure that your animation meets all
animation principles.

20

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Create a Complete Animation


To create a complete animation, use all of the
components that you have learned.

21

Complete scene of multiple objects from


multiple classes, including props and
shapes

Vehicle riding with the setVehicle


procedure

Declared procedures

Functions

Movement procedures

IF and WHILE control statements

Object rotation and object sub-part rotation


procedures

Random numbers

Simultaneous movement with the Do


Together control statement

Math expressions

Variables

Keyboard controls

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Step 4: Run the Animation


Run the animation to test that it functions properly and
executes the actions planned in the storyboard. This
process is often referred to as testing and debugging the
software.
Programs are tested by entering unanticipated commands to try
and break the code. When something is broken or doesn't
work as you intended in a software program, it is often referred
to as a bug. Debugging is the process of finding software bugs
in a software program.

22

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Test Elements of Your Animation


Test these elements of your animation:
Math calculations operate as expected.
Objects move with smooth timing.
Comments are added to each sequence of instructions.
Control statements are operating as expected.
Event listeners operate as expected.

24

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Present Your Animation Project


Its time to present your complete animation project. Here
are some steps to follow when organizing your animation
project presentation:
Make sure your presentation is fully tested and
complete.
Plan to demonstrate how you used each of the concepts
learned in this course.
Find out how much time you will have for your
presentation.
If it is a group presentation, plan who will do which parts
of the presentation.
25

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Prepare a Presentation Outline


Create a presentation outline to plan your complete
animation project presentation.
The following slides show an example presentation
outline.

26

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Presentation Outline: Section 1


Section 1: Introduction
Gain your listeners attention.
Introduce the theme of the animation project.
Preview your animation.
Establish your credibility as a speaker.
Give the audience a reason to listen to the presentation.

27

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Presentation Outline: Section 2


Section 2: Presentation of animation project
Organize the presentation in a logical flow.
Show all capabilities of your animation project.
Demonstrate how each course concept was used in the
animation project.
Time visual aids to support the spoken presentation.
Include helpful transitions between ideas.

28

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Presentation Outline: Section 3


Section 3: Conclusion
Summarize the animation in a memorable way.
Motivate the audience to respond.
Provide closure.

29

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

Practicing Your Presentation


When rehearsing your presentation:
Rehearse aloud.
Time your speech and if it is too long or short, revise it.
Rehearse standing up.
Rehearse in front of someone.
Tape-record or videotape your speech or practice in front
of a mirror if you do not have access to a video camera.
Rehearse using your visual aids and technology

30

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Develop a Complete Animation

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Prepare for this Course

33

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Alice Teaches Programming Theory


Alice is designed to teach solid programming theory
minus the intimidation that typically accompanies the
complex syntax and structural rules associated with most
production languages.
Using Alice, you simply drag-and-drop objects from a
gallery into a virtual world, and then link together
programming statements that animate the objects in a fun
and engaging way.

36

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Three-Dimensional Objects
Alice 3 uses three-dimensional (3D) objects that
programmers can drag-and-drop into a scene to create a
virtual world.

A 3D object is one with


width, depth, and height.

37

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Virtual World Example


Here is an example of a 3D world or virtual world. This
virtual world has setting and actor objects, as well as a
background template.

A virtual world contains


3D objects and simulates
a real or imaginary
physical environment.

39

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Programming Objects in an Animation


You can "program" the objects in the virtual world by
dragging and sequencing tiles that represent logical
programming structures.
These logical structures are programming instructions that
correspond to standard statements in a production
programming language such as Java.

40

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Rendering the Animation


As an animation creator, you will program the animation
instructions in Alice 3, and Alice 3 will render the
animation for you.
Rendering is the process whereby the system converts the
still image frames into a seamless animation. Alice 3 does all
of the work necessary to render the animation based on the
instructions you provide for each object.

42

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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.

Students who have never learned a programming


language enjoy using Alice because the interactive
development environment is fun and engaging.
By learning Alice, you are actually learning how to
program. Alice is also used at many colleges and
universities in introductory programming courses.
43

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Learn More About Alice 3


Visit the Alice 3 website to learn more:
http://www.alice.org/index.php?page=what_is_alice/what_is_alice

44

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Check System Requirements


This course includes practice exercises that you can work
on to reinforce the concepts being taught.
You need to have Flash, the Java Development Kit (JDK),
and Alice 3 installed on your machine.

45

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

One of the following:


Windows XP and up
Apple OS X and up

Browsers

Any modern browser that supports Java:


Internet Explorer 6 and up
Firefox 3 and up
Chrome
Safari
Opera 4.x and up

Memory

1 GB

Free Disk Space

Free disk space:


Required: 1.5 GB
Recommended: 8 GB

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

System Requirements

47

(continued)

System Component

Minimum Requirement

Graphics

Capable of high (16-bit) color and 1024 X 768


resolution
3D video card recommended

Sound Card

Required

Software

Adobe Flash Player (latest)


JDK 7 (see JDK download instructions)
Alice 3 (see Alice 3 download instructions)

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Download the Java Development Kit


1. Open any Internet Browser and type the following URL :
http://www.oracle.com/technetwork/java/javase/downloads

2. From the Java SE Downloads page, click the Download


button for the Java Development Kit (JDK).
3. Review and accept the License Agreement.
4. Locate the JDK for your computers operating system
and click the download link.
5. If prompted, save the file to a location on your hard drive
that you can easily remember, and click OK.

48

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Launch the JDK Executable File


1. Locate and double-click the executable file to launch
the installation.

2. When prompted to run the executable file, click Run.

49

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Run the JDK Wizard


1. From the Installation Wizard, click the Next button.
2. To accept the default settings, click Next.
3. When prompted for installation location, click Next. If
prompted, close the internet browser window.
4. Click Continue to acknowledge the successful
installation.
5. You will be prompted to set-up the Software Developer
Kit (SDK). Click Next.
6. When prompted for the installation location, click Next.
7. When the set-up is complete, click Close.
50

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Download Alice 3


1. Open any Internet Browser and enter the following
URL: http://www.alice.org
2. From the Downloads list, select the Alice 3 link.
3. Locate and select the Alice 3 Offline Installer option for
your computer platform.

4. When prompted, Save the Alice 3 Installer file.

51

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Downloading Alice 3 to a Windows Machine


Vista, Windows 7, and Windows 8 all have a strong
malware protection scheme that may resist installing nonstandard software directly on the hard drive.

To reduce the likelihood of installation problems,


download the Universal ZIP file for Alice 3 (instead of the
Offline Installer file) if you are using one of these operating
systems.

52

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Download the Universal ZIP File


1.
2.
3.
4.

53

Go to the Alice website at: http://www.alice.org.


From the Downloads list, select the Alice 3 link.
Locate and select the Alice 3 Universal Installer option.
Download the zipped file to your desktop.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Launch the Alice Installer Wizard


1. Locate the saved installer file.
2. Double-click the executable file. A progress window
will appear.

3. Once the installer is downloaded, the Alice 3 Installer


Wizard appears. Click Next to begin the installation.
54

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Install Alice 3


1.
2.
3.
4.

From the Installer Wizard, select the Install option.


To accept the default installation option, click Next.
Review the License Agreement.
If you agree, select the box next to I accept the terms
in the license agreement. Click Next to continue.
5. To accept the default setting that installs a desktop
shortcut, click Next.
6. To begin the installation, click Install. A progress
window will display during the Alice 3 installation.
7. To complete the installation, click Finish.

55

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Launch Alice 3


1. After Alice 3 is installed, the Alice 3 icon will appear on
your desktop.

2. Double-click the icon to launch Alice 3.

56

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Steps to Install Alice 3 Using the Universal ZIP


File
1. Unzip the file on the desktop.
2. Move the unzipped folder (containing all of Alice 3) to
the Program Files (X86) folder on the C:\ drive.
3. Create a shortcut on the desktop to Alice3.bat.
4. Click the shortcut to launch Alice.

57

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

Alice 3 Download and Support Links


Join the forum to get help from other users:
http://alice.org/community/
Alice FAQs:
http://alice.org/index.php?page=faq
Contact the Alice team:
http://alice.org/index.php?page=contact/contact

58

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Prepare for this Course

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Get Started with Alice 3

60

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Initial Scene Components


Below are components of an ocean floor scene.
Coral are
scenery objects.

Fish are acting


objects.

63

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Ocean floor is a
template.

Get Started with Alice 3

Steps to Create a New Project


1. Launch Alice 3.
2. In the Welcome dialog box, select the Templates tab.
3. Select a template, and click OK.

64

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Steps to Save a Project


1. In the File menu, select Save As.
2. Select the location to save the project (e.g., computer, file server,
memory stick).
3. Enter the project name.
4. Click Save.
5. Save projects frequently to avoid losing your work.

65

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Navigating Between Editors


Alice provides two different workspace editors, called
perspectives, to build a project; you will toggle between
them frequently throughout the development of your
project. The two editors are:
Code Editor (Edit Code perspective, shown on the left)
Scene Editor (Setup Scene perspective, on the right)

66

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Navigating Between Editors


Switch between the two editors by using either the Edit
Code button or Setup Scene button.
You are in the Code editor when you see programming
instructions in the left window pane.
You are in the Scene editor when you see the gallery of
objects.

67

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

The Default Editor


By default, Alice starts in the Code editor.
Click the Setup Scene button to switch to the Scene editor.

68

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Add an Object to a Scene Display


In programming terms, a class is a blueprint used to build
an object, and an object is an instance of a class.
In the Scene editor add an object (instance of a class) to a
scene in one of two ways:
Drag an object (instance) from the gallery into the scene
with your mouse.
Click the object, complete the dialog box, and let Alice
add the object to the center of the scene.
After an object is added to a scene, it is referred to as an
instance of the object. You can add many instances of the same
object to a scene (multiple coral objects in the water, for
example). Each instance must have a unique name.
69

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Add an Object to a Scene Display


Click the object once, or drag the object from the gallery
into the scene with your mouse.

70

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Naming the Object


Review the name that Alice 3 provided for the object. You
can modify the name, or click OK to accept the name and
add the instance to the scene.

71

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Scene Editor Display


The Scene editor contains two panels:
Scene Setup (top panel)
Gallery (bottom)

73

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Gallery Tabs
The gallery has five tabs:

75

Tab

Function

Browse Gallery by Class Hierarchy

Organizes objects by mobility.

Browse Gallery by Theme

Organizes objects by region and folklore


context.

Browse Gallery by Group

Organizes objects by categories.

Search Gallery

Allows an object search by name.

Shapes/Text

Organizes object shapes, 3D text, and


the billboard.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Save New Project Version


Save time by creating multiple versions of your project.
After objects are positioned in the initial scene, save
multiple versions of your project, giving each version a
different name.
Benefits of saving multiple versions of projects:
Use the same scene to create different animations.
Save time re-creating the scene if you encounter
programming errors.

78

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Steps to Save a Project Version


1. Select File.
2. Select Save As...
3. Select the location to save the project (e.g., computer, file server,
memory stick).
4. Enter the project name.
5. Click Save.

6. Save projects frequently in case of a power failure or a computer


crash.

79

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Instance Menu in Methods Panel


The instance menu displays above the Procedures
tab. The down pointing triangle on the right side of the
menu indicates that the menu drops down when selected.

82

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Create a Programming Instruction


From the Methods Panel, click and drag the desired
programming instruction into the myFirstMethod tab of the
Code editor.

83

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Select Values for Method Arguments


After you drag the programming instruction into the
myFirstMethod tab, use the cascading menus to select the
value for each argument used in the method.
An argument is a value that is used by the method to perform
an action.

84

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Procedure Argument Types


Argument types may include:
Direction
Amount
Duration
Text
Alice 3 recognizes how many arguments are needed for
each programming instruction. It presents you with the
correct number of cascading menus to specify the values
for each of those arguments.

85

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Copy Programming Instructions


To copy a programming instruction, you may use any one
of these methods:
The CTRL + Drag method.
Right-click and use the Copy to Clipboard option.
Click and drag the programming instruction to the
clipboard.

86

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Steps to Use the CTRL + Drag Method


1. Hold down the CTRL key on your keyboard.

2. Click on and hold the programming instruction handle.

3. Drag the handle to the desired location in the code, or to the


clipboard. Release the mouse button before releasing the CTRL
key.

87

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Steps to Use the Right-Click Copy Method


1. Right-click on the programming instruction handle.
2. Select the Copy to Clipboard option.

88

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Steps to Use the Click + Drag To Clipboard


Method
1. Click and drag a copy of the programming instruction to the
clipboard icon. The clipboard changes to a yellow color when the
mouse pointer makes contact with the clipboard icon. Use this
method when copying programming instructions between tabs.

89

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Undo an Action
Undo an action using the Undo option on the Edit menu,
or the keyboard shortcut CTRL + Z.

90

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Test and Debug Your Animation


Testing
Once you create the programming instructions for your
animation, you need to test your program.
To test your program, click the Run button.
Run the animation to test that it functions properly and
executes as planned and without error.
Test the animation frequently during development.

91

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Test and Debug Your Animation


Testing
Testing the limits of your program is also an important part
of the process. One example of this is changing the value
of an argument in a method in an effort to intentionally
break the code in order to prove that it works under
extreme conditions .
What happens if a number is very large? or negative?
Test the limits of the animation frequently during
development.

92

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Test and Debug Your Animation


Debugging
The cycle of testing your program, identifying errors or
unintended results, rewriting the code, and re-testing is a
process referred to as debugging your program.

Software programs, such as animations, are tested by entering


unanticipated commands to try and "break" the code. When
something is broken or doesn't work as intended in a software
program, it is often referred to as a "bug". Debugging is the
process of finding bugs in a software program.

93

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

Testing and Debugging Techniques


Use some of the following techniques as you program the
animation in Alice 3:
Adjust the arguments that specify the direction, distance,
and duration that objects move.
Adjust the mathematical expressions that manipulate the
direction, distance, and duration that objects move.
Refine or replace instructions in the code that do not
work as intended.
Resolve errors created by the programmer.

94

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Get Started with Alice 3

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Add and Position Objects

96

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Open an Existing Project


Saved Alice 3 project files can be opened and edited.
There are two ways to open an existing Alice 3 project file
after launching Alice:
Select the project from the My Projects tab.
Browse for the project using the File System tab.

99

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Open an Existing Project Using the


My Projects Tab
1. Open Alice 3.
2. From the Select Project dialog box, select the My Projects tab.

3. Scroll to the name or thumbnail of the project to open.


4. Select the name or thumbnail of the project and click OK.

10
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Open an Existing Project Using the


File System Tab
1. Open Alice 3.
2. From the Select Project dialog box, select the File System tab.

3. Select the Browse button.


4. Use the navigation window to navigate to the directory structure
on your computer where the Alice 3 file is located. Note: Alice 3
cannot open animations created with the Alice 2 software.

5. Click OK after the Alice 3 file has been selected.

10
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Positioning Objects Within Initial Scene


Positioning objects within your initial scene includes
choosing the:
Direction the object should face.
Orientation of objects relative to other objects in the
scene.
Position of objects in the scene.
Position of the object's sub-parts (arms, legs, etc.).

10
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Positioning Features of Objects


All Alice 3 objects share the same positioning features:
3D coordinates on x, y, and z axes.
a center point, where its own axes intersect (usually at
the center of mass).
sub-parts that can move.

10
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Ways to Position an Object


Precise / Imprecise Positioning
There are two ways to position an object:
Precise positioning using one of two methods:
Use a one-shot procedure.
Enter values for the x, y, and z coordinates and press the
Enter key.

Imprecise positioning using the drag-and-drop method


with the cursor.

10
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Select Instance to Position


Precise / Imprecise Positioning
There are two ways to select the instance that you want to
position. Rings or arrows will surround the object once it is
selected.
Click the name of the instance from the object list in the
upper left corner of the scene window.
- OR Click the instance in the scene window.

10
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Positioning Objects in the Scene


Precise / Imprecise Positioning
After adding multiple objects to the center of a scene, use
one-shot procedures to precisely place them in different
locations in the scene so that all objects are visible.

10
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Open the One-Shot Procedures Menu


Precise / Imprecise Positioning
1. Right-click on an object in the Scene editor.
2. Select procedures.

OR
1. Select the one shots procedure menu in the Properties panel.
2. Select procedures.

10
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Use One-Shot Procedures


Precise / Imprecise Positioning
1. From the one-shots procedures menu, select the desired
procedure.

2. Specify the argument values (direction and distance).


3. The object will automatically re-position based on the procedure
selected and the arguments specified.

11
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Position an Object Using Coordinates


Precise / Imprecise Positioning
1. In the Properties panel, locate the Position property.
2. Enter a value in the x axes and press enter.

3. Enter a value in the y axes and press enter.


4. Enter a value in the z axes and press enter.
The object will automatically re-position to the coordinates entered in
the x, y, and z axes fields. You must press the enter key after entering
each value.

11
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Use the Drag and Drop Method


Precise / Imprecise Positioning
1. Select the object, or the sub-part of the object, using the cursor.
2. Select a handle style. Each handle style presents rings or arrows
to assist you with your positioning. For example, the Translation
handle style will present three arrows to use in positioning the
object along the x, y, and z axes.
3. Position the object with your cursor by selecting and dragging the
rings that surround the object.

11
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Types of Handle Styles


Precise / Imprecise Positioning
Handle Style

Description

Default

Simple rotation and movement.

Rotation

Rotate about the x, y, and z axes.

Translation

Move along the x, y, and z axes.


Change the size of the object and stretch it along the x, y,
and z axes.

Resize

11
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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.

Add and Position Objects

Selected Object Properties Menu


The Selected Object Properties menu in the Scene editor
provides you with the ability to change the properties of
the instance that is currently selected in the scene.

11
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Change an Instances Properties in the


Scene Editor
1. Select the instance in the Scene editor.
2. Change properties such as its paint (color), opacity, or size using
the menus in the properties panel.
The triangle in front of the Selected Object Properties button can hide
or display the properties of an instance. If the property fields for an
instance are not displaying, click the triangle to display them.

11
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Positioning an Objects Sub-Parts


Use handle styles to position an objects sub-parts during
scene setup.
For example, if you want an objects head looking to the
left when the animation begins, complete these steps

11
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Steps to Position Object Sub-Parts


1. Select the instance from the object properties menu.
2. The right-pointing triangle next to the instance name indicates that
there are additional cascading menus for the instances sub-parts.
Select the sub-part that you want to position.
3. Use the rings around the sub-part to position it.
Repeat these steps to position additional sub-parts.
Use the Undo feature when necessary.

12
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add and Position Objects

Summary

(continued)

In this lesson, you should have learned how to:


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

12
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Procedures and Arguments

12
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Objectives

(continued)

This lesson covers the following objectives:


Demonstrate how procedure values can be altered
Create programming comments
Reorder, edit, delete, copy, and disable programming
statements
Test and debug an animation

12
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Display the Code Editor


Click Edit Code to display the Code editor. The Code
editor is where you program your animation.

12
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Code Editor Tabs


The Class Menu displays to the left of the Scene tab. You
create your programming instructions on the
myFirstMethod tab.
By default, Alice creates a Do In Order control statement
in the myFirstMethod procedure. The area labeled drop
statement here is the location onto which you will place
programming instructions.

13
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Control Structures
At the bottom of the myFirstMethod tab you will find the
Alice control structures.

13
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Create a Programming Instruction


From the Procedures tab, click and drag the desired
procedure into myFirstMethod in the Code editor.

13
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Select and Set Argument Values


After the programming statement is created, use the dropdown menus to set the values for each argument. To
access the argument drop-down menu, click on the downpointing triangle to the right of the argument value.

13
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Execute the Program


Click the Run button to execute the programming
instructions. Run the program frequently to test for the
desired results, and alter the values of the arguments as
necessary.

13
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Examples of Movement Procedures

13
7

Procedure

Description

Move

Moves the object in any one of its six directions.

Move Toward

Moves the object toward another object.

Move Away From

Moves the object away from another object.

Move To

Moves the object from its current position to the center point
of the target object.

Move and Orient To

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

Halts an objects movement for a certain number of


seconds. Delay can be used to slow down the execution of
an animation.

Say

Creates a call-out bubble with text that makes the object


appear to talk.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Examples of Rotation Procedures

13
8

Procedure

Description

Turn

Rotates an object left, right, forward, or backward on its


center point. Left and right turn on the objects vertical axis;
forward and backward turn on the objects horizontal axis.

Roll

Rolls an object left or right on its center point using the


objects horizontal axis.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Steps to Edit Arguments


1. Next to the arguments value, click the arrow to display the menu
of values.

2. Select a new value.


3. Use the Custom DecimalNumber option to specify a value that
differs from the default list of values.

14
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Steps to Reorder Programming Statements


1. Use Drag and Drop: Select the handle of the programming
statement.
2. Drag the programming statement to its new position.
3. Drop the programming statement into its new position by deselecting the handle.*

*Note: A green position indicator line will appear to help you align the
programming statement in the desired position.
14
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Edit Programming Statements


Use the drop-down lists to edit the values of a
programming statement.

14
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Delete Programming Statements


Right-click programming statements to delete them.

14
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Edit and Test the Program


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

14
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Debugging and Testing


Debugging and Testing is the process of running the
animation many times, and adjusting the control
statements, procedures, and arguments after each
execution.
Save often while debugging your program.

14
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Insert Temporary Programming Statements to


Help with Debugging
You can insert temporary programming statements into
your code to help with debugging. For example: imagine
that you have an object that is not moving forward.
Temporarily enter a Say programming statement to
announce that the object is about to move forward.
Test the program to see whether or not the Say
programming statement executes.
If the Say statement executes, but the object does not
move, this indicates one type of problem; if both the Say
and Move statements do not execute, this may indicate
another type of problem.
14
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Disabling Programming Statements


Programming statements can be disabled in the Code
editor.
Disable programming statements to:
Help isolate portions of code during testing.
Help you focus on programming, testing, and debugging
a specific instruction.

14
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Steps to Disable a Programming Statement


1. Right-click on the programming statement.
2. Unselect "Is Enabled" from the drop-down list.

3. The color of the programming statement will change to gray


hashmarks to show that it is disabled.

15
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Steps to Re-Enable a Disabled Programming


Statement
1. Right-click on the programming statement that has been disabled.
2. Select "Is Enabled" from the drop-down list.

15
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Steps to Enter Comments in a Program


1. Drag and drop the comments tile above a code segment. The
comment tile is located at the bottom of the myFirstMethod.
2. Type comments that describe the sequence of actions in the code
segment.

15
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Using Comments to Organize Your Program


Comments can be an excellent tool for organizing the
development of a program.
For large programs, create a comment that indicates
the end of the program. An end of program comment
helps to minimize scrolling when adding programming
statements to a lengthy myFirstMethod.

15
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Procedures and Arguments

Summary

(continued)

In this lesson, you should have learned how to:


Demonstrate how procedure values can be altered
Create programming comments
Reorder, edit, delete, copy, and disable programming
statements
Test and debug an animation

15
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Add Rotation and Randomization

15
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Program Development Using a Top-Down


Approach
Just as a homebuilder uses a set of blueprints and follows
a series of steps, a programmer uses a plan and follows a
series of steps to build a program.
Homebuilders work with a purpose and set specific goals
as they buildthe room is energy efficient, the bathroom is
accessible, the home meets building codes, etc.
Programmers also work with purpose and set goals
because without them, success cannot be measured.
Another term for the goal or purpose of an animation is a
high-level scenarioit is a story with a purpose.
15
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Steps to Use a Top-Down Approach to


Programming
1. Define the high-level scenario (the purpose/goal of the program).
2. Document the actions step-by-step in a textual storyboard. This
helps to gain a thorough understanding of the actions that need to
be programmed.
3. Create a table to align the storyboard steps to the programming
instructions.
4. Review the table during the animations development to ensure
the animation meets specifications.
5. Revise the table as necessary.

16
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Textual Storyboard Example


Program the following actions in order:
Chicken walks by.
Cat turns to look at the chicken.
Cat says, Dinner time!
Chicken says, Oh no!
Chicken turns to right.
Program the following actions together:
Chicken walks away quickly.
Cat walks away quickly.

16
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Align Storyboard to Programming Instructions


Order of
Instructions

Storyboard Action

Programming Instructions

Chicken walks by.

Chicken moves forward 2 meters.

Cat looks at the chicken.

Cat turns to face chicken.

Cat says, Dinner time!

Cat says Dinner time!

Chicken says, Oh no!

Chicken says, Oh no!

Chicken and cat turn right.

Chicken turns right 0.5 meters.


Cat turns right 0.125 meters.

Cat chases chicken.

Chicken moves forward 2 meters.


Cat moves forward 2 meters.

Do in order

Do together

16
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Examples of Rotation Procedures

16
4

Procedure

Description

Turn

Rotates an object left, right, forward, or backward on its


center point. Left and right turn on the objects vertical axis;
forward and backward turn on the objects horizontal axis.

Roll

Rolls an object left or right on its center point using the


objects horizontal axis.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Comparison of Turn and Roll Procedures


The object turning left and right on its
center point using a vertical axis.

The object rolling left and right on its


center point using a horizontal axis.

The object turning forward on its


center point using a horizontal axis.

(The hare was already facing left.


Turning forward caused it to lean forward)

16
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Sub-Part Rotation Example


Some objects have moveable sub-parts that can turn and roll. The pocket
watch has moveable hour and minute hands that can roll on the clocks center
point. The key to successful rotation is knowing the center point of an object.

16
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Steps to Program an Object to Rotate


1. Select the instance of the object to rotate.

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

3. Set the direction argument.


4. Set the amount argument (1.0 = one full turn or roll)
*Note: A green position indicator line will appear to help you align the
programming statement in the desired position.
16
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Execute the statements contained within the control


statement in sequential order.

Do together

Execute the statements contained within the control


statement simultaneously.

Count

Execute the statements contained within the control


statement a specific number of times.

While

Execute the statements contained within the control


statement while a specified condition is true.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Control Statements in the Code Editor


Control tile statements are located at the bottom of the
Code editor panel. They represent blocks of code into
which individual statements are grouped. Drag control
tiles into the Code editor, and then add statements to
them.

16
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Add Procedures to a Control Statement


Drag new or existing programming statements into the
Control tile statement. In the example illustrated below,
the carp will simultaneously move forward, turn left, and
roll to the right.

17
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Tip: Create Programming Blocks


Even though myFirstMethod contains a default Do in
order control statement, you can always add other Do in
order tiles to the programming area. This allows you to
keep your programming instructions together in organized
blocks.
Blocks can be easily copied to the clipboard or moved
around in a large program. Nested Do in order control
statements do not impact the performance of the
animation; they make program-editing easier for the
programmer.
17
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Nested* Do In Order Control Statements


Nested statements add visual structure to a program,
much like an outline brings structure to a report.
*Nesting is the process of
putting one thing inside of
another, like eggs lying next
to each other in a nest.

Here, two Do in order


statements are nested
inside a third Do in order
statement.
17
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Steps to Program an Objects Sub-Part to


Rotate
1. Select the instance of the object sub-part to rotate.
2. Drag a turn or roll procedure to the Code editor.

3. Select the direction value for the direction argument.


4. Select a rotation value for the amount argument
(1.0 = one full turn or roll).
17
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Examples of Random Numbers


Random numbers can be generated within a wide range
of numbers, both positive and negative, and may include
whole numbers and fractional parts of a number.
Examples of random numbers:
15674
-6934022
0.371
-89.763

17
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Random Numbers in Animations


Animals do not move in straight geometric lines. They
change direction slightly as they walk, swim, and fly.
Random numbers may be utilized in the distance
argument of a method so that the object moves in a less
predictable, more life-like manner. Random numbers are
often used when creating games that require
unpredictable behavior.

17
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Steps to Use Random Numbers


1. For any numerical argument, one of the options is a random
number. Select the argument from the drop-down list.
2. Select Random.
3. Select nextRandomRealNumberInRange.
4. Select the low and high values.

5. Run the animation. Alice 3 will randomly generate a value within


the selected range when the statement is executed.

17
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

Random Number Animation Example


The fish moves a random distance up and down at
runtime.

17
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Add Rotation and Randomization

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Declare Procedures

18
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Create Inherited Methods


In addition to the pre-defined methods, you can create
your own methods and have them display, or be
available for, any subclass object.
Inherited methods will always display at the top of the list
of pre-defined methods once they are created.

18
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

myFirstMethod Tab
The myFirstMethod tab is displayed by default when the
Code editor is opened.

18
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

View the Class Methods


Select a superclass or subclass to view the procedures,
functions, and properties defined for the selected class.

18
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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.

Identify a repetitive behavior and create one method for it:


Simplifies the code, making it easier to read.
Allows many objects of a class to use the same method.
Allows subclasses of a superclass to use the method.

19
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Procedural Abstraction Defined


An example of procedural abstraction is the removal of a
repetitive or lengthy programming statement from
myFirstMethod and the placing of it into its own method to
make the code easier to read, understand, and reuse by
multiple objects and multiple classes.
Procedural abstraction is the process of looking at programming
code, identifying repetitive programming statements, and
extracting them into their own methods, thus making the code
easier to understand and reuse.

19
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Procedural Abstraction Example 1


One or more objects may perform the same repetitive
motions. The animating of one swimming fish requires the
writing of many repetitive procedures which must then be
repeated for each fish in the school, taking up a lot of
space in myFirstMethod.

19
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Procedural Abstraction Example 2


Sometimes, a procedure needed to perform an action is
not available by default. For example, a bird needs to fly,
but a fly procedure is not available for bird objects.

19
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

When Procedural Abstraction Occurs


Procedural abstraction can occur before or after
programming statements are created.
However, by developing the storyboard first, the
programmer can more easily identify the procedures that
will be needed before the programming begins.

19
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Examples of When to Declare a Procedure


Declare a procedure when:
Motions do not have a default procedure, such as a bird
flying.
Motions need to be used by multiple objects or classes,
such as all quadrupeds hopping up and down.
Singular motions require many programming
statements, such as a person moving body parts to
walk.

19
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Declaring a Procedure Example 1


The bird flies by, turning its shoulders and moving forward
simultaneously. This repetitive motion can be extracted
into its own flying procedure.
Do together:

Bird turns right shoulder backward

Bird flies

Bird turns left shoulder backward

Bird moves forward

Bird moves forward


Do together:
Bird turns right shoulder forward
Bird turns left shoulder forward
Bird moves forward

19
6

Do together:

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Declaring a Procedure Example 2


Each bunny moves up and down in order to simulate a
hopping motion. This repetitive motion used by all bunny
objects could be extracted into its own hop procedure.

19
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Steps to Declare a Procedure


1. From the class hierarchy, select the class that should inherit the
procedure. All subclasses will then inherit the procedure as well.
(These are indented underneath their superclass.)
2. Click the Add Procedure... button.

3. Specify a name for the procedure and then click OK.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Steps to Add Procedure to myFirstMethod Tab


Before Programming
1. Click the myFirstMethod tab.
2. Select the instance for which you are coding the procedure from
the instance menu.
3. In the Procedures tab, locate the declared procedure and drag it
into myFirstMethod.

4. Go back to the procedure by clicking the tab at the top of the


Code editor with the procedures name.

19
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Steps to Add a Declared Procedure to Your


Code
1. Select the instance of the object to which you wish to add the
declared procedure.

2. Find the declared procedure listed under the Procedures tab in


the methods panel. The declared procedures are available in the
procedures tab for all objects that inherit them.
3. Drag the declared procedure to the code.

20
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Steps to Access and Edit Declared Procedures


1. In the instance menu, select the instance where the procedure
was declared.
2. Click Edit to the left of the procedure name.

3. Create or edit the programming instructions for the procedure.


4. Click the Run button to test the procedure and debug as
necessary.
5. When finished editing the procedure, click the myFirstMethod tab
to return.
20
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Identify Opportunities for Declared Procedures


As you program, continually identify opportunities to
declare procedures using procedural abstraction
techniques. For example, in myFirstMethod, the fish bobs
up and down repeatedly. A separate bob procedure
should be declared as a result.

20
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Procedural Abstraction and Using the


Clipboard
After you have written many programming instructions in
the myFirstMethod tab, you may determine that the code
would serve your program better if it were in a declared
procedure.
To save time, you can drag the programming instructions
onto the clipboard icon. Then, after creating the declared
procedure, you can drag the programming instructions
from the clipboard into the declared procedure.

20
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Use Inherited Procedures


Procedures declared at the
superclass level are
available to the other
objects in that class.
For example, a "yetiWave"
procedure created to make
a baby Yeti wave his arms
in the air could be used to
make an adult Yeti's arms
wave in the air.
20
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Declare Procedure at Superclass Level


Declare the "yetiWave" procedure at the biped
superclass level so that the baby Yeti and the adult Yeti
can both use the procedure.

20
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

this Object Identifier


When a declared procedure is created, the object
identifier, this, is used to indicate that the instance calling
the procedure is this.

20
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

this Object Identifier Example


If the baby yeti is selected in the instance menu, then
the YetiWave procedure is added to myFirstMethod; this in
the declared procedure refers to the baby yeti.
If the adult yeti is selected in the instance menu, and the
YetiWave procedure is added to myFirstMethod, this in the
declared procedure now refers to the adult yeti.
In essence, this always refers to the instance of the class
that is calling the procedure.
20
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Declare Procedures

Summary

(continued)

In this lesson, you should have learned how to:


Describe when to implement procedural abstraction
Demonstrate how to declare a procedure
Identify and use procedural abstraction techniques to
simplify animation development

20
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Control Statements

21
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Arguments Display
Below are examples of arguments in a procedure.

21
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Steps to Edit Arguments


1. Next to the arguments value, click the arrow to display the menu
of values.
2. Select a new value. The menu indicates the current value,
followed by pre-set values to choose from, followed by additional
menu options to specify randomization, math calculations, or a
custom decimal number.

21
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Selecting a Placeholder Argument


When adding a procedure to the code, you are required to
select a value for each argument in the procedure.
Often times you may choose a pre-set value as a
placeholder (a temporary value) which is later changed
during an edit cycle.
Using a placeholder value is a common approach to
creating and refining animation performance.

21
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Simultaneous Movements
To create simultaneous movements for an object, use the
Do together control statement.
Control Statement
Do In Order

Do Together

21
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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.

Use Control Statements

Simultaneous Movements Example 1


For example, a movement executed together could be as
simple as simultaneously raising both arms of a biped
object from a hanging position to a straight arm overhead
position.

21
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Simultaneous Movements Example 2


Another example is a walking motion, which requires
simultaneous movement of the hips and shoulders.
To create the walking motion for a biped, use:
A series of move, roll, and turn procedures.
Do Together control statements.
Different programming may be required for different
objects because no two objects walk the same way.

21
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Walking Textual Storyboard Example


Order of Instructions

Programming Instructions
Left hip turns forward
Whole body moves forward
Left hip turns backward

Do Together

Right hip turns forward


Left shoulder turns left
Right shoulder turns right
Whole body moves forward
Left hip turns forward

Do Together

Right hip turns backward

Left shoulder turns right


Right shoulder turns left
21
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Walking Motion Example


Examine this code for a simple walking motion.

22
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

When Procedures Offset Each Other


A common mistake is to include two procedures that will
offset and cancel each other in a Do Together construct.
For example, if you include a move up 1 meter procedure,
followed by a move down 1 meter procedure in a Do
Together, nothing will happen. The procedures cancel
each other out.

22
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

setVehicle Procedure Example 1


The child is positioned on the camel in the Scene editor.
Then, the camel is set as the vehicle of the child in the
Code editor. When the camel moves, the child stays on
top and moves with the camel.

22
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

setVehicle Procedure Example 2


The helicopter is set as the vehicle of the camera in the
Code editor. When the helicopter moves, the camera films
the scene from the helicopter's perspective.

22
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Steps to Use setVehicle Procedure


1. Determine the vehicle object and the rider object.
2. In the Code editor, select the rider object from the Instance menu.
3. From the Procedures tab, drag the setVehicle procedure into the
Code editor.
4. In the procedure, select the vehicle object from the menu.

22
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

Steps to Stop setVehicle Procedure


1. If you want the rider object to get off the vehicle object, drag
another setVehicle procedure into the Code editor at the point the
rider should get off the vehicle.
2. Set the vehicle to this, which sets the vehicle of the rider back to
the scene.

22
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Control Statements

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Functions

22
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Objectives
This lesson covers the following objectives:
Use functions to control movement based on a return
value

22
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Functions Precisely Answer Questions


Functions provide precise answers to questions, such as:
What is the distance between the helicopter and the
ground?
What is the height of the cat?
What is the width of the owl?
A boolean function returns either a true or false value. For
example, if the isFacing function is called to determine if
the person object is facing the tree object, a true or false
value will be returned.
23
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Functions Solve Distance Problems


Suppose we want to move the lioness directly to the rock
without having to manually determine, through trial and
error, the distance between the lion and the rock.
We could guess the distance by specifying a placeholder
value and testing the movement until we get close to the
desired end result, but a more efficient way is to use a
function to determine the exact distance to move.

23
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Use getDistanceTo Function


Use the getDistanceTo function in the move procedure to
solve this distance problem.

23
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Steps to Use the getDistanceTo Function


1. Determine the moving object and target object.
2. In the Code editor, select the moving object from the Instance
menu.
3. Drag the move procedure into the Code editor.

4. Select the direction and a placeholder argument for distance


(the distance argument will be modified in the next step).

5. From the Functions tab, drag the getDistanceTo tile onto the
highlighted distance value.
6. Select the target object.

23
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Test the Function


Click the Run button to test the programming statement.
In the example below, the lioness moves to the center of
the rock at runtime. This could be read out loud as
"determine the distance from the center of the lioness to
the center of the boulder and then move the lioness
forward that amount."

23
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Test the Function


The lioness moves to the middle of the rock. This is
because the getDistanceTo function calculates the
distance between the centers of both objects.
The function calculated the distance from the center of the
lioness to the center of the rock, and moved the object
using that value.

23
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Using Math Operators


A function determines the distance between the lioness
and the rock. To reduce the value returned by the
getDistance function, the subtraction operator subtracts a
specified value. The specified value is determined by
calling the getWidth function and dividing that value in
half.
Lioness

Rock
X = Get distance from lioness to rock
Y = Get width of rock

Z = X (Y / 2)
23
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Examine the Math Calculation


Let's examine the math calculation Z = X - (Y / 2):
Z represents the total distance the lioness will move.
X represents the distance between the lioness and rock.
Y represents the width of the rock.
Y / 2 represents the width of the rock divided by 2.
( ) represent the order of precedence.
Lioness

Rock
X = Get distance from lioness to rock
Y = Get width of rock

24
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Math Operator Tip


Why did we divide the width of the rock in our calculation?
Because we want the animation to appear as though the
lioness is moving to the very edge of the rock. If we used
the entire width of the rock, the lioness would stop further
from the rock than desired.

Lioness

Rock
X = Get distance from lioness to rock
Y = Get width of rock

24
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Steps to Use Math Operator to Avoid Collision


1. Click the outer arrow next to the function argument.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Understanding the Math Menus Example 1


The following image displays the math operators (+ - * / )
requiring one or two arguments. Each option will provide
one or two cascading menus to specify the argument
values.

24
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Understanding the Math Menus Example 2


The following image displays an (+) addition operator
requiring a single argument.
The following image displays math operators requiring two
arguments.

Remember, you can select placeholder values for the


arguments. Placeholder values can always be edited.
24
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Remove Objects Depth from Function


Another precise way to avoid collisions is to remove the
depth (length) of the moving object from the function. In
the example below, the lioness will move the distance to
the rock, minus the depth of the lioness.

Lion

Rock
Distance from lioness to rock

Lioness depth

24
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Depth is Measured from Objects Center


When a distance value is calculated, it is measured from
one object's center to another object's center. The same is
true for math calculations. When the depth of the lioness
is subtracted from the rock, it is actually subtracted from
the center of the rock.

Lioness

Rock
Distance from lioness to rock

Lioness depth

24
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Steps to Remove Depth from Function


1. In the Functions tab, drag the moving objects getDepth function
onto the highlighted distance value.

2. Run the animation to test how the object moves at runtime. Adjust
with additional math calculations if necessary.

24
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Functions

Summary
In this lesson, you should have learned how to:
Use functions to control movement based on a return
value

24
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use the IF and WHILE Control Structures

24
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Control Structures Available in Alice 3


Available pre-defined control structures include:
Do in order
Count
While
For each in
While
Do together
Each in together

25
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Control Structures Display


You can drag a control structure to myFirstMethod before
or after creating the programming instructions that will be
included in the control structure.

25
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Control Structures Example


For example, if you create a move and turn instruction for
an object, and later decide that the actions should execute
simultaneously, you can insert a Do together control
structure and reposition the move and turn instructions
within the control structure.
Or, you can anticipate that you are going to need a Do
together control structure, insert the control structure, and
then create and position the programming instructions
within the control structure.

25
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Nesting Control Structures


Control structures may be nested, meaning that one
structure is contained within another.
For example, if a person is going to wave his left hand
and then his right hand while he is moving forward, nested
control structures would be necessary.

25
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Nesting Control Structures Code Example


Examine the programming instructions below.

25
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Conditional Execution Using Control


Structures
Conditional control structures allow you to control
execution based on a condition, or a decision being made.
Consider these examples:
If the current color of an object is blue, change the color
to orange.
If the width to the rock is less than 1 meter, move
forward 1/2 meter.
If the object opacity is 0, change the opacity to 1.

25
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

IF Control Structure Parts


The IF control structure has two parts: the IF part, and the
ELSE part.
If the IF part is executed, the ELSE part is never
executed.
If the ELSE part is executed, the IF part is never
executed.
Both the IF part and the ELSE part of an IF statement
can contain another nested IF control structure.

25
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

WHILE Control Structure


The WHILE statement executes instructions repeatedly in
a loop while a condition is true. This conditional execution
is also known as repetition.
The WHILE condition:
Acts like a gatekeeper to an event.
Must be true to allow the programming instructions
within the loop to execute.

26
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

WHILE Control Structure and Repetitive


Execution
After all of the programming instructions within a loop are
executed, the WHILE condition is evaluated again for
repetitive execution.
If the condition is still true, execution will repeat.
If the condition is false, the loop will be skipped and
execution will continue with the next programming
statement following the WHILE control structure.

26
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Interpret an IF Control Structure


An IF statement is a decision based on a condition.
Example condition: If it rains today I will wear a raincoat.
Otherwise, I will wear a sweater.
IF statements can be interpreted using a process flow.
A process flow is a graphical representation of a process model.
Process flows use shapes to represent the actions in the model.

26
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

IF Statement Process Flow


If it rains today, then I will wear a raincoat. Otherwise, I will
wear a sweater.
True

If it rains
today, then

Do this: Wear
sweater

Do this: Wear
raincoat

End

26
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

False

Use the IF and WHILE Control Structures

IF Statement Process Flow Example


If the cat walks into the dog, then the cat says Excuse
me! Otherwise, the cat continues walking.
True

If cat
collides with
dog

Do this: Cat
continues to
walk

Do this: Cat
says, Excuse
me!

End

26
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

False

Use the IF and WHILE Control Structures

Steps to Program an IF Statement


1. Insert the initial motions that happen before the IF statement is
executed.
2. Drag and drop the IF statement control structure into the Code
editor and select the true condition as a placeholder during setup.

3. Replace the true condition with a condition to evaluate, such as a


function.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

IF Control Structure Example


If the cat collides with the dog, then the cat moves
backward and says Excuse me! Otherwise, the cat
continues to move forward.
The isCollidingWith function was dragged onto the true
condition placeholder. This function tells us if one object is
colliding with another.

26
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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.

Infinite loop: Never stops.


The hour and minute hands on a clock continue rolling.

26
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

WHILE Control Statement Process Flow


The Queen moves forward, unless she collides with the
Playing Card. If the Queen collides with the Playing Card,
she stops and turns to face the camera.
True

While the
Queen is
collision-free

Queen stops
and turns
around

Queen moves
forward

End

26
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

False

Use the IF and WHILE Control Structures

Steps to Program a WHILE Statement


1. Drag and drop the WHILE statement into the Code editor and
select the true condition as a placeholder.

2. Replace the true condition placeholder with the condition to


evaluate.
3. Insert procedures that will be executed while the condition is true.
4. Insert the procedures that are executed after the while loop stops
executing.

27
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

WHILE Statement Example Code


While the Queen is not colliding with the Playing Card, the
Queen moves forward repeatedly. If the Queen does
collide with the Playing Card, the WHILE loop stops and
the program continues with the next instruction: she stops
and turns to face the camera.

27
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

Steps to Test a WHILE Statement


1. Position objects such that the WHILE condition will evaluate to
true.

2. Observe that all programming instructions within the WHILE loop


execute.
3. Ensure that the WHILE loop execution stops when the while
condition is no longer true.

27
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use the IF and WHILE Control Structures

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Expressions

27
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Objectives
This lesson covers the following objectives:
Create an expression to perform a math operation
Interpret a math expression

27
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Location of Math Operators


Math operators are available in the cascading menus
where you select the argument values for:
Amount and Duration
getDistance functions

27
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

View Expressions in a Distance Argument


Select the Math option to view the available math
operators in a procedures distance argument.
Select from two different sets of math expressions.
The first set lets you specify the value of one operator
the second set lets you specify the values of both operators.

27
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

getDistanceTo Function Display


Select the Math option to view the available math
operators for the getDistanceTo function's argument.

28
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Steps to Create an Expression


1. Summarize the timing or distance problem in your program.
2. Consider the expression that will solve the problem.

3. Code the expression.


4. Test and debug the expression until the animation works as
intended.

28
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Steps to Move an Object the Distance to


Another Object
1. Drag the move procedure for an object into the Code editor.
Select forward and a distance placeholder value.
2. From the Functions tab, drag the getDistanceTo function onto the
distance argument placeholder.

3. From the cascading menu, select the target object to which the
object should move.

28
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Steps to Modify the Distance Using a Math


Operator
1. From the getDistanceTo tile, click the outer-most arrow to open
the menu of distance values, and then select the Math option.

2. Select getDistanceTo - ???


3. Select a default value to reduce the distance by, or select Custom
DecimalNumber to enter a value.

4. Test and debug the expression as necessary.


28
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Editing the Expression


During the debugging process, you may need to adjust
the value of the expression. Click the arrow next to the
value, and select a new default value or use the Custom
DecimalNumber... menu to select a more defined value.

28
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Subtract Depth from the Expression


Subtracting the depth of the target object from the
expression is a more precise way to ensure that the
moving object lands directly near the target object without
going through its center.

28
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Steps to Subtract Depth from Expression


1. Select the target object in the instance menu.
2. From the Functions tab, drag the getDepth tile onto the existing
distance value in the expression.

3. Test and debug the animation, and adjust the expression as


necessary.

28
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Formulating the Expression


To interpret an expression, it is helpful to draw a picture or
write the values you know before formulating the
expression.
Example:
Z = X (a / b)
Z = Distance moved
X = Distance from adult penguin to cave
a = Cave width
b=2
29
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Expressions

Expression Example Answer


Examine the visual associated with this expression. The
adult and baby penguin instances are moving towards the
cave. Will they go inside? No, they stop outside the cave.

29
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Variables

29
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Objectives
This lesson covers the following objectives:
Understand variables and how they are used in
programming

29
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Variables Example
Below are the variables and their values for a wolf
instance.
Grey color

1.17 meter height

29
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

0.46 meter width

1.0 opacity

Use Variables

Variables for Data Storage


A variable is like a container that stores a specific type of
data for later retrieval and use by your program. Declare a
variable by naming it and selecting the type of data to
store in it. Then, specify a default value for the variable.
Numbers (1, 0.254)

Boolean values
(true or false)

TextString
List of objects

29
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

(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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Variable Data Types in Alice 3


Data Type
Decimal Number
Whole Number

Boolean

Classes

30
1

Description
Perform arithmetic and set the value of a procedure's arguments.

Examples: 0.1, 2.25, 98.6.


Perform arithmetic and set the value of a procedure's arguments.
Examples: 1, 459, 30.
One of two values: true or false.
Usually is the result of tests that compare one thing to another.
The classes of objects that are available in your animation.
Examples: Biped, Scene, Quadruped.

TextString

A String of characters such as hello and goodbye.

Other

Sounds, colors, shapes, and other special values.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Steps to Declare a Variable


1. Drag the variable tile into the Code editor.
2. Select the value type and name the variable.
3. Initialize the variable (set the first value that the variable will hold)
and click OK.

4. Note that the preview of the variable, above the thin line, displays
the variable settings.

30
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Changing Initialized Value


Remember, the initial value you specify for the variable
can be considered a placeholder value, and changed at a
later time.

30
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Using Variables in Procedures


To use a variable that has been declared in a procedure,
drag the variable tile onto the procedures argument value.
The argument is replaced with the variable's initialized
value. Alice 3 helps you visualize the locations you can
place a variable by darkening the screen and highlighting
the values that can be replaced by the variable.

30
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Using Variables in Procedures

(continued)

Be aware that a variable must be declared and initialized


before it can be referenced by any other statement in your
code. If you try to reference a variable before it exists, your
program will encounter an error at runtime.
Caution: Alice highlights all arguments that might potentially
reference the selected variable, including those arguments
that precede the variables existence.

30
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Using Variables in Math Calculations


Note that variables can also be created and used in math
calculations.
You can drag a declared variable onto any value within a
math expression.

30
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Changing an Initialized Value


You can change the initialized value of a variable
using the drop-down list.
The new value of all arguments using the variable will
change when the initialized value is changed.
If one of the default values listed on the drop-down is not
what you need, use the CustomWholeNumber menu
option to specify another value.

31
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Changing an Initialized Value Display


You can change the initialized value of a variable
using the drop-down list.

31
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Steps to Randomize an Initialized Value


1. Click the down arrow next to the initialized value.
2. Select Random from the drop-down list.

3. Choose either the option to randomize using a predefined range


or the option to randomize based on values you establish.
4. If you choose the option to randomize based on values you
establish, select the starting and ending values for the range
using the cascading menus.
Remember, argument values can always be changed. Randomization
of variable values can add value to an animation or game by creating
random behavior.

31
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Randomize an Initialized Value Display


Below shows how to randomize an initialized value.

31
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Use Variables to Manage Speed Example


The example program below is a race between a walrus
and a baby yeti. They both move forward continuously a
random amount until they reach the flags. If the walrus
collides with the flags sooner than the baby yeti, the
walrus wins.

31
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Use Variables to Manage Speed Example


(continued)

The speed traveled is managed by two variables:


walrusSpeed and sledSpeed
Each time the program runs, a new random number
between 0.25 and 2.0 is assigned to each variable.

31
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Relational Operators
Notice the use of relational operators in the IF statement.

A relational operator is a symbol used to express a relationship


the equality, inequality, or degree of equalitybetween two
expressions. Two suitable expressions combined with a
relational operator often form a relational expression or condition
in a programming language.
31
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Types of Relational Operators


The relational operators available in Alice 3 are:

31
7

Relational Operator

Description

<

Less than

Less than or equal to

>

Greater than

Greater than or equal to

==

Equal to

Not equal to

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Variables

Summary
In this lesson, you should have learned how to:
Understand variables and how they are used in
programming

31
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Getting Started with Alice


Use Keyboard Controls

31
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Objectives
This lesson covers the following objectives:
Use keyboard controls to manipulate an animation

32
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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.

This is often referred to as event handling.


32
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

What Happens When an Event Occurs?


Typically, an event triggers (fires, or sets in motion) the
execution of a procedure or function.
For example, when a user presses an up arrow key on the
keyboard (event), it triggers a method that makes the
object in the animation move up (event handling method).

32
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Keyboard Controls Example


In Alice 3, you can assign procedures to keys on your
keyboard. When the animation viewer clicks a certain
keyboard key, the procedure assigned to the keyboard
key is executed. For example, clicking the right-arrow key
on the keyboard turns the submarine to the right.
In programming, keystrokes and mouse clicks are events.
Coding events to handle each procedure is referred to as event
handling.

32
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Types of Event Listeners


While this topic focuses on keyboard listeners, there are
four types of event listeners available in Alice 3:
Scene Activation/Time
Keyboard
Mouse
Position/Orientation

32
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Access Event Listeners


1. In the Code editor, click the Scene tab.
2. Click the button next to initializeEventListeners and choose Edit.

32
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

View Event Listeners


View the initializeEventListeners tab. You will Add an
event listener to this tab.

33
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

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

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Types of Keyboard Listeners

33
2

Data Type

Description

addKeyPressListener()

This listener lets you program procedures for the


keyboard key(s) you specify.

addArrowKeyPressListener()

This listener lets you program procedures for the arrow


key(s) you specify.

addNumberKeyPressListener()

This listener lets you program procedures for the


number key(s) you specify.

addObjectMoverFor(???)

This listener lets you program the user-defined


movement for a specified object.

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Program Keyboard Event Listeners


For example, we will program keyboard event listeners to
command the submarine to move up and down using the
A and B keys, and move left, right, forward and backward
using the arrow keys.

33
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Add Keyboard Event Listener


1. Select the Add Event Listener drop-down list.
2. Select Keyboard.
3. Select addKeyPressListener.

33
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Program the IF Conditional Statement


1. Drag the IF statement into addKeyPressListener.
2. Select the true condition.

33
5

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Select the Keyboard Key to Activate


an Objects Motion
1. Drag the isKey ??? tile onto the true condition.
2. A key menu appears. From the drop-down menu, select the
keyboard key that you want to use to control the motion.

33
6

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Program Motions Activated by Key


Press
1. From the Instance drop-down menu, select the object controlled
by the keyboard key.

2. Drag the procedure that should be activated by the keyboard key


into the IF statement and select the arguments. You could drag
multiple procedures and control statements into the IF statement.
For example, when the A key is pressed, the submarine moves
and then turns.

33
7

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Program Additional Listener Actions


To program the keyPressListener to listen for more than
one keyboard key, add additional IF statements to the
listener structure. There are two ways to do this:
Add a series of IF statements one after another and
always leave the ELSE condition empty.
Nest additional IF statements in the ELSE condition.
Both methods execute in the same manner. The following
steps use the second method, nesting IF statements in
the ELSE condition, to save display space.
33
8

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Program Additional Listener Actions


1. Drag an IF statement into the ELSE condition of an existing IF
statement and select the true condition.
2. Drag the isKey ??? variable onto the true argument.
3. Specify the keyboard key to listen for.
4. Specify the programming statements to execute.

33
9

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Completed Programming Instruction Example


Below is an example of a submarine programmed to
move up and down using the A and B keyboard keys.

34
0

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Move Objects Using Arrow Keys


1. Select the Add Event Listener drop-down menu.
2. Select Keyboard.
3. Select addObjectMoverFor.
4. Select the entity, or object, to control.

34
1

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Steps to Test Event Listeners


1. Run the animation.
2. Click inside the animation window with your cursor.
3. Use the keyboard keys (specified in addKeyPressListener) to
make the object perform the procedure (move up and down).
4. Use the arrow keys on your keyboard to move the object forward,
backward, right, and left.

34
2

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Summary
In this lesson, you should have learned how to:
Use keyboard controls to manipulate an animation

34
3

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

Use Keyboard Controls

Contact Us
Send your queries to Oracle Academy Instructor:
academy-apac-instr_sg@oracle.com

34
4

Copyright 2012, Oracle and/or its affiliates. All rights


reserved.

S-ar putea să vă placă și