I like commuting to work on my Greenspeed recumbent tricycle
A little about you
Please fill out a piece of paper with the following:
Your name and username (optional)
Your school or degree program
Does this course fulfill a degree requirement for you (other than general
credit hours)
What do you hope to learn from this course
What is your greatest concern with respect to this course
If you have ever done any programming, what was the context and the
language
Anything else you'd like to add
Why learn programming?
Automate routine work by writing small programs
embedded programming environments in spreadsheets, databases,
editors, animation and game development systems
Write small independent programs to automate tedious work, transform data
going from one system to another, transform images and sound, mine
the web for specific information
Learn to look at the world computationally
Creative fun: you control the computer!
Improve your problem solving skills
Programming languages we'll use
First 3 weeks (and 4th week assignment): Alice
learn the basic elements of programming
easy to do fun things
specialized for a certain kind of animated and interactive graphics
After that: Python
useful for a vast range of applications
many similarities with other general purpose programming languages
Interactive: active user interacts with keyboard and mouse
For Your Information
FYI When you see in any course web material a link to a file (as in the last
slide), you can right-click it to download the file.
FYI FYI items, like these two, are just For Your Information: you may
find them useful, but they're not course content you are responsible for.
Demo: Creating a new Alice world
File > New World
Templates tab
double click desired template
Demo: Adding objects
Saving your Alice world
File > Save World
Writing and testing an animation is an intense load on the computing
system—a crash can occur ☹
So save your world at least every 10 minutes
also save to a backup space, in case your working copy gets corrupted
Some Alice tools and techniques
The mouse is used to approximately position objects in the scene
Camera navigation is used to set the camera point of view
Object drop-down menu used for many things including
resizing objects
more precisely position objects in the scene
Quad view is used to position one object relative to another object
Center of an object
At the center of mass
Where it stands on the ground
Where it is held
Object-oriented programming concepts
Objects
Classes
An object has
has a name, such as boar and boar2
may have sub-parts that are also objects, such as frontLeftLeg
has properties, such as color and skin texture
can perform methods (actions) on command, such as turn
has functions that allow programs to obtain information about the object
Objects in Alice and other languages
Alice objects are (usually) visible
Objects in other object-oriented (OO) languages, such as
Python, are similar, but
other languages often do not make Alice's distinction between methods and functions
objects in other languages may be anonymous (not have names)
Alice object parts
Objects may be composed of parts
they are accessible through the object browser (upper left)
Class
Objects are categorized into classes, such as boar
Each object is an instance of the class
boar2 and boar3 are instances of boar
All objects in a class have the same methods and set of properties, but
their property values are usually different
FYI In Alice objects are classes (they can be copied to create instances of
themselves), but most languages distinguish objects and classes
Galleries
Alice classes (3D models) are found in the galleries
all are installed with the software on STC machines
similar installation is recommended on personal machines
then you do not need the CD and web galleries
Click the green ADD OBJECTS button for scene editor to access object
galleries
Click the green DONE button to return to the program editor
Steps for Alice movie programming
State the problem
a scenario is a general description of an animation, as in the
statement of an exercise
Evaluate the Tools available to solve the problem
review the text
Design an Algorithm (systematic method) for solving the problem
a story board in the case of an animation
Implement the algorithm
write the program, a bit at a time
Test and Revise any earlier steps as needed
debug the program
Story boards
We will use the storyboard design technique commonly used in the film
industry
Example: Penguin cheerleaders scenario
Scenario
White and pink penguins are on a snow-covered landscape.
The pink penguin says "Go Team!" and jumps on the head of the
white penguin. But they sink. The white penguin says "I'm sinking.", and
the pink penguin says Yikes!. The pink penquin then dives off, while the white penguin
rises up.
Storyboard Option—Screen shots
Storyboard Option—Text Form
A textual storyboard describes the action in each scene
Penguin cheerleaders
Pink penguin turns to face white penguin.
Pink penguin jumps on white penguin and says "Go Team!"
Penguins sink and white penguin says "I'm sinking!"
Pink penguin says "Yikes!" and dives of, while whtie penguin rises up.
A program (a.k.a. script) is a sequence of commands
in an animation, they direct the objects perform certain actions
A method is a sub-program associated with an object
in a simple Alice movie, just write myfirstmethod of the World object,
which is called automatically when the movie is played
Documenting code
Comments document code
they explain the purpose of a particular part of a program to humans
a group of instructions may perform an action that is not obvious
In an animation program, the lines of a text-form storyboard make
excellent comments
Comments in Alice
Alice comments begin with // (two slash characters)
A comment ends with the end of the line
use multiple comments lines for long comments
Drag-and-drop the // tool at the right of the tool bar at the bottom of
the screen and then enter comment text
Statements
The actions in methods are called statements
In Alice we have created statements by drag-and-drop from three locations
the toolbar at the bottom of the screen
for Doinorder, Dotogether, and //
the methods tab of the details panel on the left
to call methods of the object selected in the object browser
the properties tab of the details panel on the left
to assign a new values to a property
Statement blocks in Alice
Dotogether and Doinorder blocks
They can be nested one inside the other
Do together statements in the same block should take the same amount of
time
otherwise results may be unpredictable
the default duration is one second
Methods may have arguments
For example, the move method calls we used had direction, distance, and
duration arguments
Some arguments are optional (more... down arrow in Alice) and have default values
if omitted
How do you program an Alice object to perform an action?
Type the name of the object, a dot, the name of the corresponding
method, and then the argument list
Select the functions tab and drag the corresponding function onto the object
Select the object, and then drag the corresponding
method from the method tab into the right place in the program
A or C
Answer: C
An object may contain
methods
properties
other objects
A and B
all of the above
Answer: E
Alice vehicle property
The vehicle property allows objects to be linked so when the vehicle
moves, the object "riding on" the vehicle moves with it
it says in the same position and orientation with respect to the
vehicle
by default every objects vehicle is World
Like any property, the vehicle can be set in a program by dragging the
property into the program as if it were a method
Alice asSeenBy motion
Every object's pointOfView property has both position and
orientation components
By default, an object moves with respect to its own orientation
The move method has an optional asSeenBy argument that can be used to
specify that motion is to be with respect to the orientation of any other
object (including World)
Saving a scene after method calls
It is not possible to save the scene at any point but the beginning of a
program
To save a scene after one or more method calls, modify an initial scene by
right clicking the method's object
select the methods option
select the method to call and its arguments via the pop-up menus
Limitation: optional arguments and argument values that require a
drag-and-drop can't be used
Testing
You're not done with a program until you run it to be sure it does what
it is supposed to
Use an incremental development process
run your program after every few lines are added
then if there is a new problem, you know it involves one of the lines
you just added
this saves much aggravation
Programming style
It is important to write programs so they are as easy to understand as
possible
they are usually difficult enough to understand under the best of
circumstances: readers need all the help they can get
readers include you when you are debugging it ☺
This is why style in evaluated when programs are graded
Suitable comments are an important part of program style
avoid comments that just paraphrase the code, without providing a
"bigger picture"
How to avoid a lot of programming trouble!
Programming is problem solving
Have a plan for your program, and even a plan for how you solve
problems
any but the easiest problem solving requires a plan
Warning
When students in this course are having more difficulty than they
should, the most common reason is inadequate attention to planning.
A plan for problem solving
STAIR steps for problem solving:
State the problem
Evaluate the Tools available to solve the problem
Design an Algorithm (systematic method) for solving the problem