Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction...

55
Alice: A Visual Introduction to Programming Chapter 1 1-1

Transcript of Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction...

Page 1: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Alice:

A Visual Introduction to Programming

Chapter 1

1-1

Page 2: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 3: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 4: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 5: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 6: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 7: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 8: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 9: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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?

Page 10: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 11: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 12: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 13: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 14: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Objects

Alice uses objects

o Tent

o Soldier

o Princess

Objects perform actions

1-14

– Turn

– Move

– Fly

– Wave

Page 15: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

The Alice System

1-15

Page 16: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Open SnowLove in Examples

1-16

Page 17: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Executing Alice Program

1-17

PLAY

Page 18: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 19: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

The Alice Environment

1-19

Toolbar

Scene

Editor or

World

View

Events

Editor

Object Tree

Details

Panel

Tile

Tile

Page 20: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 21: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 22: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Object Properties

1-22

Object

Selected

Change

Properties

Object

Selected

Page 23: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 24: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 25: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Methods

Methods

o Set of instructions to perform task

o Default method

world.my first method

1-25

Page 26: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Methods

Each object and its subparts can be manipulated with methods

o Move

o Turn

o Roll

o Say…

1-26

Page 27: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

The World is an Object

Contains all other objects

Also has its own properties

o Atmosphere color

o Lighting

o Fog

1-27

Page 28: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 29: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 30: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 31: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 32: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Creating a New World

• Create a new world

o File New

o Choose template

Page 33: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Adding Objects

Click on Add Object

Page 34: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Adding Objects: Scene Editor

1-34

Click on People collection thumbnail

Page 35: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Add Coach

Place object in scene editor by

o Clicking on it

o Drag it

1-35

Page 36: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Coach Object With Bounding Box

1-36

Page 37: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Saving Alice World

Click on File then Save World

Has .a2w extension

Page 38: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 39: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 40: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

3D Objects and the Camera

Alice world and objects are three-dimensional

o Height

o Width

1-40

– Depth

} 2D objects

Page 41: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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.

Page 42: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 43: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 44: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 45: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Modifying Objects

1-45

Use Mouse Mode Buttons

Page 46: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 47: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 48: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 49: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Rotational Movement

1-49

Page 50: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 51: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 52: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 53: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

Coordinate System

1-53

Page 54: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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

Page 55: Alice: A Visual Introduction to Programmingamanno/Chapter_01_Intro_to_Alice.pdfA Visual Introduction to Programming Chapter 1 ... A modern programming tool o 3-D graphics ... Lab You

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