An Introduction To Programming Using Alice 22 2nd Edition Charles W Herbert Instant Download
An Introduction To Programming Using Alice 22 2nd Edition Charles W Herbert Instant Download
https://ebookbell.com/product/an-introduction-to-programming-
using-alice-22-2nd-edition-charles-w-herbert-1920286
https://ebookbell.com/product/an-introduction-to-programming-using-
python-schneider-david-i-21354512
https://ebookbell.com/product/an-introduction-to-programming-using-
visual-basic-2008-with-visual-studio-expression-edition-dvd-7th-ed-
schneider-22041544
https://ebookbell.com/product/an-introduction-to-programming-using-
visual-basic-2012-9th-edition-david-i-schneider-4332796
https://ebookbell.com/product/an-introduction-to-programming-using-
visual-basic-2005-6th-ed-david-i-schneider-930012
An Introduction To Programming Using Visual Basic 2012 Schneider Di
https://ebookbell.com/product/an-introduction-to-programming-using-
visual-basic-2012-schneider-di-5498324
https://ebookbell.com/product/mathematical-computing-an-introduction-
to-programming-using-maple-softcover-reprint-of-the-original-1st-
ed-2002-betounes-55199802
https://ebookbell.com/product/instructor-solutions-manual-for-an-
introduction-to-programming-using-python-david-i-schneider-7012768
https://ebookbell.com/product/new-programmers-start-here-an-
introduction-to-computer-programming-using-javascript-
bartlett-55919162
https://ebookbell.com/product/how-to-design-programs-an-introduction-
to-computing-and-programming-using-scheme-free-web-version-
felleisen-m-874218
An Introduction
to Programming
Using Alice 2.2
Second Edition
pi
ii ' H i '
Charles W. Herbert
m to Programming Using A
« COURSE TECHNOLOGY
ond Edition Herbert «• C t N i j A G E Learning"
Leilehua Maly graduated from the University of Hawaii
at Hilo in 2003 with a B.S. in Computer Science. After
graduation, he moved to Seattle to work as a software
engineer at Amazon.com. Leilehua is currently
employed as a software engineer in the Windows
Mobile and Embedded division of Microsoft.
J
You knew you were headed for a career in Computer Science when...
I realized how much fun it was to make a computer do what I want.
AN INTRODUCTION
PROGRAMMING
2.2
S E C O N D EDITION
by Charles W. Herbert
; COURSE TECHNOLOGY
t% CENGAGE Learning-
Purchase any of our products at your local college store or at our preferred
online store www.cengagebrain.com
Some of the product names and company names used in this Course Technology, a part of Cengage Learning, reserves the
book have been used for identification purposes only and may right t o revise this publication and make changes f r o m t i m e t o
be trademarks or registered trademarks o f their respective t i m e in its c o n t e n t w i t h o u t notice.
manufacturers and sellers.
The programs in this book are for instructional purposes only.
Any fictional data related t o persons or companies or URLs used
throughout this book is intended for instructional purposes only. They have been tested w i t h care, but are not guaranteed for any
At the time this book was printed, any such data was fictional particular intent beyond educational purposes. The author and
and not belonging t o any real persons or companies. the publisher do not offer any warranties or representations, nor
do they accept any liabilities w i t h respect t o the programs.
CHAPTER T W O
Methods 31
CHAPTER THREE
Events 63
CHAPTER FOUR
Algorithms 97
C H A P T E R FIVE
C H A P T E R SIX
CHAPTER SEVEN
C H A P T E R EIGHT
C H A P T E R NINE
CHAPTER TEN
APPENDIX A
APPENDIX B
APPENDIX C
GLOSSARY 321
INDEX 327
Table of Contents
PREFACE ix
FOREWORD TO THE FIRST EDITION xv
CHAPTER ONE
A n Introduction t o Alice a n d O b j e c t - O r i e n t e d P r o g r a m m i n g 1
Object-Oriented Programming and Alice 2
Tutorial 1A—Exploring the Alice Interface 4
The Main Work Areas of the Alice Interface 7
Other Elements of the Alice Interface 9
Menus 9
Tutorial 1 B — P l a y i n g an Alice World 10
Tutorial 1 C — C r e a t i n g Your First Alice World 12
Adding Objects to an Alice World 14
Object Classes and Instances in Alice 15
Positioning Objects 17
Adding Some Action 18
Closing and Reloading a Saved World 22
Tutorial 1 D — P r i n t i n g Code from an Alice World 22
Tutorial 1 E — S a v i n g an Alice World as a Movie File 23
Chapter Summary 26
Review Questions 26
Exercises 27
CHAPTER TWO
Methods 31
Top-Down Design and Modular Development 32
The Software Development Cycle 36
Designing Methods 36
Coding Methods in Alice 37
Testing and Debugging Alice Methods 37
Tutorial 2 A — W o r k i n g with Primitive Methods in Alice 39
Running Primitive Methods Directly 41
Using Primitive Camera Methods to Find a Lost Object 43
Tutorial 2 B — C r e a t i n g New Methods in Alice 45
Setting the Scene 46
Designing a Method 49
Coding the J u m p Methods 50
Creating the Main Method 52
Testing (and Debugging) Your Finished Software 53
Tutorial 2 C — M e t h o d s With Parameters 54
Creating a Parameter 55
Using a Parameter 56
Chapter Summary 58
Review Questions 59
Exercises 59
Table of Contents V
CHAPTER THREE
Events 63
Event-Driven Software 64
Three-Dimensional Space 65
Tutorial 3 A — E v e n t s in Alice 70
Exploring Events 70
Creating a Sample World for Event Exploration 71
Alice Event Types 74
The When a Key is Typed Event 76
The While a Key Is Pressed Event 78
The When the Mouse Is Clicked on Anything Event 78
Additional Notes About Mouse Events 79
Tutorial 3 B — B u i l d i n g Camera Controls with Events 80
Open an Existing World 80
The Let the Mouse Orient the Camera Event 82
The Let the Mouse Move the Camera Event 82
The Let the Arrow Keys Move the Camera Event 83
Tutorial 3 C — B u i l d i n g a Flying Machine in Alice 84
Software Specifications 84
Refining Specifications 84
Code the World—Specification 1 , Create a World with a Seaplane 87
Code the World—Specification 2, Animate the Seaplane 89
Code the World—Specification 3, Add Turn Controls 89
Code the World—Specification 4 , Add a Find Control 90
Test the World 90
Debug the World 91
Chapter Summary 92
Review Questions 93
Exercises 94
CHAPTER FOUR
Algorithms 97
Elements of Logical Structure 98
Flowcharts 99
Flowcharting Template 100
Flowchart Symbols 100
Linear Sequences 101
Selection S e q u e n c e s — B r a n c h i n g Routines 103
Binary and Multiple Branching 103
Binary Branching 104
Pseudocode 104
Repetition S e q u e n c e s — L o o p i n g 105
Pretest and Posttest Loops 106
Count-Controlled and Sentinel Loops 108
Parallel Algorithms 110
Tutorial 4 A — B r a n c h i n g in Alice Methods 110
User Functions in Alice 111
Tutorial 4 B — A Simple Count-Controlled Loop 116
Tutorial 4 C — U s i n g the While Instruction 118
VI An Introduction to Programming Using Alice 2.2
CHAPTER EIGHT
Lists a n d A r r a y s in Alice 213
Data Structures in Alice 214
The Need for Different Data Structures 214
Lists in Alice 217
Arrays in Alice 219
Tutorial 8 A — E i g h t Ballerinas 220
Exploring the Ballerina Movement Methods 221
Creating a List of the Ballerinas 222
Creating a Dance Routine for the Ballerinas 224
Tutorial 8 B — M a r c h i n g Toy Soldiers 227
The Toy Soldiers World 227
Creating a Marching Routine 229
Tutorial 8 C — S a l u t i n g Toy Soldiers 232
Creating a Generic Salute Method 232
Making All of the Soldiers Salute 237
Tutorial 8 D — S o r t i n g an Array of Sixteen Ballerinas 238
Chapter Summary 241
Review Questions 242
Exercises 243
CHAPTER NINE
M a k i n g A n i m a t e d M o v i e s with Alice 245
Introduction 246
The Moviemaking Process 247
Tutorial 9 A — R e c o r d i n g a Movie from Alice 248
Preproduction 250
Movie Types 252
Movie Topics 253
Outlining the Plot: Scenes, Shots, and Storyboarding 254
Tutorial 9 B — S t o r y b o a r d i n g 257
Camera Placement And Shot Transitions 258
Tutorial 9 C — S i m u l a t i n g Multiple Cameras 259
Tutorial 9 D — R e c o r d i n g Camera Positions for a Multi-Shot Scene 261
Postproduction 266
Chapter Summary 267
Review Questions 268
Exercises 269
CHAPTER TEN
Video G a m e Programming 271
What Is a Video Game? 272
Video Game Careers 274
Game Development Project Management 274
Game Design 275
Script Writing 275
Graphics Arts 275
Music and Sound Engineering 276
Programming 276
Quality Assurance 277
viii An Introduction to Programming Using Alice 2.2
Three things have been changed in this new edition of the text:
Alice 2.2
The second edition of this book is based on Alice 2.2 because this is the best current version
of Alice for learning introductory programming for most students. Some of the features that
did not work well, or at all, in Alice 2.0 now work in Alice 2.2, such as the ability to export
movie files. Alice 3.0 is still not yet ready for prime time, and when it is it may not be the
best vehicle for a general introduction to programming. It is significantly more complicated
and more difficult to use than Alice 2.2. Alice 3.0 will probably be a better vehicle for a
course in which students wish to develop more sophisticated programming skills, or for stu-
dents who wish to dive deeper into things like the nature of events or human computer inter-
action in second-level Java courses. Because it is not as easy to use as Alice 2.0 or Alice 2.2,
Alice 3.0 could be a barrier to getting started with programming for many students.
Therefore, this book, which is intended to introduce students to the nature of computer pro-
gramming, is based on Alice 2.2.
New Chapters
The two new chapters on making animated movies and video game programming aren't
included to displace any of the previous chapters, but rather to extend them. The chapters
should provide students with a good foundation in each area. The animated movie chapter
teaches students about things like camera angles, fades, and transitions so that they can use
An Introduction to Programming Using Alice 2.2
these in programming virtual worlds or in making movies. The video game chapter discusses
careers in the video game industry and exposes students to the kinds of programming needed
for video games.
These chapters aren't intended for courses in filmmaking or game development, but to intro-
duce these areas to students learning programming because these are things that many mod-
ern professional programmers need to learn. Moviemaking and gaming are also areas of
interest to most students, which could spark an interest in computer programming and
related math and physics.
Many years ago, Galileo and others explored the most fundamental concepts in the universe—
optics, heat, mechanics, and so on—as a foundation for understanding and developing the
newest technologies of the day. And so it is with modern computer science. The more we
understand things that don't change, the more we can explore and affect things that do
change. Conversely, the more we wish to know about today's newest and hottest technologies,
the more we find ourselves learning about the immutable foundations of the universe in
which we live. Today's emerging technologies that motivate people to learn include personal
moviemaking and interactive gaming. It may seem like they have been around forever, but
moviemaking and video gaming are relatively new topics that are becoming increasingly
important for computer programmers, are motivating for students, and are just beginning to
appear in most introductory computer programming courses.
R e v i s i o n in E x i s t i n g C h a p t e r s
The chapters that were in the first edition have been revised for this new edition in response
to feedback from instructors and students. More images are included, the language of the text
has been clarified in places, and some of the examples and exercises have been changed. The
fundamental goals and approach of the text remain the same.
O r g a n i z a t i o n o f t h e Text
Each lesson in this text is composed of two parts—lecture and lab. The lecture part of the les-
son includes reading material for the student and lecture material for the teacher that
parallels the reading material. For the most part, the reading material is relatively brief and is
intended to establish a foundation for the lab component. The new chapter on video game
development contains a bit more reading material than most chapters, providing students
with an overview of video game development careers and the kinds of programming used in
video games.
The lab component includes hands-on tutorials in Alice, and sometimes related work intended
to help them explore the concepts of the lesson. The lab component consists of one or more
hands-on step-by-step tutorials, followed by review questions and open-ended exercises the
students should be able to complete on their own, either individually, or in groups, once they
Preface
understand the step-by-step exercises. The exercises contain notes directing the students'
attention to what they should be learning as they carry out the exercise. It is not enough to com-
plete the steps in the exercise, each student should understand what was done, why it was
done, and should be able to repeat the exercise without the directions.
This edition of the book is organized in ten chapters, with goals as follows:
The notion of objects is introduced in the first chapter. Understanding the nature of an object
as a collection of properties and methods that can manipulate those properties is critical in
modern computer programming. The text mentions but does not explore more sophisticated
concepts of object-oriented programming, such as inheritance and polymorphism. In that
sense, like Alice, it is not truly object-oriented, but might better be described as object-based.
I have found that attempts to introduce students to a complete understanding of objects upon
their first exposure to programming is counterproductive. Students can learn more about
inheritance and polymorphism after they have some experience with objects and program-
ming. This approach actually enables students to develop a better grasp of important funda-
mental concepts, like Boolean logic and the nature of algorithms, and to more deeply explore
in a second course how inheritance—with public, private, and protected properties, sub-
classes, super-classes, and so on—really works.
Chapters 7 and 8 present topics that are not covered by everyone in an introductory pro-
gramming course. They are intended to provide students with a first exposure to recursion
and to data structures. Some preliminary work with developmental math and English stu-
dents has shown that the chapters work in making this material accessible to them.
Lesson plans, course outlines, and additional instructional materials for all three approaches,
as well as a complete proposal for a course based on Alice, can be found on the Web site for
the text.
Acknowledgements
May people are responsible for the production of this book, and I am grateful to them all.
Mary Pat Shaffer was the Development Editor, who worked most closely with me in creating
the book's second edition. I appreciate her hard work, and thank her for her patience and
guidance in working with me. This is a much better book because of her efforts.
The book's copy editor was Harold Johnson. Copy editors are the unsung heroes of the pub-
lishing world; guardians of language and thought who painstakingly sift through material
with a fresh eye, finding things that others miss. Chris Scriver and Serge Palladino served as
quality assurance testers, checking each of the tutorials and exercises in the manuscript to
make sure that the final text, the student data files, and the solutions for instructors are cor-
rect. Course Technology stands out among publishers in part because of their attention to
such details.
I am grateful to Alyssa Pratt, Senior Product Manager and Amy Jollymore, Acquisitions
Editor for Computer Science & Programming, two key people at Course Technology who
helped make this edition of the book possible. Thanks also to Melissa Panagos, Content
Product Manager, who guided this book through the production process, and to Marissa
Falco, Art Director, who led the efforts to create the new cover and update the interior design
for this edition.
The original manuscript for the second edition of this book was reviewed by:
I am grateful for their time and the influential insights they offered. Many improvements
were made because of their efforts.
I'd like to thank Walt Johnson, one of my colleagues at Community College of Philadelphia,
who provided the IBM flowchart template shown in chapter 4. Walt is retired now, but for
years I had the opportunity to teach with him and learn much about programming from him.
Early in his career, Walt worked with some now-primitive IBM equipment, like the 1401 and
360 series, and became a master at improvising and inventing new techniques to get a pro-
gramming job done. Many things change rapidly in the world of computing, but one thing that
will never change is the need for people like Walt, filled with intelligence, enthusiasm, and
the ability to work well with computers and with the people who use them.
This book is dedicated to my father, George William Herbert, Jr., who passed away during the
week when the first edition of the book went to press. He was the athletic director for the
Maplewood School District in Colonie, NY for more than 30 years, but spent most of his sum-
mers driving our family around the country to visit as many of America's national parks as
possible. There are many heroes in the world, but few as important as a good father.
The Alice software can be found at www.Alice.org, the official Alice Web site.
Each chapter of this book has clearly stated objectives, one or more readings related to those
objectives, and several hands-on tutorials. A chapter summary, review questions, and further
exercises are included at the end of each chapter. Note that Appendix A of this text contains
technical information about the Alice software, which is easy to install and use.
Note that the text was quality assurance tested using Alice v. 2.2 on Windows 7 Ultimate.
Student Data Files These are provided on the Course Technology Web site at www.cengage.com/
coursetechnology. The student data files contain all of the Alice worlds, image files, and so on
that are needed within the tutorials.
Solution Files Solutions to the review questions and exercises found in the book are
provided for instructors on the text's Companion Site at www.cengage.com/coursetechnology.
The solutions are password protected. The solution files contain the completed Alice worlds
that are the final product of each tutorial.
Foreword to the First Edition
Note from the author: I asked Randy Pausch, Dennis Cosgrove, and Caitlin Kelleher to tell us
about the development of Alice, the current state of affairs regarding Alice, and where things
seem to be headed in the future. The sections that follow are what they wrote in reply. We've
also included their individual bios at the end of this foreword.
All A b o u t A l i c e
So far there have been three distinct phases in the development of Alice, the Goggles and
Gloves phase, the "rapid prototyping 3D graphics phase," and the Teaching Introductory
Programming phase.
The Goggles and Gloves phase started in the early 1990's at the University of Virginia, where
Randy was on the faculty, heading a 20-person User Interface Group investigating the bound-
ary where people and technology interact. We were trying to make virtual reality more acces-
sible by developing improved interfaces and lower-cost human computer interaction
hardware and software. The paper Virtual Reality on Five Dollars a Day, which was pub-
lished in the April 1991 edition of the ACM SIGCHI's journal Human Factors in Computing
Systems, describes some of our work. It's available online through www.alice.org, where we
provide links to publications related to our work on Alice.
We call that first phase the Goggles and Gloves phase because we really were focusing on the
development of virtual reality systems in which the participant (the term user really doesn't
seem to capture the sense of it; Disney Imagineering uses the term "guest") enters a virtual
world by putting on a VR helmet and gloves. One mantra was "If it doesn't have a glove, it's
not VR." At the time, virtual reality was in its infancy. So, in addition to developing VR inter-
faces, we were working on software systems to test the interfaces. One of our early reseach
projects was SUIT, the Simple User Interface Toolkit, to which Matt Conway and Rob DeLine
contributed heavily. Matt was instrumental in recognizing that vocabulary matters—that the
choice of names for behaviors is critically important in a system for novices. His work was
very influential in shaping the direction of the development work that led to the Alice sys-
tem we have today. His doctoral dissertation, Alice: Easy-to-Learn 3D Scripting for Novices
should be required reading for people interested in how to design systems for novices. It's
available on the Web at www.alice.org.
The language for programming VR systems required one to think in terms of X,Y,Z coordi-
nates, and to use terms like translate, scale, and rotate to describe things happening in a vir-
tual world. On the early Silicon Graphics machines, angles were measured in integers
representing tenths of a degree, so commands like rotate -3600 were common. A person
needed fairly advanced mathematics skills to program graphical objects in a 3D system.
An Introduction to Programming Using Alice 2.2
Engineers and physicists had the keys to get in, but many other intelligent, talented and cre-
ative people, such as artists, and filmmakers, did not. Matt saw that the language of VR was
a part of the problem and that if we could change the language, then VR systems would be
easier to use, and thus more accessible for novices and more powerful for experts at the same
time. In his dissertation he wrote that "the tradeoff between power and simplicity is often a
false one." He led us in discovering that using more everyday terms terms like move, turn,
and resize instead of technically-oriented terms like translate, rotate, and scale could go a
long way toward achieving the powerful simplicity that would become one of the hallmarks
of Alice. Turn left 1 revolution makes sense to a lot more people than rotate X -3600.
The first version of Alice emerged as an easy-to-use scripting system for building virtual
worlds. The system itself was a combination of C and Python code, with which one could
rapidly create virtual worlds by iterating Python scripts. Over the years, the programming
features of Python have been replaced with dragging and dropping code elements.
It's important to note that even early versions of Alice could not have been created without
the efforts of a dedicated team of people. In particular, PhD student Rich Gossweiler, was
responsible for the implementation of the very early versions of Alice, and its co-system
DIVER. Tommy Burnette was also responsible for a great deal of the early Alice software
implementation. A complete listing of people who have contributed to the Alice project over
the years is available at www.alice.org .
At about this time (the mid 1990's) our work was funded by a variety of sources, including
the National Science Foundation (NSF) and the Defense Advanced Research Projects Agency
(DARPA). These are two of the most amazing agencies in the federal government, when it
comes to return on investment of public money. A while back, NSF and DARPA asked for
funding to explore using computers as tools for communication among educators, scientists,
and engineers, and the result is the Internet. We believe that any time they ask for money,
Congress should jump at the chance to spend public funds so wisely. One day one of the peo-
ple from the Department of Defense who was overseeing our project said that we should for-
get about the virtual reality hardware and concentrate on the software we were building. He
argued that our most important contribution was the way in which our software could be
used as a rapid development system for 3D graphics prototyping.
During the summer and fall of 1995, Randy spent a sabbatical at Walt Disney Imagineering's
Virtual Reality Studio working on the "Aladdin" project which was featured at EPCOT
Center and, later, at DisneyQuest. The experience working with the Imagineering team
helped to make it clear that we were moving into a realm of work that would require both
artists and engineers. In the spirit of bringing artists and engineers together, Randy created a
course called "Building Virtual Worlds" in which teams of artists and engineers work together
Foreword to the First Edition xvii
to create interactive virtual worlds. In the Spring of 1997, the research group moved to
Carnegie Mellon University, in order to take advantage of the fairly unique cross-disciplinary
focus at CMU. However, no story of the Alice system would be complete without acknowl-
edging how gracious the University of Virginia was in allowing us to continue work on Alice
seamlessly, by allowing us to transfer our funding and research to another university, and we
are very grateful for their support. We have fond memories of the University of Virginia and
highly recommend it to students looking for a great place to go to school.
Over the next few years we gradually moved into the third phase of our work as we devel-
oped better ways to build virtual worlds. Alice became a workhorse for the "Building Virtual
Worlds" course, which was then being taught at Carnegie Mellon, for several years, finally
realizing our dream of allowing "a 1,000 creative flowers to bloom." However, with respect to
making 3D graphics programming easier, we slowly began to realize that we had the problem
inside-out. Instead of thinking about how to improve programming to make 3D graphics
more accesible, it started to become clear that 3D graphics could make programming more
accesible. A seminal event occured one day when Randy was on a family trip to
DisneyWorld. His ten year old nephew Christopher spent the day working with Alice on a
laptop as they drove. Chris programmed 3D graphics for eight hours straight, never really
having trouble with the 3D part, but constantly asking for help about "where the commas and
semicolons had to go." In Randy's words: "I immediately realized that this was a problem we
could solve." Some work had already been done on the drop and drag interface, but now the
creation of a drag and drop interface for creating Alice programs became a priority.
Wanda Dann and Steve Cooper both became important contributors to the future of Alice at
about this time. Wanda, who teaches Computer Science at Ithaca College, and Steve, who
teaches at St. Joseph's University, have long been interested in how visualization can be used to
teach object-oriented programming concepts. They began to work with us to shape Alice as a
better tool to teach introductory programming. We were all beginning to recognize that Alice
works well for teaching introductory programming for three primary reasons: minimization of
the problems of syntax, the ability to see the results of object-oriented programming in a live
virtual world, and the motivation provided by working in such an exciting environment.
Since 1999 Steve and Wanda's efforts developing educational materials based on Alice, test-
ing Alice in the classroom, and providing feedback to Dennis and company as the software
was refined have been instrumental in shaping the current look and feel of Alice.
In addition to helping students with the technical hurdles, Alice is allowing us to begin
changing the ways in which we introduce students to computer programming. The way we
teach computer programming hasn't changed much in the past 50 years, despite the fact
that the way we use computers has. The first computers that appeared in the middle of the
20 th
century were literally used to help bombs hit their targets. The early high-level pro-
gramming language, FORTRAN, was designed to help scientists and engineers with their
An Introduction to Programming Using Alice 2.2
number crunching. Today, how many high school students are excited about writing code
to generate the first 10 Fibonacci numbers? Using Alice, students learn the basics of pro-
gramming while creating animated stories and games. Wanda Dann has been a strong pro-
ponent for using Alice to introduce programming through storytelling at the college-level,
and Caitlin has been studying using the activity of storytelling in Alice to interest middle-
school girls in learning to program. In addition to being more motivating than assignments
like sorting a list of numbers, creating animated stories helps to make computer program-
ming seem less foreign. Not many people are familiar with the concept of mathematical
algorithms, but everyone is familiar with storytelling. By using Alice to tell story in a vir-
tual world, young people become engaged in linear sequencing, modular development,
and planning before implementation—three of the most important skills for early success
in computer programming.
One highly desirable side effect of using Alice to introduce programming through story-
telling is that more young women are attracted to the discipline. It's no secret that Computer
Science, unlike Law and Medicine, has failed to attract women in significant numbers.
Currently, women constitute less than one-third of all Computer Science majors in the US,
and less than one-fourth of those earning Ph.Ds in Computer Science. According to Caitlin s
research (her dissertation, when completed, will be available at www.alice.org), Alice has the
power to begin to change that; thereby changing the culture of the Computer Science class-
room and workplace.
So where do things stand now? Well, Chuck Herbert's programming textbook is only the second
book to use Alice as a tool to teach programming. The Dann, Cooper and Pausch book was the
first. Course Technology's Alice CourseCard is the first widely available reference material for
Alice 2.0. More material is sure to follow as the number and type of schools using Alice
increases. Last year we knew of approximately 30 colleges and universities using Alice. This
year we are aware of about 60 colleges and universities and at least that many high schools, as
well—and there are probably more folks using Alice that we don't know about.
Currently most people who use Alice seem to be doing so to teach introductory program-
ming, although it is starting to be used in other disciplines. The most widespread educa-
tional model for the use of Alice is to use Alice for the first half of an introductory
programming course, followed by the use of Java or a similar commercial programming
language in the second half of the semester. That model seems to be working remarkably
well in places like Duke University, the University of Mississippi, Haverford College, and
here at Carnegie Mellon.
Foreword to the First Edition xix
Within the past three years other models for the use of Alice have emerged, particularly in
the community colleges, and in courses other than computer programming. Here are just a
few of the efforts we know about:
The most common question people ask us these days is about the future of Alice. Right now,
the 04/05/2005 Version of Alice 2.0 is reasonably stable and reliable, and runs on Windows and
the Macintosh. There are no plans develop it further. Instead, work is beginning on Alice 3.0.
How will Alice 3.0 be different? Well, to start with, one thing about it will be the s a m e —
it will continue to be provided free of charge to the public from Carnegie Mellon University.
The University has been very gracious in supporting us, and we are committed to maintain-
ing Alice as an open source, non-commercial, piece of software. This "purity" is important;
many students have worked hard over the years to contribute to the Alice effort, and we
believe it must continue to be "for the people." All of Randy Pausch's royalties from the
Dann, Cooper and Pausch book are donated by him to Carnegie Mellon, to help support the
software development. We are glad to hear that Chuck Herbert has also pledged a portion of
his royalties from this book to the Alice effort. We had various corporate sponsors over the
years, most notably Intel and Microsoft, and we are pleased to say that Electronic Arts (EA) is
a major sponsor of Alice version 3.0.
xx An Introduction to Programming Using Alice 2.2
We expect that Alice 3.0 will be a pure Java implementation, and that you will be able to dump
the Java code for an Alice 3.0 world and then work with it in Java. That's a big change from
Alice 2.0, which does not create Java code, but works more like an interpreter that directly exe-
cutes Alice methods. This should serve several purposes, including helping to make the transi-
tion form Alice to Java smoother in introductory programming courses.
You can expect the new version of Alice to be more truly object-oriented than the current
version. Alice 2.0 is a good tool to introduce the concept of an object as a collection of prop-
erties and methods, but it does not provide the ability to create true class-level methods, true
inheritance, or the overriding necessary for polymorphism. Alice 3.0 should have some, if
not all, of these features.
Caitlin's work has shown that users, especially young people, can do more and learn more
with objects that have higher order primitive methods, such as walk, sit, and touch instead of
just move, turn, and so on. There will probably be more methods that manipulate objects and
their sub-parts together, and the gallery of available objects will probably be richer that the
current Alice gallery.
The overall look and feel of Alice will also probably be less toy-like. Anyone who has used Alice
for more than a few minutes knows it's not a toy, but it looks like a toy. The new version should
still be easy to use, but people probably won't think "Fisher Price" when they first see it.
The team that started working on virtual reality interfaces years ago at the University of
Virginia had no idea that our work would lead to Alice and that it would become such an
important tool in Computer Science education. As is the case with many NSF funded projects,
the taxpayers have gotten more than their money's worth, but just not in the way one would
have thought reading the original proposals. Such is the path of science and exploration. Now
that we know where we are headed, our goal is to make Alice the vehicle of choice for some-
one's first exposure to computer programming, for everyone—worldwide—from 5 th
grade
through college.
Randy Pausch
Dennis Cosgrove
Caitlin Kelleher
Carnegie Melon University,
December 2005
Foreword to the First Edition
Dennis Cosgrove is a Human Computer Interaction Project Scientist (formerly Senior Research
programmer) at Carnegie Mellon University, where he has spent the last several years as the pri-
mary software architect and implementer for Alice 2.0, 2.2, and 3.0. He was one of the principal
developers of the earlier PC/Windows 95 Alice implementation at the University of Virginia.
In addition to his work on Alice, he has contributed to the development of an eye-tracking sys-
tem that allows quadriplegics to interact with a computer.
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
Create a new Alice world by adding objects to a blank world, positioning them, and
using simple methods to animate those objects
An object can be something in the physical world or just an abstract idea. An airplane, for
example, is a physical object that can be manipulated by an autopilot—a computer that can
fly the plane. To the computer, the airplane is an object.
Most objects that computers manipulate are not physical objects. A bank transaction is an
example of an object that is not physical. There is usually a paper record of a transaction;
however, the transaction itself is simply a concept. It is an object, but not a physical object.
Whether an object exists in the physical world doesn't matter much in terms of what hap-
pens inside a computer. To a computer, an object is simply something that can be repre-
sented by data in the computer's memory and manipulated by computer programs. The data
that represents the object is organized into a set of properties. Each property describes the
object in some way. For example, the weight of an airplane, its location, the direction in
which it is facing, and so on are all properties of the airplane. A computer manipulates an
object by changing some of its properties or some of the properties of parts of the object. For
instance, the autopilot might change the angle of a wing flap, which in turn affects the
entire airplane.
Sometimes the hardware in a computer translates these changes in properties into actions
that affect the physical world—as an airplane's autopilot does—and sometimes the changes
in an object only affect information in the computer's memory and have no direct effect on
the physical world. For example, when a bank deposit is recorded on a computer, the
amount of money in the bank balance property of the bank account object is changed, but
there is no other immediate effect on the physical world.
The programs that manipulate the properties of an object are called the object's methods.
An object is a collection of properties along with the methods that are used to manipulate
those properties. The values stored in the properties of an object at any given time are col-
lectively called the state of an object. This modern approach to computer programming is
known as object-oriented programming, or OOP for short.
Object-Oriented Programming and Alice 3
Learning to program a computer is often a difficult task because it requires learning about
programming concepts and the language of programming at the same time. It's also difficult
because people find it hard to visualize all of the changes that are occurring as a computer
program runs. Alice can make it easier to learn to program a computer by helping with both
of these problems.
Alice uses an object-oriented style of programming. The objects in Alice exist in a three-
dimensional virtual world, much like a modern video game. In fact, the virtual world itself
is an object in Alice—it has properties and methods that can be used to manipulate those
properties. Alice is similar to other modern object-oriented programming languages, such as
Java, C++, or Visual Basic. However, as you will see, Alice is constructed so that you don't
need to memorize the grammar and syntax of the language to write computer programs. As
you are learning Alice, you can concentrate on learning about the ideas of computer pro-
gramming, such as the logic of your algorithms, instead of having to worry about the
spelling and grammar of a new language at the same time.
The virtual world of Alice is one that you can see. Like the real world, it has three-dimensional
space (and time), and each object has properties just like physical objects have properties;
these include color, size, position, the direction in which the object is facing, and so on. Alice
has a camera that allows you to see its virtual world on a computer screen, just as you might
view a movie or a video game. This ability to see what happens to objects in your virtual world
makes it easier to learn computer programming with Alice than with almost any other system
of programming. For instance, if you try to program a white rabbit to run around in a circle,
and instead he simply stays in one spot and spins, you can see that happening on the screen.
You can get instant feedback from viewing the way Alice runs the programs you have created.
Not every programming system is so easy to use.
For more information on computer programming languages, see Appendix C of this book.
Chapter 1 • An Introduction to Alice and Object-Oriented Programming
In summary, there are three things about Alice that make it a more effective tool for learning
programming than almost any other system of programming:
You will also find that Alice is fun and interesting to use, which never hurts when one is
trying to learn something new.
Anyone attempting this exercise should have experience using a computer. You certainly
don't need to be an expert, but you should have some experience with things like word pro-
cessing and accessing the Internet so that you are familiar with Windows, a mouse, a key-
board, and a printer.
1. Start the Alice software. You will see the Welcome to Alice! dialog box
open in front of the Alice Integrated Development Environment (IDE), as
shown in Figure 1-1. If Alice opens without showing you the Welcome to
Alice! dialog box, click File, and then click New World to open this win-
dow. An Integrated Development Environment (IDE) is a computer pro-
gram that is used to write other computer programs. Most modern
programming languages have IDEs with everything you need to create and
run computer programs. Alice is no exception, but its IDE is simpler than
most. The Alice IDE is often called the Alice interface.
The Show this dialog at start check box appears in the lower-left corner o f the Welcome
H W I * to Alice! dialog box. It should be checked so that the Welcome to Alice! dialog box will
appear when Alice starts.
Tutorial 1 A—Exploring the Alice Menace
FIGURE 1 - 1 : The Alice interface with the Welcome to Alice! dialog box
j lit
ft"*" Alice
H Tutora
il "(Recent Wod
rls T
(empa
ltes "| Examp
e
ls ( O p a n a world
Vcfeli*! m
[ ethods f rations create new variable
myfNSt method
DoUiotdtrr ftjtotjother l*Hu> Loop wti.le Foradmorder Fo. allio.jettier Wad prmt
2. Notice that the Welcome to Alice! dialog box has five tabs: Tutorial, Recent
Worlds, Templates, Examples, and Open a world. You can return to this
dialog box at any time while using Alice by clicking File on the menu bar,
and then clicking New World or Open World. Let's look at each of these
tabs before continuing.
3. Click the Tutorial tab and you will see four Alice tutorials. You won't use
the tutorials now, but you may want to come back to them later as an exer-
cise on your own. When you are ready to use the tutorials, either click the
tutorial you would like to run, or click the large Start the Tutorial button to
follow them in order. They are quite easy to follow.
Dr. Caitlin Kelleher from Washington University in St. Louis created the original version
of these tutorials while she was a graduate student at Carnegie Mellon University.
4 . Click the Recent Worlds tab. You will see thumbnail sketches of the most
recently saved Alice worlds. If no worlds have been saved since the Alice
software was installed on your system, this tab will say No recent worlds.
6 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
5. Click the Templates tab. Alice comes with six blank templates for starting a
new virtual world—dirt, grass, sand, snow, space, and water. Each of the
templates includes a texture for the surface, which is called the ground in
Alice, and a background color for the sky.
6. Click the Examples tab. Several example worlds created by the Alice devel-
opers are provided with the Alice software. We'll return to the Examples
tab later in this tutorial.
7. Click the Open a world tab. This tab is used to access Alice worlds saved
on your computer. Click the Browse button to open the Open dialog box, as
shown in Figure 1-2. This dialog box is very similar to the Open File dialog
boxes seen in other programs, such as Microsoft Windows, with navigation
icons across the top, a list of folders and Alice worlds from the current
directory in the middle, and some controls to view and open files at the
bottom. Notice that the Alice world files end with the extension .a2w. This
extension indicates that the files were created with either version 2.0 or
version 2.2 of the Alice software, the two most recent versions. Alice uses a
generic interface that looks the same when using the Windows, Apple, or
UNIX operating systems. Click the Cancel button to return to the Open a
world tab when you are ready to move on.
w
Jim Watson's Worlds
Recent Ray Sweeney's Worlds folders
Walt Johnson's Worlds
airport.a2w
baseball.a2w
Desktop boat game.a2w Alice worlds
chicken is tasty.a2w
cows.a2w
My haunted house.a2w
Documents tiny dancer.a2w
toy soldiers.a2w
My
Computer controls
8. Next, you will look at the Alice interface with an Alice world open. Click
the Examples tab, click the lakeSkater thumbnail, and then click the Open
button to open the lakeSkater Alice world. It will take a few seconds for
Alice to load all of the elements of the world. The name of each element
will briefly appear in a small window in the center of the screen while this
happens. When Alice is finished loading the world, your screen should
resemble Figure 1-3.
FIGURE 1-3: The Alice interface after loading the lakeSkater world
World window
Events area
Object tree
T h e M a i n W o r k A r e a s of t h e Alice Interface
The Alice interface has five main work areas, as shown in Figure 1-3: the World window, the
Object tree, the Details area, the Editor area, and the Events area. There are also several ele-
ments across the top of the interface—a menu bar, three control buttons, a Trash can icon,
and a Clipboard icon. Let's look at each of these before playing the lakeSkater world.
The World window contains a view of the lakeSkater virtual world. The set of blue arrows
below the window controls the Alice camera, which provides you with the view in the win-
dow. Next to the arrows is a large green ADD OBJECTS button, which you will use in
Tutorial l C when you create your first Alice world.
8 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
The Object tree appears to the left of the World window. It shows the objects in the current
Alice world organized as a tree of tiles, with a tile for each object. The plus sign next to an
object shows that it has sub parts, which may be seen by clicking the plus sign. Click the plus
sign to see the parts of the IceSkater object, and then click the minus sign to hide its parts.
T h e Details A r e a
The Details area of the Alice interface is located below the Object tree. It has tabs to show
properties, methods, and functions for the currently selected Alice object. Properties con-
tain information about an object, such as its color and position in the world. Methods are
programs that manipulate an object. A function is a method that returns a value, such as the
distance between two objects.
You may select an object by clicking that object in the World window or by clicking its tile in the
Object tree. Information about the currently selected object will be displayed in the Details area.
Click the World tile in the Object tree to see the World's details in the
Details area.
Click the lake tile to see the lake's details in the Details area.
Click the IceSkater tile in the Object tree and then the properties tab in
the Details area to see the IceSkater's properties.
• Click the methods tab to see the IceSkater's methods.
Click the functions tab to see the IceSkater's functions.
T h e Editor A r e a
The largest area of the Alice interface is the Editor area, which appears to the right of the
Details area. Here, you assemble and edit methods by clicking and dragging tiles from other
parts of the interface. The bottom of the Editor area has a row of logic and control tiles that
can be used to put branching, looping, and other logical structures into the algorithms that
will make up an object's methods. Most of the time that you spend working with Alice will
be spent using the Editor area.
The Events area in Alice is above the Editor area. The Events area shows existing events
and is used to create new events. An event consists of a condition, called an event trigger,
and a method, called an event handler. Whenever the event trigger occurs, the event han-
dler is called into action. For example, you might want the sound of a splash to occur if an
ice skater falls through the ice. Falling through the ice would be the event trigger, and the
method that makes the splash sound would be the event handler.
Tutorial 1A—Exploring the Alice Interface
Some events, such as causing a method to run when a key is pressed, provide user interac-
tion for an Alice world. The flight simulator world that can be accessed through the
Examples tab is an interactive world that you might want to take a look at after finishing
this chapter. Events are very important for interactive simulations and gaming and are cov-
ered in detail in Chapter 3.
O t h e r E l e m e n t s o f t h e Alice I n t e r f a c e
In addition to the main work areas that you have just explored, the Alice interface also has
two icons, three buttons, and a menu bar near the top of the screen.
The Trash can icon and the Clipboard icon are used for editing Alice worlds.
You can delete an item in an Alice world, such as an object or instruction tile, by dragging
and dropping it in the Alice Trash can. You can also right-click an object or tile, and select
delete from the menu that appears.
You can copy any object, event, or method in the Editor area by dragging and dropping its
tile onto the Clipboard icon in the top-right corner of the interface, and then dragging it
from the Clipboard icon to a new location. You can also duplicate a method tile by right-
clicking it and selecting make copy from the menu that appears; however, this does not
work with Alice objects or events.
The Undo and Redo buttons near the top-left corner of the interface are also useful for edit-
ing an Alice world. You can undo the last change you made by clicking the Undo button.
The effects of the Undo button can be reversed by using the Redo button. Alice can remem-
ber the last several dozen changes that you made. The Ctrl+Z and Alt+U shortcut keys can
be used for Undo. The Ctrl+Y and Alt+R shortcut keys can be used for Redo. There are no short-
cut keys for cut, copy, and paste.
Menus
The Alice interface has a menu bar at the top of the screen with four menus: File, Edit,
Tools, and Help. The menus in Alice are used much less frequently than in many other
computer programs. For now, you will look at only a few of the items on these menus. All
of the features on the Alice menus are listed in Appendix B.
File M e n u The Alice File menu has commands for opening and saving Alice worlds, and
for exiting Alice. It also has several other items that you will explore later, including options
for exporting an Alice world as a Web page or as a video, and exporting code from an Alice
world for printing. You will use these options in later tutorials throughout this book.
10 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
Edit M e n u Currently the only option on the Alice Edit menu is Preferences, which is
used to change settings for the Alice software. Appendix B of this book lists and describes
these settings. The most important thing to know for now is that the Alice Edit menu is not
used to edit Alice methods in the same way that an Edit menu might be used in other soft-
ware. Instead, Alice emphasizes the use of a drag-and-drop interface, which uses the editing
icons and buttons described throughout this book.
T o o l s M e n u The Alice Tools menu contains three options: Text Output, Error Console,
and World Statistics. The Text Output option allows you to see system messages generated
as you play Alice worlds, and the Error Console can be used to look at detailed Alice error
messages. Both of these are rather sophisticated, and are not very useful for novice program-
mers. The World Statistics option allows you to see statistics, such as the number of objects
in a world, the time the world has been open, and many other useful items. Only some of
the information here will be meaningful to you until you learn more about Alice and com-
puter graphics.
H e l p M e n u The Help menu does not contain an option to look up the features of Alice as
you might expect. By not providing a way to look up features, the developers of Alice were
hoping to encourage people to learn about Alice by experimenting with it.
The Help menu does have three options: Tutorials, Example Worlds, and About Alice.
Example Worlds and Tutorials will both take you back to the Welcome to Alice! dialog box.
The About Alice option provides general information about Alice and the Alice Web site,
www.alice.org.
Mil From time to time you may encounter errors while using the Alice software. The Alice
error message box contains a button to copy the error message to the clipboard. You can then
paste the message into programs such as Word or Notepad, although they are often too sophis-
ticated for novice programers to read. You may submit bugs and suggestions about Alice
through the Alice Web site. The Alice team wants to hear from the users of Alice.
In this tutorial, you will experiment with playing an Alice world. Alice worlds fit into one
of two different categories—some Alice worlds are interactive in the way a video game is;
others are simply run and viewed like a movie. In either case, experienced Alice users refer
to "playing" an Alice world the way most software developers talk about "running" a com-
puter program.
The Alice world you will play in this tutorial is the lakeSkater world discussed in Tutorial 1 A.
It is not an interactive world; rather, it is more like watching a movie of an ice-skater's
Tutorial 1B—Playing an Alice World
performance. If you have just finished Tutorial 1A and still have the lakeSkater world open,
then continue with the steps that follow. If not, you will need to run the Alice software and
open the lakeSkater world before starting this tutorial.
1. There are three buttons near the top of the Alice interface, labeled Play,
Undo, and Redo. Undo and Redo are used for editing, as described in
Tutorial 1A. The Play button is used to play the current Alice world. When
this button is clicked, the world will play in a larger version of the World
window, with player controls at the top of the window, as shown in
Figure 1-4. Click the Play button now and watch the show unfold. Let the
world play through to the end at least once before proceeding.
2. Notice that the new window has a speed slider control and five buttons
across the top of the window in which the Alice world plays. The buttons
are labeled Pause, Play, Restart, Stop, and Take Picture.
3 . The Restart button is 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 now to restart the lakeSkater
world, and then experiment with the Pause and Play buttons.
4. The speed slider is used to change the speed of the world while it is play-
ing. Restart the world, and experiment with the speed slider control.
12 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
5. The 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 but-
ton to take a picture of the world. An Image captured and stored dialog box
will appear, showing you the full path name of the file that was saved. The
stored image file can be viewed and used as any other computer image file
can be. By default, the images are saved as JPEG files to the desktop.
Appendix B has more information on changing the settings for Alice's
screen capture feature. Click OK to close the dialog box.
6. The Stop button stops the world that is currently playing and returns you
to the standard Alice interface. Once the Stop button is pressed, you will
need to click the standard interface's Play button to replay the world. Try
this now. After you have finished experimenting, click the Stop button one
last time to return to the standard Alice interface.
Alice is a graphics-intensive program that can use a lot of a computer's memory, so you
should exit the Alice program when it is not in use. Now that you are finished with this
tutorial, you should exit the Alice program.
While you are viewing or editing an Alice world, a dialog box will appear every 15 min-
utes, warning you that you have not saved your Alice world. If this happens while you are
playing an Alice world, such as in Tutorial 1B, then it's probably safe to ignore the warn-
ing. If it happens while you are creating or editing your own Alice world, then you should
save your world.
In this tutorial, you will create, play, and save a new Alice world. You should finish
Tutorials 1A and I B before starting this tutorial. You will create an Alice world in which a
bunny will move from the right side of the screen to the center, turn to face the camera, and
then say "Hello, World!" This is an Alice equivalent of the Hello, World! program that stu-
dents traditionally write as their first program in a new programming language.
This tutorial begins with the Alice software closed. If you have an Alice world open, then
exit Alice before continuing.
Tutorial 1C—Creating Your First Alice World 13
FIGURE 1-5: The Templates tab with six templates for new Alice worlds
3. Thumbnail sketches for the six new world templates are now available—
dirt, grass, sand, snow, space, and water. The templates appear to be very
simple, but looks can be deceiving. There is actually a great deal of com-
puter programming behind a new Alice world, with a camera, ambient
light, and other elements already in place. Click the grass thumbnail, and then
click the Open button.
A new Alice world based on the grass template is now open, and you can see the standard
Alice interface that you used earlier in the chapter. Notice that the Object tree in the upper-left
part of the interface contains the four tiles that appear in every new Alice world: world,
camera, light, and ground, as shown in Figure 1-6. You can see from the way the tree is
organized that the other objects are subobjects of the world object.
world
iff camera
C n light
ground
14 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
The new world also has the default event—When t h e world s t a r t s , do world.my first
method—in the Events area, and a blank default method—world.my f i r s t method—in the
Editor area.
A d d i n g O b j e c t s t o a n Alice W o r l d
The next several steps will introduce you to the Alice object galleries and the process of
adding objects to an Alice world. Many people get carried away with creating big worlds
with many objects when they first start to use Alice. In this tutorial, you will start with a
very small Alice world with a minimum number of objects. Objects are added to an Alice
world in Scene Editor mode.
1. Click the large green ADD OBJECTS button in the bottom-right corner of
the World window to enter Alice's Scene Editor mode, which is used to
add objects and position them in an Alice world.
2. Note that the Alice interface now looks different, as shown in Figure 1-7.
The Object tree and the Details area are still visible on the left, but there is
a new area on the right side of the screen. This new area is called the
Scene Editor.
Tutorial 1C—,
tin Crea
9 Your First Alice
Web
nection
Gallery maintained
to use the Web Gallery.)
Scene Editor mode, as shown
by Carnegie
in Figure
Mellon
The Local
1-7.
VmveVSlty.
Gallery is the (N>U
visible at
The galleries are organized
IW
the bottom Ot
as a tree of folders
SCTWU
containing related ob)ects. You can navigate the tree of galleries by clicking a gallery folder
to enter that gallery, or by using the gallery navigation bar, which is just above the galleries.
You will explore the galleries a bit before preparing to add objects to your new world.
1. Click the folder icon on the gallery navigation bar to move up one level in
the tree of galleries, so that you can see the top level in the tree, as shown
in Figure 1-8. Two icons are visible: one for the Local Gallery and one for
the Web Gallery.
Home
2. Click the Local Gallery icon to go back to the Local Gallery. Scroll left and
right through the Local Gallery using the scroll bar below the gallery fold-
ers, and you will see some of the many categories of objects available in Alice.
3. Find and click the Animals folder icon to open the folder. Scroll left and
right through this gallery to see some of the animal objects available in Alice.
O b j e c t C l a s s e s a n d I n s t a n c e s in Alice
Each of the tiles in the Animals folder represents a class of objects. A class is a group of
objects with the same properties and the same methods. Objects in the same class are virtu-
ally identical to each other, except that the values stored in some of their properties may be
different. For example, you could have an Alice world with two Penguin objects. They
16 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
would both have the same methods and the same properties, but the values of some of those
properties, such as location or color, might be different.
Each copy of an object from a particular class is called an instance of the object. As you use
Alice, you will notice that the object class tiles in the object galleries have the word class in
their title and each begins with a capital letter, such as Class Bunny or Class Chicken, but
once an instance of an object is placed in a particular Alice world, its name begins with a
lowercase letter. Of course, it is possible to rename objects, so this distinction is not always
maintained.
The act of adding an instance of an object class to an Alice world is called instantiation.
The same terminology—classes, instances, and instantiation—is used in most object-
oriented programming languages.
You are going to add an instance of an object from the Animals folder in the Local Gallery
to your new Alice world. You are going to instantiate a Bunny class object.
1. Click the Class Bunny icon. A window with information about Bunny class
objects, like the one in Figure 1-9, should appear.
* Bunny X
2. Click the Add instance to world button to put a bunny into the world. This is
sometimes called dropping an object into the world. You should see a bunny
appear in the center of the World window.
3. You can also add an object to an Alice world by clicking an object class tile
and dragging it into place in the World window. Try this now: drag and
drop a chicken tile into your Alice world. This approach lets you place the
new object wherever you would like on the ground in the World window;
however, it does not show you the object's information window first.
4. You should now have an Alice world with two objects—a bunny and a
chicken. Notice that tiles for the new objects have also been added to the
Object tree. You really don't need the chicken for the rest of this exercise.
Tutorial 1C—Creating Your First Alice World 15
The Scene Editor has new controls, a larger World window, and object galleries on the bot-
tom. The Scene Editor replaces the Events area and the Editor area when you are in Scene
Editor mode.
There are two Alice object galleries: a Local Gallery provided with the Alice software, and a
Web Gallery maintained by Carnegie Mellon University. (You need an active Internet con-
nection to use the Web Gallery.) The Local Gallery is visible at the bottom of the screen in
Scene Editor mode, as shown in Figure 1-7. The galleries are organized as a tree of folders
containing related objects. You can navigate the tree of galleries by clicking a gallery folder
to enter that gallery, or by using the gallery navigation bar, which is just above the galleries.
You will explore the galleries a bit before preparing to add objects to your new world.
1. Click the folder icon on the gallery navigation bar to move up one level in
the tree of galleries, so that you can see the top level in the tree, as shown
in Figure 1-8. Two icons are visible: one for the Local Gallery and one for
the Web Gallery.
Home
2. Click the Local Gallery icon to go back to the Local Gallery. Scroll left and
right through the Local Gallery using the scroll bar below the gallery fold-
ers, and you will see some of the many categories of objects available in Alice.
3. Find and click the Animals folder icon to open the folder. Scroll left and
right through this gallery to see some of the animal objects available in Alice.
O b j e c t C l a s s e s a n d I n s t a n c e s in Alice
Each of the tiles in the Animals folder represents a class of objects. A class is a group of
objects with the same properties and the same methods. Objects in the same class are virtu-
ally identical to each other, except that the values stored in some of their properties may be
different. For example, you could have an Alice world with two Penguin objects. They
16 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
would both have the same methods and the same properties, but the values of some of those
properties, such as location or color, might be different.
Each copy of an object from a particular class is called an instance of the object. As you use
Alice, you will notice that the object class tiles in the object galleries have the word class in
their title and each begins with a capital letter, such as Class Bunny or Class Chicken, but
once an instance of an object is placed in a particular Alice world, its name begins with a
lowercase letter. Of course, it is possible to rename objects, so this distinction is not always
maintained.
The act of adding an instance of an object class to an Alice world is called instantiation.
The same terminology—classes, instances, and instantiation—is used in most object-
oriented programming languages.
You are going to add an instance of an object from the Animals folder in the Local Gallery
to your new Alice world. You are going to instantiate a Bunny class object.
1. Click the Class Bunny icon. A window with information about Bunny class
objects, like the one in Figure 1-9, should appear.
ftiBunny X
4
M M
u..,rl.-l.-.HV
ii4i«ed by-
pans:
a o
2. Click the Add instance to world button to put a bunny into the world. This is
sometimes called dropping an object into the world. You should see a bunny
appear in the center of the World window.
3 . You can also add an object to an Alice world by clicking an object class tile
and dragging it into place in the World window. Try this now: drag and
drop a chicken tile into your Alice world. This approach lets you place the
new object wherever you would like on the ground in the World window;
however, it does not show you the object's information window first.
4. You should now have an Alice world with two objects—a bunny and a
chicken. Notice that tiles for the new objects have also been added to the
Object tree. You really don't need the chicken for the rest of this exercise.
Tutorial 1C—Creating Your First Alice World
To delete the chicken, right-click the object or the object's tile in the Object
tree and select delete from the menu that appears.
Positioning Objects
The layout tools to the right of the World window in Scene Editor mode can be used to
manipulate objects. This area contains the seven standard tools listed in Table 1-1.
n Pointer tool Selects an object and moves the object parallel to the ground
m Turn tool Turns an object along its X-Y plane parallel to the ground
4 . After the bunny is in position, click the large green DONE button to close
the Scene Editor and go back to the standard Alice interface.
Adding S o m e Action
The next step is to add some motion to your world. You can start with something s i m p l e —
making the bunny move across the screen—and then add a little more action. To make
things happen in your world, you need to use methods for the objects. In the Editor area,
you already have the default method, which is world.my f i r s t method. The full name of
every method has two parts: the name of the object associated with the method (which
comes before the period) and the name of the method itself (which comes after the period).
1. Click the World tile in the Object tree in the upper-left corner of the interface.
2 . Click the methods tab in the Details area. You will see that the name of the
method in the Details area is simply my f i r s t method, but in the Editor,
you see the full name, world.my f i r s t method.
The default event can be seen in the Events area on the top-right side of the
interface. In Figure 1-11, you can see the tile for the default event, which
shows that the event trigger is When t h e world s t a r t s , and the event han-
dler is w o r l d , my f i r s t method. Any instructions you add to world .my
f i r s t method will be executed when the world starts to play.
Tutorial 1C—Creating Your First Alice World 19
3. Click the bunny tile in the Object tree. Now you can see information about
the bunny in the Details area. You should be able to see the bunny's meth-
ods in the Details area. You create new code for Alice objects by dragging
tiles for objects, other methods, and control structures into the method you
are currently editing. You get object tiles from the Object tree, method tiles
from the methods tab in the Details area, and logic and control tiles from
the bottom of the Editor area.
4. Make sure that the methods tab is selected in the Details area, and then find
and drag the bunny move tile into the middle of world.my f i r s t method
in the Editor area.
5. A short menu will appear asking you to choose the direction and amount
you want the bunny to move. Select forward for the direction, and then
1 meter for the amount.
Information that you must give to a method whenever you use the method is called
a method p a r a m e t e r . Direction and amount are two parameters for the move method.
6. To test your world, click the Play button near the upper-left corner of the
Alice interface. You will see the bunny move. It's not much, but it's a start.
Click the Restart button to play the world again, and then click the Stop
button to return to the standard Alice interface.
7. To change the amount the bunny moves, click the 1 meter parameter in the
move tile in your new method, and then choose one of the values in the
drop-down menu. You can also click other and then enter a number on the
calculator-style keypad that appears. Try changing the amount a few times
and then playing the world after each change until you can make the bunny
move to approximately the middle of the screen.
8. Let's add a few more instructions. First, find the bunny turn to face method
tile. It's in the Details area about 11 or 12 tiles below the bunny move tile
that you just used. You will probably need to scroll down to see it. The
parameter for this tile will be the object you want the bunny to face. Click
and drag the bunny turn to face tile into the Editor area and drop it below
the bunny move tile, and then choose camera as the object you want the
bunny to face.
20 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
9. Next, you are going to add two tiles to make the bunny speak, and then you
will save the world. First, find and drag the bunny say tile into the Editor
area and drop it below your other two instructions. The parameter for this
method is the phrase you want the bunny to say. This parameter is a string
parameter, which contains a string of characters from the keyboard. When
the parameter menu appears, click other, and then type Hello, World! in the
Enter a string input box that appears, and then click OK.
Why "Hello, World!"? One of the most useful and popular programming languages ever cre-
ated was the C programming language developed at AT&T labs in the 1970s. The Hello,
World! program first appeared in a C language book written by two AT&T software develop-
ers, Brian Kernighan and Dennis Ritchie. Dr. Kernighan, who later became a professor at
Princeton University, actually wrote the first Hello, World! program for a tutorial on an ear-
lier programming language. Ever since then, it has been the custom for someone program-
ming in a new language to write a version of the Hello, World! program as his or her first
program. Congratulations, you've just done that in a new language! Let's add one more
instruction before saving the program.
1. Add another bunny say tile to make the bunny say "Hello, Dr. Kernighan!"
2. Now play your world again (several times if you'd like), and when you are
finished, click the Stop button to return to the Alice interface.
3. To save the world you created, click the File menu and then click Save
World. Notice that Alice has File menu options to Save World and to Save
World As. The first time you try to save a new world, you will see the
Save World As dialog box, as shown in Figure 1-12. This dialog box looks
similar to Save As dialog boxes in Windows programs, such as Microsoft
Word; the dialog box contains a navigation bar and other controls.
Whenever you want to make a copy of an Alice world, particularly if you
have made changes to it and want to keep the old world, use the Save
World As feature, and give the new copy a different name.
Tutorial 1C—Creating Your First Alice World
3
airport.a2w
baseball.a2w
boat game.a2w
j
chicken is tasty.a2w
cows.a2w
My
Desktop haunted house.a2w
Documents keyboard tutorial.a2w
Shackleton's penguins.a2w
titry dancer.a2w
My toy soldiers.a2w
Computer
4. Decide where you want to save the world, and then navigate to the
correct folder.
You may save Alice worlds wherever you wish. If you are in a course using Alice, please
find out where your instructor would like you to save your files, because this may depend
on how your classroom computers are configured. If you are working on your own, you
should save them someplace where they will be easy to find; remember (or write down)
where you saved each file. Appendix B contains more information about changing the
default settings for the save command.
5. Type the name hello world, with no punctuation, in the File name box.
Notice that the file type shown below the File Name box is A2W (Alice
World Files). This indicates that the file you save will end in the extension
,a2w. You should not change this. Click the Save button to save your world.
Whenever you want to make a copy o f an Alice world, particularly if you have made
changes to it and want to keep the old world, use the Save World As feature, and give the
new copy a different name.
22 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
Next, close the Alice program and then open your saved world.
1. Click File on the menu bar, and then click Exit. The Alice program will close.
2. Reopen the Alice software. Click the Recent Worlds tab in the Welcome to Alice!
dialog box, and then open the hello world world that you created. If the name of
a world you want to open does not appear on the Recent Worlds tab, you can
click the Open a world tab and look for your world in the tree of folders.
The code from methods and events in an Alice world can be saved on an HTML Web page,
which you may then print, send as an e-mail attachment, or view like any other Web page.
You can also cut and paste items from the resulting Web page to other programs, such as
Microsoft Word or PowerPoint.
The steps in this tutorial show you how to save the code from your Hello, World! project as
an HTML file in the root directory on the C: disk drive. If you are a student in a course
using Alice, it is best to ask your instructor whether you should use the C: disk drive or
another location.
1. Click File on the menu bar. Notice that there are menu options to export an
Alice world as a Web page and to export code from an Alice world for printing.
You are going to use Export Code For Printing, which will put the code from
your Alice world as text on a Web page, rather than putting the Alice world
itself on a Web page as a Java Applet. These options on the hie menu are dis-
cussed in more detail in Appendix B. Click the Export Code For Printing
option. The Export to HTML dialog box, as shown in Figure 1-13, should appear.
jfti E x p o r t t o HTML...
What to export:
| world Select AH
Author's name;
POLYXENES.
Sano!
CAMILLO.
Mun määräsi hän teidät murhaamaan.
POLYXENES.
Ken määräsi?
CAMILLO.
Kuningas.
POLYXENES.
Mistä syystä?
CAMILLO.
Hän luulee, jopa vannookin sen varmaks,
Ikäänkuin nähnyt ois tai itse teillä
Apuna ollut, — että ilkityötä
Olette tehnyt kuningattarelle.
POLYXENES.
Myrkkyiseks silloin hyytyköhön visvaks
Sydänvereni, ja nimeni sen nimeen
Nivottakohon, joka petti Parhaan!
Maineeni puhtain tulkoon löyhkäks, jota
Jo kaukaa tylsimmänkin aisti kammoo.
Näköni inhon tuottakoon ja kauhun
Kuin iljettävin rutto, mit' on nähty
Tai koskaan kuultu.
CAMILLO.
Vannokaatte vaikka
Jok' ainokaisen taivaan tähden kautta
Ja kaiken niiden tenhon, ennen voitte
Te kieltää meren kuulemasta kuuta
Kuin valoin järkyttää tai neuvoin kaataa
Tuot' epäluulon linnaa, jonka perus
On hänen uskonsa ja joka kestää
Niin kauan kuin hän itse.
POLYXENES.
Mikä syynä?
CAMILLO.
En tiedä, mutta varmaan vaaraa taatump'
On karttaa kuin sen syytä tiedustella.
Siis, — jos te luotatte mun kunniaani,
Mi tässä ruhoss' asuu, jonka voitte
Mukaanne pantiks ottaa, — pois tän' yönä!
Ma tiedon siitä miehillenne kuiskaan
Ja kaksittain heit' eri teitä päästän
Kaupungist' ulos. Teidän turvihinne
Jää oma onneni; se täällä nyt on
Jo menetetty. Älkää epäröikö!
Kautt' isieni kunnian: totta puhun.
Mut sitä tutkimaan jos tänne jäätte.
Niin minä teit' en varro; eikä teillä
Tääll' olo liene taatumpi kuin sillä,
Jonk' itse kuningas on tuominnut ja
Telattavaksi vannonut.
POLYXENES.
Sua uskon.
Jo hänen kasvoistansa sydän kuulti.
Kätesi mulle; oppaakseni lähde,
Niin paikkas mua lähinnä on aina.
Purjeiss' on laivat; kaksi päivää lähtöön
On väki ollut valmiina. — Tuo koskee,
Tuo luulevaisuus kallist' olentoa.
Se yhtä suuri on, kuin hän on kaunis,
Ja yhtä hillitön kuin mies on voipa,
Ja kahta karvaammaksi tehnee koston
Se luulo, että häväissyt on häntä
Mies, joka aina hänt' on kunnioinnut.
Mun valtaa pelko. Onneksi tää päätös
Minulle olkohon ja lohduks tuolle
Jalolle olennolle, joka syyttä
Miehensä luuloiss' on. Camillo, tule:
Sua niinkuin isää kunnioitan, jos
Viet hengissä mun täältä. Paetkaamme!
CAMILLO.
Mun arvoni se mulle aukaiseepi
Kaupungin kaikki portit. Suvaitkaa vaan
Ajasta ottaa vaari. Lähtekäämme.
(Poistuvat.)
TOINEN NÄYTÖS.
Ensimmäinen kohtaus.
Paikka sama.
(Hermione, Mamillius ja hovinaisia tulee.)
HERMIONE.
Pois poika viekää; mua häiritsee hän,
En sitä nyt voi kestää.
1 HOVINAINEN.
Tulkaa, prinssi,
Minusta saatte leikkitoverin.
MAMILLIUS.
Sinust' en huoli.
1 HOVINAINEN.
Miksi, rakas prinssi?
MAMILLIUS.
Mua suutelet ja puhut, niinkuin vielä
Olisin lapsi. — Paremp' olet sinä.
2 HOVINAINEN.
Ja miks?
MAMILLIUS.
Ei siksi, että silmäkarvat
On sulla mustemmat; lie joskus kauniit
Mustatkin silmäkarvat, jos vaan eivät
Ole liian paksut, — sulin tehty juomu,
Kuunkanta hienon hieno vain.
2 HOVINAINEN.
Ken teille
On moista opettanut?
MAMILLIUS.
Naisten kasvot. —
Mut mink' on väriset sun silmäkarvas?
1 HOVINAINEN.
Siniset.
MAMILLIUS.
Älä! Rouvan näin, joll' oli
Sininen nenä, vaan ei silmäkarvat.
2 HOVINAINEN.
Mut kuulkaas! Kuningatar, äitinne,
On pikkusiin; koht' uuden, hienon prinssin
Me saamme; kyllä silloin kisaisitte,
Jos teistä huolisimme.
1 HOVINAINEN.
Niin, hän vahvast'
On paisunut. Jumala hälle avuks!
HERMIONE.
Mit' ilveilyä siellä? Tule, lapsi,
Taas seuraas kaipaan. Istu, kerro mulle
Tarina.
MAMILLIUS.
Hauskako vai surullinen?
HERMIONE.
Niin hauska kuin vain tahdot.
MAMILLIUS.
Surullinen
Sopivin talvell' on. Ma yhden tiedän,
Siin' aaveit' on ja noitia.
HERMIONE.
Se kerro.
No, istuhan ja ala; aaveillasi
Mua oikein säikytä; sit' osaat tehdä.
MAMILLIUS.
Oli kerran miesi —
HERMIONE.
Istuhan; no ala!
MAMILLIUS.
Jok' asui kirkkomaalla. — Kerron hiljaa
Nuo sirkat sit' ei kuulla saa.
HERMIONE.
No, jatka,
Ja korvahan! kuiskaa.
LEONTES.
Sielläkö
Hän nähtiin? Seuroineen? Camillo myötä?
1 HOVIHERRA.
Männistöss' yhdyin heihin. Moista kiirett'
En ole nähnyt. Silmin heitä saatoin
Laivastoon asti.
LEONTES.
Mua miekkoista,
Kun oikein näin ja toden arvasin! —
Oo, vähempikin riittäisi Lemmon tuskaa
Tää miekkoisuus! — Voi maljass' uida lukki,
Ja sinä juot ja poistut tietämättä
Myrkystä mitään, sillä oma tietos
Ei ole myrkytetty; vaan jos joku
Tuot' inhaa otust' osoittaa ja näyttää
Mit' olet juonut, silloin kuotus tuima
On sulta poven katkoa ja kyljet. —
Minäkin join ja lukin näin. Camillo
Hänt' auttoi, teki parittajan virkaa. —
He hengen multa tahtovat ja kruunun;
Epäilys toteen käy: — tuo viekas konna,
Mun palkkaamani, palkoiss' oli hällä;
Hän hankkeeni on ilmaissut, ja minä
Nolattu olen narri, joka nulkin
Ivailtava. — Mut kuinka pääsivätkään
He portist' ulos?
1 HOVIHERRA.
Hänen arvollansa,
Mi käskystänne suurempaakin aikaan
On saanut.
LEONTES.
Hyvin tiedän. — Poika tänne!
(Hermionelle.)
Hyvä, ett'et sinä häntä imettänyt.
Vaikk' on mun näköäni hän, niin liiaks
On häness' äidin verta.
HERMIONE.
Leikkiäkö?
LEONTES.
Pois poika viekää! Hän sit' ei saa pitää;
Pois, pois! Sen kanssa nyt hän leikitelköön,
Jota hän kantaa, sillä Polyxenes
Sen hälle tehnyt on.
HERMIONE.
Ei, sanon, ei,
Ja vannon, että uskotte, min sanon,
Vaikk' yritätte kieltää.
LEONTES.
Hyvät herrat,
Katselkaa häntä tarkoin; jos on mieli
Sanoa teillä: "hän on kaunis", heti
Vavahtaa tuntonne ja lisää: "sääli,
Ett'ei hän ole siveä ja puhdas!"
Kiitelkää hänen ulkomuotoansa, —
Jok' ansaitseekin suurta ylistystä, —
Niin heti olan nykäys, hm! ja haa!
Nuo poltinmerkit, joita parjaus käyttää —
Ei, mitä? — sääli käyttää, sillä parjaus
Hyveenkin polttaa; — niin tuo olan nykäys,
Nuo hm! ja haa! — sanottuanne juuri
"Hän kaunis on"; — teit' estää sanomasta:
"Hän ompi siveä". Mut tietyks tulkoon
Sen suusta, jolla suurin syy on harmiin:
Hän portto on.
HERMIONE.
Jos sanoisi sen konna.
Viheliäisin konna maailmassa.
Hän suuremp' ois vaan konna; mut te, herra.
Te erehdytte.
LEONTES.
Itse erehdyitte
Te, hyvä rouvani, kun Polyxeneen
Leonteeks luulitte. Oo, sinä eläin,
Jot' en voi oikein nimin nimittääkään,
Ett'ei mua raakuus matkisi ja samaa
Käyttäisi kieltä kaikensäätyisille,
Näin unhottain, mik' erotus on prinssin
Ja kerjäläisen välillä. Ma sanoin,
Ett' on hän portto, sanoin myöskin, kelle.
Lisäksi: kavaltaja, jonka kanssa
Camillo liitoss' on, mies, joka tietää
Mit' itsekin tuon pitäis hävetä
Katalan raiskaajankin nähden tietää,
Ett' on hän portto pahempi, kuin mit' on
Pahimmat tulenlautat; niin, hän tiesi
Tuon paon myös.
HERMIONE.
En tiennyt, totta Jumal',
En siitä tiennyt! Teitä kaduttaa,
Parempaan tietoon kerran tultuanne,
Nää herjauksenne. Hyvä puoliso,
Mua tuskin hyvitätte sillä, että
Sanotte pettyneenne.
LEONTES.
Ei, jos petyn
Tään rakenteeni perustusten suhteen,
Ei silloin koulupojan hyrrää jaksa
Maapallo kantaa. — Tyrmään hänet viekää!
Ken puhuu hänen puolestaan, on syypää
Jo siksi, että puhuu.
HERMIONE.
Turman tähti
Nyt hallitsee. Mun malttaa täytyy, kunnes
Suopeemmaks kääntyy taivas. — Hyvät herrat,
Niin hevin kuin muut naiset min' en itke,
Ja tämän hyödyttömän kasteen puutos
Teilt' ehkä säälin kuivaa; mut tääll' asuu
Siveyden syvä suru, ja se palaa
Niin, ett'ei sitä sammuttaa voi itkut.
Mua, hyvät herrat, pyydän, tuomitkaa
Niin leppeesti kuin ihmisrakkaus sallii; —
Ja täyttyköön nyt tahto kuninkaan.
LEONTES.
Mua totellaanko?
HERMIONE.
Seuraako mua kukaan?
Rukoilen, herra, suokaa naisieni
Mukaani tulla; tilani sen vaatii,
Sen näette. Ei, hyvät lapset, itkuun
Ei syytä nyt; mut vankeuteen syypääks
Jos emäntänne kuulette, niin silloin
Valukoot kyyneleet, kun vapaa olen.
Koetus tää tuo ikionnen mulle. —
Hyvästi, kuningas; en murheisena
Sois koskaan teitä näkeväni; mutta
Niin käynee nyt. — No, tulkaa, teill' on lupa.
LEONTES.
Pois, tehkää niinkuin käskimme; pois täältä!
1 HOVIHERRA.
Rukoilen: palauttakaa kuningatar.
ANTIGONUS.
Punnitkaa tarkoin, muuten oikeutenne
On väkivaltaa; siitä kolme kärsii:
Te itse, poikanne ja puolisonne.
1 HOVIHERRA.
Siit' uskallan ma henkeni, jos vaan se
Takeeksi kelpaa, että kuningatar
On puhdas taivaan edessä ja teidän,
Syytteestä — tarkoitan.
ANTIGONUS.
Jos toteen saadaan,
Ett' toisin on, niin vaimoani vahdin
Yöt päivät, häneen kytkettynä kiinni,
Ja sen vaan uskon, minkä näen ja tunnen;
On silloin joka tuuma naisen lihaa,
Niin, joka hiuke naista uskoton.
Jos hänkin on.
LEONTES.
Vait ole!
1 HOVIHERRA.
Hyvä herra —
ANTIGONUS.
Puhumme teidän, eikä omaan puoleen.
On joku viettelijä, lemmon konna
Teit' uskotellut; jos sen tuntisin,
Niin ruhjoisin sen. Hänkö kunniaton! —
Tytärtä mull' on kolme, yhdentoista
Ja yhdeksän ja viiden ijässä;
Jos tott' on tää, niin, kautta kunniani,
Sen heille kostan, kohdun heiltä leikkaan,
Ennenkuin neljäntoista ovat vanhat
Ja epäsikiöitä siittää saavat.
Mun perivät, mut ennen olen salvio,
Kuin kelvottoman rodun kantaisä.
LEONTES.
Vait! Täss' on vainu yhtä valju teillä
Kuin kuolleen nenällä; ma tunnen, näen sen
Niinkuin te tämän (kouristaa häntä) tunnette, ja näette,
Mik' elin teihin koskee.
ANTIGONUS.
Niin jos on,
Ei kunnialle hautaa ole tarvis;
Lemuksiks siit' ei jää maan tunkiolle
Niin hiukkaakaan.
LEONTES.
Mua ei siis uskota!
1 HOVIHERRA.
Parempi jos täss' uskottaisi mua,
Kuin teitä, herra! Ennen soisin, että
Hän puhdas olis, kuin te oikeassa,
Vaikk' oiskin moitteeksi se teille.
LEONTES.
Miksi
Kyselen tuumianne? Paremp' on
Totella vihan puuskaa. Majesteetti
Ei neuvojanne kaipaa. Hyvyyttämme
Sen kerroimme. Jos ette voi tai tahdo —
Joko luonnon- taikka teko-tyhmyydestä —
Niin nähdä totuutta kuin me, niin sitä
Paremmin tutkikaatte; neuvojanne
Ei meidän tarvis; asia, sen meno,
Sen voitto, tappio meit' yksin koskee.
ANTIGONUS.
Parempi olis ollut hiljaisuudess'
Asiaa ensin tutkia kuin siitä
Melua nostaa.
LEONTES.
Mahdollistako?
Sin' olet joko vanhuudesta tylsä
Tai luotu narriksi. Camillon pako,
Tuo tuttavallisuus — niin peittämätön.
Niin epäiltävä, että todisteeksi
Vaan näkemistä tarvittiin, ei muuta
Kuin näkemistä, ilmeisethän oli
Muut seikat kaikki — pakotti mua tähän.
Mut vielä paremmaksi vakuudeksi —
Näin tärkiss' asioissa hurja toimi
Ois surettava — olen lähettänyt
Apollon temppelihin, pyhään Delphiin
Cleomeneen ja Dionin, jotk' ovat,
Tiedämmä, taatut miehet. Kaikki riippuu
Oraakelista nyt; sen pyhä neuvo
Mua auttaa taikka kaataa. Teinkö oikein?
1 HOVIHERRA.
Ihan oikein, kuningas.
LEONTES.
Vaikk' itse vanna
Asiast' olen enkä muuta kaipaa
Kuin minkä tiedän, tulee oraakelin
Tyventää muiden mielet, moisten, jotka,
Typerän tyhminä kuin tuo, ei jaksa
Yletä totuuteen. Suvaitsin siksi
Tuon naisen poistaa läheisyydestämme,
Ett'ei hän noiden kahden paennehen
Petosta panis täytäntöön. Nyt tulkaa;
Puhua tahdon kansalle; tää tapaus
Kiihottaa meitä kaikkia.
ANTIGONUS (syrjään).
Niin, nauruun,
Kun selvä totuus tulee päivän valoon.
(Poistuvat.)
Toinen kohtaus.
Seutu sama. Etuhuone kuningattaren vankilassa.
(Paulina ja useita palvelijoita tulee.)
PAULINA.
Hae tänne vanginvartija ja sano
Nimeni hälle. —
(Yksi palvelijoista menee.)
Jalo rouva, sulle
Ei parhain hovi ole liian hyvä,
Miks siis nyt tyrmäss' istut?
(Palvelija palajaa, mukanaan vanginvartija.)
Ystävä,
Te tiedätte, ken olen?
VANGINVARTIJA.
Arvonainen,
Ylevä rouva.
PAULINA.
Päästäkää siis minut
Kuningattaren luo.
VANGINVARTIJA.
En tohdi, rouva,
Päinvastainen on mulla jyrkkä kielto.
PAULINA.
Kaunista kieltää ystävien seura
Hyveeltä, kunnialta! Onko lupa
Tavata hänen naisiaan? Vain yhtä?
Emiliaa?
VANGINVARTIJA.
Jos suvaitsette, rouva,
Lähettää syrjään seuranne, niin saatan
Emilian luoksenne.
PAULINA.
Se, pyydän, tehkää. —
Menkäätte syrjään!
(Seuralaiset poistavat.)
VANGINVARTIJA.
Minun täytyy olla
Keskustelussa läsnä.
PAULINA.
Hyvä, hyvä!
(Vanginvartija poistuu.)
Mik' into tahratonta tahrata!
Ihana kaunoaisti!
(Vanginvartija palajaa Emilian kanssa.)
Hyvä rouva,
Mitenkä kuningattaren on laita?
EMILIA.
Niin hyvin kuin niin ylhäisen voi olla
Noin sorrettuna. Surusta ja kauhusta —
Kovempaa ei lie koskaan hento nainen
Kokenut — synnytti hän ennen aikaa.
PAULINA.
Pojanko?
EMILIA.
Tyttären, ja kauniin lapsen,
Terveen ja virkun. Äiti iloitseepi
Ja sanoo: "Vanki parka, niinkuin sinä,
Viaton minäkin".
PAULINA.
Sen minä vannon.
Kirotut kuninkahan hullut houreet!
Tään saa hän tietää, saapa niin! Se toimi
On naiselle kuin luotu; minä teen sen.
Jos mairii kieleni, niin rakkoutukoon,
Niin ett'ei vihaa verisilmäist' enää
Se koskaan torveta! Emilia hyvä,
Mua suositelkaa kuningattarelle;
Jos lapsens' uskoa hän tohtii mulle.
Niin kuninkaan sen nähdä vien ja lupaan
Asiat' ajaa oikein kuuluvasti.
Kenties tuo heltyy, kun hän lapsen näkee;
Viaton, puhdas äänettömyys usein
Enemmän voi kuin puhe.
EMILIA.
Jalo rouva,
Hyveenne, hyvyytenne on niin taattu,
Ett' altis, suora hankkehenne varmaan
Hyvinkin päättyy. Sopivampaa naista
Ei tähän toimeen löydy. Pyydän, käykää
Lähihuoneeseen, niin kuningattarelle
Ilmoitan heti jalon tarjonne.
Hän tänään hautonut on samaa tuumaa,
Mut ketään arvomiest' ei tohdi pyytää,
Peläten kieltoa.
PAULINA.
Sanokaa hälle,
Ett'en ma kieltän' aio lainkaan säästää;
Jos se niin liukas on, kuin miel' on uljas,
Niin jotain aikaan saanen.
EMILIA.
Kost' jumala!
Kuningattaren luo nyt lähden. Käykää
Lähemmä, olkaa hyvä.
VANGINVARTIJA.
Kuningatar
Jos suvaitsee nyt lapsen luotaan antaa,
Niin kuinka käy mun, jos sen täältä päästän,
Kun mull' ei siihen valtaa?
PAULINA.
Huolet' olkaa!
Laps vanki äidin kohduss oli vainen.
Ja suuren luonnon lain ja säännön mukaan
Siit' on se vapaa nyt, ei osallinen
Kuninkaan vihaan eikä syypää myöskään
Kuningattaren rikokseen, jos moista
On olemassakaan.
VANGINVARTIJA.
Sen ihan uskon.
PAULINA.
Siis huolet' olkaa: minä astun teidän
Ja vaaran väliin, kautta kunniani!
(Kaikki poistuvat.)
Kolmas kohtaus.
Seutu sama. Huone hovilinnassa.
(Leontes, Antigonus, hoviherroja ja seuralaisia tulee.)
LEONTES.
Ei rauhaa öin, ei päivin! Heikkoutt' on
Tää mielentila, pelkkää heikkoutta.
Jos syy vaan olis poissa — osa syystä —
Tuo naikko! Kuningasta hylkiötä
Ei yllä käteni; hän turviss' ompi,
Ajuni ampumatkan ulkopuolla.
Mut iskeä voin naikkoon. Hän jos poissa
Ja tulen oma ois, niin pala jäisi
Taas toinen puoli rauhaa. — Kuka siellä?
PALVELIJA.
Palvelijanne.
LEONTES.
Kuink' on pojan laita?
PALVELIJA.
Makasi hyvin yönsä; luultavasti
On tauti taittunut.
LEONTES.
Mik' ylväs lapsi!
Kun tajusi hän äidin häväistyksen,
Niin oiti kuihtui, laihtui, tunsi kaihon,
Ikäänkuin tarttunut ois häpy häneen,
Menetti ilon, unen, ruokahalun,
Pelehtyi aivan. — Yksin tahdon olla;
Pois, käykää poikaa katsomaan. —
(Seuralaiset lähtevät.)
Hyi, häntä
Älä aattelekaan! Siihen suuntaan käypä
Jo pelkkä koston ajatuskin kimmoo
Takaisin minuun; suuri häll' on valta,
Suvut ja liittolaiset; — hän siis jääköön
Parempaan aikaan; naikkoa vain kosto
Nyt kohdatkoon. Camillo ja Polyxenes
Mua nauravat, ivaavat suruani;
Jos yltää heidät voisin, eivät naurais,
Ei, eikä tuokaan, jok' on vallassani.
1 HOVIHERRA.
Täst' ette pääse.
PAULINA.
Mitä? Hyvät herrat.
Pikemmin tulis teidän mua auttaa.
Pelättävämpi tuonko hurja vimma
Kuin henki kuningattaren, sen raukan,
Mi puhtaamp' on, kuin tuo on luulevainen.
ANTIGONUS.
Vait, vait!
1 HOVIHERRA.
Hän yöt' ei maannut, eikä salli
Kenenkään päästä luokseen.
PAULINA.
Tyynny, veikko!
Juur' unta tulen tuomaan. Teidän moiset,
Jotk' ympärillään luikitte kuin varjot,
Te teidän moiset häntä valvotatte.
Ma tulen vilpittömin, terveellisin,
Vakavin sanoin loihtimaan pois vammaa,
Jok' unen hältä vie.
LEONTES.
Melua mitä?
PAULINA.
Ei melua, vaan tuumailua, mistä
Sais ylhäisyydellenne kummin.
LEONTES.
Mitä?
Pois rietas vaimo tuo! Antigonus,
Sua kielsin päästämästä häntä tänne,
Aikeensa tiesin.
ANTIGONUS.
Omani ja teidän
Vihanne uhalla ma häntä koitin
Täält' estellä.
LEONTES.
Hänt' etkö suistaa voi?
PAULINA.
Pahasta, kyllä; vaan täss' asiassa —
Jos ei hän tee kuin te, ja tyrmään heitä
Mua siitä, ett'en kunniaani heitä —
Hän ei mua suista.
ANTIGONUS.
Nyt sen kuulette!
Jos noin hän kiltoo, juoskoon minkä jaksaa,
Hän kyll' ei kompastu.
PAULINA.
Kuningas hyvä,
Ma pyydän, mua kuulkaa! Teille tahdon
Ma lääkär' olla, taattu palvelija
Ja nöyrä neuvoja, vaikk' en niin julkee
Tuskanne lieventäjän' esiintyä,
Kuin liehakkonne nuo, — mun lähetti
Hyvä kuningatar.
LEONTES.
Hyvä kuningatar!
PAULINA.
Niin, hyvä, sanon, hyvä kuningatar,
Ja siitä tappelisin, mies jos oisin,
Vaikkapa kehnoin.
LEONTES.
Aja hänet ulos!
PAULINA.
Se, jok' ei pelkää silmiään, se ensin
Käsiksi käyköön! Lähden milloin tahdon.
Asia ensin! — Hyvä. kuningatar —
Hyvä on hän — antoi teille tyttären:
Täss' on se, siunaustanne pyytää.
LEONTES.
Ulos,
Sa, noidan narttu! Hiiteen täältä! Pois,
Lipakka parittaja!
PAULINA.
Erehdytte:
Tuost' olen yhtä tiedoton kuin te,
Sen nimen antaja, ja yhtä siivo
Kuin te olette hullu; joka kyllin
Jo siivoutt' on tähän mailman aikaan.
LEONTES.
Kavaltajat! Hänt' ette viskaa ulos?
Kakara hälle viekää! —
(Antigonukselle.)
Sinä narri,
Sinä ämmälauri, narttusi kun annat
Sun orrelt' ajaa! — Ota äpärä,
Otahan, sanon; ämmälles se anna!
PAULINA.
Ijäksi kätes saastukoon, jos kosket
Prinsessaan nyi, kun näin on häneen syyttä
Ajettu lokaa.
LEONTES.
Eukkoaan hän pelkää.
PAULINA.
Jos tekin tekisitte sen, niin varmaan
Omistaisitte oman lapsenne.
LEONTES.
Kavaltajia kaikki!
ANTIGONUS.
Totta jumal',
En minä.
PAULINA.
Enkä minä, eikä kukaan;
Yks on, hän itse; kavaltain hän oman
Hyvän maineensa ja kuningattarensa
Ja poikansa ja tyttärensä alttiiks
Näin heittää parjaukselle, joka puree
Miekkaakin kipeämmin, eikä tahdo —
Kirottua, ett'ei voi häntä siihen
Pakottaakaan! — pois tyynni temmata
Tuon luulon juurta, jok' on yhtä laho,
Kuin tammi on tai paasi terve.
LEONTES.
Suulas,
Lipakka lutka, jok' on miestään piessyt
Ja nyt mua hämää! Mun ei ole pentu,
Polyxeneen se peruutt' on. Pois, pois se,
Ja äitineen se tuleen viskatkaa!
PAULINA.
Se teidän on ja teidän näköisenne
Niin — käyttääkseni vanhaa sananpartta —
Ett' oikein hävettääpi. — Nähkääs, herrat,
On koko pieni, vaan se ihan isän
On jälkipainos: silmät, huulet, otsa,
Nenä ja kulmakarvat, niin, ja posken
Ja leuan sievät kuopanteet, ja hymy
Ja kätten, sormien ja kyntten muoto. —
Hyvä jumalatar, Luonto, joka lapsen
Näin isän näköön teit, jos luonteen myöskin
Voit muodostaa, niin keltaist' älä käytä
Väriä vain; se muuten, kuten tuokin,
Epäilee, ett'ei lapsens' ole hänen
Miehensä lapsi.
LEONTES.
Sinä, hiiden velho! —
Sinäkin, pöllö, hirtettävä oisit,
Kun tuon et kieltä suistaa voi.
ANTIGONUS.
Jos kaikki
Ne miehet hirtettäisi, jotka moista
Ei aikaan saa, niin tuskin teille yhtään
Jäis alamaista.
LEONTES.
Vaimo pois, ma sanon!
PAULINA.
Pahempaa luonnottomin ilkiökään
Ei tehdä voisi.
LEONTES.
Sinut poltatan.
PAULINA.
Siit' en ma huoli; tulen virittäjä
Kerettiläinen on, ei tulen uhri.
Tyranniks teit' en sanoa ma tahdo,
Mut tämä julmuus vaimoanne kohtaan —
Kun muuta teill' ei ole todistusta
Kuin pelkkä luulo — tyranniuteen hiukan
Se vivahtaa, häväisee teitä, tekee
Maailman silmiss' ilkiöksi.
LEONTES.
Kautta
Vasallivalanne, pois, pois tuo vaimo!
Jos oisin tyranni, niin hän ei eläis;
Ja noin ei haastaa tohtisi, jos siksi
Mun tuntisi hän. — Ovest' ulos!
PAULINA.
Älkää
Mua täältä työntäkö, kyll' itse lähden.
Lastanne hoitakaatte, se on teidän.
Zeus sille suokoon ylevämpää mieltä. —
Pois kätenne! — Te, jotka hyväilette
Noin hänen hulluuttaan, te ette koskaan
Hänt' auttaa voi, ei, ainutkaan ei teistä.
Kas niin, hyvästi vaan, nyt minä lähden.
(Poistuu.)
LEONTES.
Petturi, tähän yllytit sa vaimos.
Mun lapseniko? Pois, pois! — Sinä, joka
Niin sitä hellittelet, ota pentu
Ja tulen syötäväks se heitä oiti.
Niin, sinä, juuri sinä! Vie se heti!
Tunnissa tieto tuo, ett' on se tehty,
Ja täysi todistus, tai omasi
Ja omaistesi hengen vien. Jos kiellät,
Vihaani ärrytellen, sano vaan se,
Niin omin käsin äpärän tuon aivot
Murskaksi lyön. — Vie se ja tuleen paiskaa!
Sa vaimos tähän yllytit.
ANTIGONUS.
En, herra;
Nää loordit, jalot ystävät, mun puhtaaks
Julistaa voivat.
1 HOVIHERRA.
Armollinen herra,
Hän syytön vaimonsa on tänne tuloon.
LEONTES.
Valehtelette kaikki!
1 HOVIHERRA.
Suvaitkaa
Parempaa meistä luulla; uskollisest'
Olemme teitä palvellehet; siitä
Tunnustus suokaa. Polvin rukoilemme —
Entisten palvelusten palkinnoksi
Ja tulevaisten — muuttakaa tuo päätös;
Verinen, kauhea se on ja varmaan
Vie turmioon. Me polvistumme kaikin.
LEONTES.
Ma höyhen olen joka tuulen viedä.
Nähdäkö täytyy mun, kuink' äpärä
Tuo polvistuu ja isäkseen mua kutsuu?
Ei, parempi nyt polttaa se kuin sitten
Kirota sitä. Mutta — jääköön eloon!
Ei sittenkään! —
(Antigonukselle.)
Käy tänne, sinä siellä;
Sa, joka puuhassa niin helläss' olit
Tuon kätilösi, Kaisa-rouvan kanssa
Äpärän pelastukseksi, — se on hän,
Niin totta kuin on partas harmaa — mitä
Tuon pennun hengest' uskallat sa?
ANTIGONUS.
Kaikki,
Min tehdä voin ja kunnia niin vaatii.
Jos muuta en, niin tämän: vähäisetkin
Vereni tähteet turvaks syyttömyyden
Ma uhraan; kaikki, minkä vaan ma voin.
LEONTES.
Sen kyllä voit. Tuon miekan kautta vanno,
Ett' täytät käskyni.
ANTIGONUS.
Sen vannon, herra.
LEONTES.
Siis kuule ja se tee; näet, vähimmässä
Jos vilpistelet, niin et yksin sinä,
Vaan herja vaimoskin on kuolon oma;
Nyt saa hän anteeksi. — Me käskemme siis
Vasallivalas nimess', että saatat
Pois tämän tyttöäpärän ja viet sen
Syrjäiseen, jylhään metsäseutuun, kauas
Rajoilta näiltä, ja sen sinne jätät,
Armotta aivan, omaan hoiteeseensa
Ja säiden valtaan. Outo sallimus
Sen tänne toi, siis oikein vaadin, että
Sen outoon korpeen viet, miss' sallimus
Sit' imettäköön tai sen tappakoon.
ANTIGONUS.
Sen totta teen; mut kyllä laupiaampi
Ois äkkisurma. — Tule, lapsiraukka,
Ylempi valta sääkset pankoon, korpit
Sua imettämään! Moista armon työtä
On tehneet sudetkin ja karhut, raivons'
Unohtaen. — Te onnellisemp' olkaa,
Kuin mitä sietää tekonne! — Ja siunaus
Julmuutta vastaan sua puoltakohon,
Hylätty lapsi-raukka!
LEONTES.
Min' en vieraan
Kakaraa ruoki.
PALVELIJA (tulee).
Herrani, vast'ikään
On Delphiin matkaajilta sana tullut:
Cleomenes ja Dion hyväll' onnell'
On kotiin palanneet ja maalle nousseet;
Koht' ovat täällä.
1 HOVIHERRA.
Tuopa arvaamatont'
On joutuisuutta.
LEONTES.
Päivää kolmekolmatt'
Olivat poissa; moinen kiire näyttää,
Ett' tahtoo suur' Apollo joutuun tehdä
Totuuden tiedoksi. Siis valmiit olkaa;
Neuvosto kokoon! Tuomionsa saakoon
Tuo valapatto. Yhtä julkinen
Kuin syytöskin, yht' ilmeinen ja vapaa
Myös olkoon tutkinto. Sydäntä vaivaa
Niin kauan kuin hän eloss' ompi. — Menkää
Ja tehkää, mitä käskin.
(Lähtevät.)
KOLMAS NÄYTÖS.
Ensimmäinen kohtaus.
Seutu sama. Erään kaupungin katu.
(Cleomenes ja Dion tulevat.)
CLEOMENES.
Suloist' on ilmanala, lauhaa sää
Ja saari viljava, ja templi voittaa
Kehutkin kaikki.
DION.
Ihaninta oli,
Hurmaavaa ihan, taivaiset nuo puvut —
Niin niitä nimittäisin — sekä pappein
Vakava arvoisuus. Ja uhritoimi,
Kuink' ylevää se, ylimaallist' oli
Ja pyhää!
CLEOMENES.
Entä huumaava tuo jyry
Ja oraakelin ääni, joka pauhas
Kuin herranvoima ja niin valtas aistit,
Ett' aivan menehdyin.
DION.
Jos matkan tulos
Niin suotuinen on kuningattarelle —
Sen taivas suokoon! — kuin se oli meille
Suloinen, hauska, joutuisa, niin toivo
On saavutettu.
CLEOMENES.
Suur' Apollo kaikki
Parhaaksi kääntäköön! Nuo juonet, joilla
Koetaan kuningatar syyhyn saada,
Mua eivät miellytä.
DION.
Noin kiivaat toimet
Tekevät selvän kaikesta tai lopun.
Kun tietoon tulee ennus, jonk' Apollon
Pääpappi tähän lukitsi, niin varmaan
Jotakin kummaa ilmaantuu. — Hoi! Tänne
Ravakat ratsut! Kaikki hyvin käyköön!
(Lähtevät.)
Toinen kohtaus.
Seutu sama. Oikeushuone.
(Leontes, hoviherroja, virkamiehiä ja oikeudenpalvelijoita tulee.)
LEONTES.
Tää toimitus, sen surulla ma myönnän,
Mun sydäntäni kalvaa: syytetty on
Kuninkaan tytär, puoliso, ja lisäks
Niin hellitty ja rakas. Älköön meitä
Tyranniks sanottako, kun näin suoraan
Vetoomme lakiin, joll' on täysi valta
Julistaa syyllisyys tai syyttömyys. —
Esille vanki!
OIKEUDENPALVELIJA.
Kuninkaan on tahto,
Ett' itse tänne oikeuden eteen
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com