Alice ppt ch01

50
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning of each presentation. You may customize the presentations to fit your class needs. Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor Resources disc. 1

Transcript of Alice ppt ch01

Page 1: Alice ppt ch01

About the Presentations

•  The presentations cover the objectives found in the opening of each chapter.

•  All chapter objectives are listed in the beginning of each presentation.

•  You may customize the presentations to fit your class needs.

•  Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor Resources disc.

1

Page 2: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition

Chapter 1 An Introduction to Alice and Object-Oriented Programming

Page 3: Alice ppt ch01

Objectives

After finishing this chapter, you should be able to: •  Provide a brief definition of the following terms:

–  Algorithm, computer program, object, property, method, state of an object, object-oriented programming (OOP), computer programming language, Integrated Development Environment (IDE), function, event, class, instance, instantiation, and method parameter

An Introduction to Programming Using Alice 2.2, Second Edition 3

Page 4: Alice ppt ch01

Objectives (cont’d.)

•  Run the Alice software and locate and describe the following components of the Alice interface: –  World window, Object tree, Details area, Editor area,

Events area, menu bar, Trash can icon, Clipboard icon, Play button, Undo button, and Redo button

•  Load and play an existing Alice world

An Introduction to Programming Using Alice 2.2, Second Edition 4

Page 5: Alice ppt ch01

Objectives (cont’d.)

•  Create a new Alice world by adding objects to a blank world, positioning them, and using simple methods to animate those objects

•  Print the code for Alice methods and events •  Save an Alice world as a QuickTime movie file

(*.mov)

An Introduction to Programming Using Alice 2.2, Second Edition 5

Page 6: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 6

Object-Oriented Programming and Alice

•  Algorithm –  A step-by-step process

•  Methods –  Programs that manipulate the properties of an object

•  Object –  Collection of properties along with the methods that

are used to manipulate those properties •  State of an object

–  Values stored in the properties of an object at any given time

Page 7: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 7

Tutorial 1A – Exploring the Alice Interface

•  Start the Alice software –  Integrated Development Environment (IDE)

•  Computer program that is used to write other computer programs

•  Welcome to Alice! dialog box has five tabs –  Tutorial, Recent Worlds, Templates, Examples, and

Open a world •  Click the Tutorial tab and you will see four Alice

tutorials

Page 8: Alice ppt ch01

8 An Introduction to Programming Using Alice 2.2, Second Edition

Page 9: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 9

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  Click the Recent Worlds tab –  You will see thumbnail sketches of the most recently

saved Alice worlds •  Click the Templates tab

–  Templates for starting a new virtual world - dirt, grass, sand, snow, space, and water

•  Click the Examples tab –  Example worlds created by the Alice developers are

provided

Page 10: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 10

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  Click the Open a world tab –  Tab is used to access Alice worlds saved on your

computer •  Click the Examples tab

–  Click the lakeSkater thumbnail –  Click the Open button to open the lakeSkater Alice

world

Page 11: Alice ppt ch01

11 An Introduction to Programming Using Alice 2.2, Second Edition

Page 12: Alice ppt ch01

12 An Introduction to Programming Using Alice 2.2, Second Edition

Page 13: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 13

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  The main work areas of the Alice interface –  The World window

•  Contains a view of the lakeSkater virtual world •  Set of blue arrows below the window controls the Alice

camera –  The Object tree

•  Appears to the left of the World window •  Shows the objects in the current Alice world organized

as a tree of tiles

Page 14: Alice ppt ch01

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  The main work areas of the Alice interface (cont’d.) –  The Details area

•  Located below the Object tree •  Has tabs to show properties, methods, and functions

for the currently selected Alice object •  Function: method that returns a value, such as the

distance between two objects –  The Editor area

•  Largest area of the Alice interface

An Introduction to Programming Using Alice 2.2, Second Edition 14

Page 15: Alice ppt ch01

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  The main work areas of the Alice interface (cont’d.) –  The Events area

•  Above the Editor area •  Shows existing events and is used to create new

events •  Event: consists of a condition, called an event trigger,

and a method, called an event handler

An Introduction to Programming Using Alice 2.2, Second Edition 15

Page 16: Alice ppt ch01

Tutorial 1A – Exploring the Alice Interface (cont’d.)

•  Other elements of the Alice interface –  Trash can icon and the Clipboard icon are used for

editing –  Undo and Redo buttons

•  Useful for editing an Alice world –  Play button is used to play an Alice world

•  Menus –  Alice interface has a menu bar at the top of the

