Alice:
A Visual Introduction to Programming
Chapter 1
1-1
Reasons to Program
The joy of programming
To create a tool
Make something creative
For non programmers
o Learn a new way to think
Drawing course does same thing
o Helps problem solving skills
How to find answer to question
Figure out how to perform a task
Alice
A modern programming tool
o 3-D graphics
o 3-D models of objects
People, animals, fantasy creatures, vehicles and backgrounds
Animation
o Objects can be moved around a 3D virtual world
o Just like video game or simulation
CD in book has Alice worlds from chapters
Can download Alice 2.4 from the web www.alice.org
Origination of Alice
Named in honor of mathematician Charles Lutwige Dodson
o Was able to do complex math and logic
o Knew he needed to make things for learner
Simple
Fascinating
Pen name was Lewis Carroll who wrote
o Alice in Wonderland
o Through the Looking Glass
Alice
Programming in Alice is like being a movie director, puppeteer, or choreographer in a 3D world
Create programs by dragging words and objects to editor with mouse
Kinds of Animations
Two kinds of animations
o Movie
You can tell a story
Use is passively watching the animation
o Interactive
Active user clicks on mouse or types on keyboard
Actions of user are called events
Programming Terminology
Algorithm – step by step structure to solve a problem
Program – implementation of algorithm using a programming language
Instruction – an action to be performed
Pseudo code – loose set of instructions not tied to any program environment
Computer
A device that follows instructions for manipulating and storing data
Computer program – set of instructions that computer follows to perform a task
o Instructions must be carefully written to follow a logical sequence
That is key – you think of what logical sequence you want computer to follow
Running or executing program – when computer is performing instructions
1-8
Algorithms
Algorithm
o Set of well-defined logical steps
o Must be performed in order to perform a task
1-9
• Example: Making a cup of instant coffee
– Remove lid from coffee jar
– Put lid down on counter
– Remove 1 tsp of coffee from jar
– Place that coffee in a cup
– Add 8 oz of boiling water to cup
– Use teaspoon to stir water and coffee mixture
– Stir 10 revolutions
– Remove teaspoon from cup and place on counter
Is this adequate?
Is it detailed enough?
Is it anything
ambiguous?
Algorithms
Algorithms are understandable by humans (natural language)
Computers understand machine language not natural language
1-10
Blah
Blah
Blah
0110001001101100011000010110
1000001000000110001001101100
011000010110100000100000
0110001001101100011000010110
1000
Programming Languages
Programming languages are converted to machine language by
o Compiler – converted before executing program
o Interpreter – instructions converted during execution each instruction, Ex: Alice
1-11
Starting
…01010011011101000110000101110010011101000110
1001011011100110011100100000
out
…011011110111010101110100
With
…0111011101101001011101000110100000100000
Alice
…0100000101101100011010010110001101100101
Programming Languages
Operators o + - * /
o Perform arithmetic and other functions on data
Syntax
o Set of rules that must be followed
o Similar to the set of rules that are followed when people speak a natural language
Program or code
o Consists of keywords, operators, punctuation arranged in proper logical sequence
o Save, compile, link, executable program is produced
1-12
Checkpoint
What is a computer?
What is an algorithm?
What is a program?
What is only language computers understand?
Why were programming languages invented?
1-13
Objects
Alice uses objects
o Tent
o Soldier
o Princess
Objects perform actions
1-14
– Turn
– Move
– Fly
– Wave
The Alice System
1-15
Open SnowLove in Examples
1-16
Executing Alice Program
1-17
PLAY
Controlling Runtime Speed
Can increase speed of program
Move slider of speed control
Useful to skip over parts of program that work when troubleshooting
Max of 10x normal
The Alice Environment
1-19
Toolbar
Scene
Editor or
World
View
Events
Editor
Object Tree
Details
Panel
Tile
Tile
Checkpoint
How do you control speed that a world is played?
What part of Alice environment displays a view of the world?
What part of the Alice environment displays a list of objects in the world?
What is a tile?
1-20
Objects
Anything that can be identified as unique from other things
How is an object unique? o Has a name
o Has properties Color, opacity, etc.
o Can perform actions (methods) Associated actions (move, turn , think, etc.)
Tasks it can carry out
Object Properties
1-22
Object
Selected
Change
Properties
Object
Selected
Opacity
How transparent an object is
o Less opaque an object, more transparent
Opacity of 100%, cannot see through the object
Opacity of 0%, object is transparent
Like clear glass
An object with opacity of 0% is invisible
This can be used to make something look far away in water or have a ghostly appearance
Objects and Object Parts
1-24
Objects are made of other subparts
Snowman made of: o head
topHat
leftEye
rightEye
carrotNose
mouth
o leftArm
o rightArm
o Bottom
Objects named in “camel Case” format o 1st letter is lower case
o Upper case next word’s 1st letter
Methods
Methods
o Set of instructions to perform task
o Default method
world.my first method
1-25
Methods
Each object and its subparts can be manipulated with methods
o Move
o Turn
o Roll
o Say…
1-26
The World is an Object
Contains all other objects
Also has its own properties
o Atmosphere color
o Lighting
o Fog
1-27
Checkpoint
What are properties?
What is the name of a property that determines
o An object’s color?
o You can see through an object?
What is a method?
What do you call an object made of other objects?
1-28
Alice has Class(es)
Objects are created from classes
Blueprint that describes a particular “type” of object
Defines a particular kind of object
1-29
Animals Collection
Classes
Gallery is a collection of different object types (animals, beach, people, etc.).
Each item found in the Gallery is a class
Two galleries are used
o Local gallery (stored on computer)
o Web gallery (maintained by creators of Alice)
1-30
Class Instance in Alice
Class: Chicken
Instance: An object that is created from a class
Examples
o Chicken
o Chicken2
o Chicken3
Each instance has its own properties, methods, functions
Can manipulate each one individually
1-31
Creating a New World
• Create a new world
o File New
o Choose template
Adding Objects
Click on Add Object
Adding Objects: Scene Editor
1-34
Click on People collection thumbnail
Add Coach
Place object in scene editor by
o Clicking on it
o Drag it
1-35
Coach Object With Bounding Box
1-36
Saving Alice World
Click on File then Save World
Has .a2w extension
Demo: Saving a world
Writing and testing an animation is an intense load on the computing system
o Crashes can occur
Best solution Save your world every 15 minutes
Also save to a backup system
Ex: USB flash drive
Checkpoint
What is a class?
What is stored in the Alice galleries: classes or objects?
When you click on Add Object button what mode does Alice go into?
What are two ways to add object to scene?
What appears around object when selected?
Where do you find an object’s properties?
39
3D Objects and the Camera
Alice world and objects are three-dimensional
o Height
o Width
1-40
– Depth
} 2D objects
3D Movement
1-41
Motion is based on OBJECT’s
perspective…our left is the Coach’s right
Forward is perceived as the object getting
larger as it gets closer to us.
Backward is perceived as the object getting
smaller as it gets farther away from us.
The Camera
When you create an Alice world a camera is automatically placed in the world
Displays image of world in Scene Editor window
o Called camera viewpoint
1-42
Camera Controls
Drive forward, backward, turn left and right
Move camera up, Tilt camera up, down
down, left, right
You can make camera move faster by dragging mouse pointer away from center of camera control
Different World Perspectives
Sometimes difficult to tell where object is in relation to other objects
Fish looks like it should be in water
Change world perspective
o Look at fish from perspective of water instead of sky
Also called Camera control or point of view
Modifying Objects
1-45
Use Mouse Mode Buttons
Modify Objects
1-46
Move Freely
Move Up
and Down
Turn Left
and Right Tumble
Copy
Resize
Turn Forward
and Backward
When checked can
modify subpart
Center of an object
Provides pivot or spin reference
o Object spins around center
At the center of mass
Where it stands on the ground
Where it is held
Orientation
When you click on object and rotate it you will notice arrows
o Green points to up
o Red points where object thinks right is
o Blue is forward to the object
48
Rotational Movement
1-49
Scene Editor Viewing Modes
Single View o Viewing scene from
World View angle
Quad view o View scene from four
views World View
From top
From right
From front
o Allows you to position one object in relation to another object
1-50
Zoom
Scroll
Quad view
Relational Positioning in Quad View
Notice how rabbit is positioned in relation to chicken
1-51
From the right From the front
From the top World view
Scroll view
Zoom
Using Coordinates
Axes are measured in meters
Point (0,0,0) is at center of the world
When you add an object to the world by clicking on the class places the object at (0,0,0)
Can see position of an object in pointOfView property
1-52
X axis
Coordinate System
1-53
Homework
Read chapter 1
Do tutorials
o Tutorials 1-1, p 6
o Tutorials 1-2, p. 19
o Tutorials 1-3, p. 34
o Tutorials 1-4, p. 40
o Tutorials 1-5, p. 43
Answer questions in handout
Do lab assignments after handing in answered questions
Due one week after assigned with 1 week grace
1-54
Lab You must hand in your answers to the questions in the handout
You will get the lab handout showing what labs to do only AFTER you have handed in the handout
o Lab exercises require you to demonstrate your program to the professor
o When you write code you must explain to professor what each line of code does and why.
o Professor will sign lab sheet after you do those two things
o You only get full credit for lab exercise if professor signs lab sheet
o If you hand in lab without explaining code then you will lose half credit
If you choose to do the lab exercises before you hand in the questions then the professor will not assist you with your lab questions
If you finish lab exercises before you hand in questions professor will not sign off until handout is handed in