screen with four menus: File, Edit, Tools, and Help

An Introduction to Programming Using Alice 2.2, Second Edition 16

Page 17: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 17

Tutorial 1B – Playing an Alice World

•  Buttons near the top of the Alice interface –  Play, Undo, and Redo

•  Click the Play button to watch the show unfold •  New window has a speed slider control and five

buttons across the top of the window –  Pause –  Play –  Restart –  Stop –  Take Picture

Page 18: Alice ppt ch01

18 An Introduction to Programming Using Alice 2.2, Second Edition

Page 19: Alice ppt ch01

Tutorial 1B – Playing an Alice World

•  The Restart button –  Used to begin playing the current world again from

the beginning –  The Pause and Play buttons work like the pause and

play buttons on a DVD player –  Click the Restart button –  Experiment with the Pause and Play buttons

An Introduction to Programming Using Alice 2.2, Second Edition 19

Page 20: Alice ppt ch01

Tutorial 1B – Playing an Alice World (cont’d.)

•  Speed slider –  Used to change the speed of the world while it is

playing –  Restart the world, and experiment with the speed

slider control •  Take Picture button

–  Captures an image of the currently playing world and saves it in a data file

–  Restart the world and click the Take Picture button to take a picture of the world

An Introduction to Programming Using Alice 2.2, Second Edition 20

Page 21: Alice ppt ch01

Tutorial 1B – Playing an Alice World (cont’d.)

•  Stop button –  Stops the world that is currently playing and returns

you to the standard Alice interface –  Once pressed, you will need to click the standard

interface’s Play button to replay the world

An Introduction to Programming Using Alice 2.2, Second Edition 21

Page 22: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 22

Tutorial 1C – Creating Your First Alice World

•  Start the Alice software •  In the Welcome to Alice! dialog box, click the

Templates tab •  Thumbnail sketches for the six new world templates

–  Dirt, grass, sand, snow, space, and water

Page 23: Alice ppt ch01

23 An Introduction to Programming Using Alice 2.2, Second Edition

Page 24: Alice ppt ch01

24 An Introduction to Programming Using Alice 2.2, Second Edition

Page 25: Alice ppt ch01

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Adding objects to an Alice world –  Click the large green ADD OBJECTS button in the

bottom-right corner of the World window –  Note that the Alice interface now looks different –  Scene Editor

•  Has new controls, a larger World window, and object galleries on the bottom

•  Replaces the Events area and the Editor area when you are in Scene Editor mode

An Introduction to Programming Using Alice 2.2, Second Edition 25

Page 26: Alice ppt ch01

26 An Introduction to Programming Using Alice 2.2, Second Edition

Page 27: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 27

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Adding objects to an Alice world (cont’d.) –  Explore the galleries before preparing to add objects

to your new world •  Click the folder icon on the gallery navigation bar to

move up one level in the tree of galleries •  Click the Local Gallery icon to go back to the Local

Gallery •  Find and click the Animals folder icon to open the folder

Page 28: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 28

Page 29: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 29

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Object classes and instances in Alice –  Class

•  Group of objects with the same properties and the same methods

–  Objects in the same class •  Virtually identical to each other •  Values stored in some properties may be different

–  Instance of the object •  Each copy of an object from a particular class

Page 30: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 30

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Object classes and instances in Alice (cont’d.) –  To instantiate a Bunny class object

•  Click the Class Bunny icon •  Click the Add instance to world button to put a bunny

into the world •  Add an object to an Alice world by clicking an object

class tile and dragging it into place in the World window •  You should now have an Alice world with two objects -

a bunny and a chicken

Page 31: Alice ppt ch01

31 An Introduction to Programming Using Alice 2.2, Second Edition

Page 32: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 32

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Positioning objects –  Layout tools can be used to manipulate objects –  Pointer tool is already selected

•  Experiment a bit by using the pointer to click the bunny and move it around the screen

–  Click the Rotate tool and try turning the bunny a few times

–  Before exiting Scene Editor mode •  Properly position the bunny in its starting position for

the new Alice world you are creating

Page 33: Alice ppt ch01

33 An Introduction to Programming Using Alice 2.2, Second Edition

Page 34: Alice ppt ch01

34 An Introduction to Programming Using Alice 2.2, Second Edition

Page 35: Alice ppt ch01

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Positioning objects (cont’d.) –  After the bunny is in position, click the large green

DONE button to close the Scene Editor •  Adding some action

–  Click the World tile in the Object tree in the upper-left corner of the interface

–  Click the methods tab in the Details area –  Click the bunny tile in the Object tree –  Make sure methods tab is selected in the Details area

•  Find and drag the bunny move tile into the middle of world.my first method

An Introduction to Programming Using Alice 2.2, Second Edition 35

Page 36: Alice ppt ch01

36 An Introduction to Programming Using Alice 2.2, Second Edition

Page 37: Alice ppt ch01

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Adding some action (cont’d.) –  Select forward for the direction, and then 1 meter for

the amount –  To test your world, click the Play button –  To change the amount the bunny moves, click the 1

meter parameter in the move tile in your new method •  Choose one of the values in the drop-down menu

An Introduction to Programming Using Alice 2.2, Second Edition 37

Page 38: Alice ppt ch01

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Adding some action (cont’d.) –  Find the bunny turn to face method tile

•  Parameter - object you want the bunny to face •  Drag the bunny turn to face tile into the Editor area •  Choose camera as the object you want the bunny to

face

An Introduction to Programming Using Alice 2.2, Second Edition 38

Page 39: Alice ppt ch01

•  Adding some action (cont’d.) –  Add two tiles to make the bunny speak, then save the

world –  Find and drag the bunny say tile into the Editor area

and drop it below your other two instructions –  When the parameter menu appears, click other, and

then type Hello, World!

An Introduction to Programming Using Alice 2.2, Second Edition 39

Tutorial 1C – Creating Your First Alice World (cont’d.)

Page 40: Alice ppt ch01

•  To add another instruction and save your world: –  Add another bunny say tile to make the bunny say “Hello, Dr. Kernighan!”

–  Play your world again –  To save the world you created

•  Click the File menu and then click Save World –  Decide where you want to save the world –  Type the name hello world, with no punctuation, in

the File name box

An Introduction to Programming Using Alice 2.2, Second Edition 40

Tutorial 1C – Creating Your First Alice World (cont’d.)

Page 41: Alice ppt ch01

41 An Introduction to Programming Using Alice 2.2, Second Edition

Page 42: Alice ppt ch01

Tutorial 1C – Creating Your First Alice World (cont’d.)

•  Closing and reloading a saved world –  Click File on the menu bar, and then click Exit –  Reopen the Alice software –  Click the Recent Worlds tab in the Welcome to Alice!

dialog box –  Open the hello world world that you created

An Introduction to Programming Using Alice 2.2, Second Edition 42

Page 43: Alice ppt ch01

Tutorial 1D – Printing Code From an Alice World

•  Click File on the menu bar –  Use Export Code For Printing

•  Notice that you need to tell the computer what to print –  Make sure that the boxes in front of both items are

checked •  Tell Alice where you want to save the HTML file •  Add your name as the author of the code •  Click the Export Code button to create the new

HTML document

An Introduction to Programming Using Alice 2.2, Second Edition 43

Page 44: Alice ppt ch01

44 An Introduction to Programming Using Alice 2.2, Second Edition

Page 45: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 45

Tutorial 1E – Saving an Alice World as a Movie File

•  Start Alice, and open the hello world Alice world that you created in Tutorial 1C

•  Click the Play button •  Click the Restart button if you wish to view the world

again •  Click File on the Menu bar

–  Then click the Export Video option •  Click the Save button to save the world

Page 46: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 46

Tutorial 1E – Saving an Alice World as a Movie File (cont’d.)

•  Type the name of your movie file in the File name box

•  Click the Record button to start recording –  Click the Stop Recording button to finish recording

•  Export the recorded video to a file •  Click the Stop button to close the window

–  Close the Alice software

Page 47: Alice ppt ch01

47 An Introduction to Programming Using Alice 2.2, Second Edition

Page 48: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 48

Summary •  Algorithm

–  Step-by-step process •  Computer programs are algorithms •  Most modern computer programming languages are

object-oriented languages •  Object

–  Collection of properties and methods that can be used to manipulate those properties

Page 49: Alice ppt ch01

An Introduction to Programming Using Alice 2.2, Second Edition 49

Summary (cont’d.)

•  State of the object –  Values stored in the properties of the object at any

given time •  Class of objects

–  Collection of all objects that have the same properties and methods

•  Instance of that class –  Each individual object in a class

Page 50: Alice ppt ch01

Summary (cont’d.)

•  Alice uses an object-oriented style of programming •  Alice makes it easier to learn programming because:

–  It requires minimal memorization of syntax and it provides visualization and rapid feedback

An Introduction to Programming Using Alice 2.2, Second Edition 50