Alice Alice is a programming language that allows creating 3D-animations. It is designed to teach how to program a computer, but in a much different way than with most other programming languages. First you won’t have to remember special words or syntax. Then you will not be asked to solve obscure problems. Instead you will create short animations, and if we get far enough simple interactive games. To be honest, the animations will not be of professional quality but many students before you have shown that this is a teaching tool that allows them to make full use of their creativity while at the same time learning important programming concepts. You will have some homework assignments in which you need to use the software. If you want to work on these assignments on your own computer you can download Alice from http://alice.org/index.php?page=downloads/download_alice2.2. Choose the alternate downloads with the Alice textbook Worlds. If you do not have Alice on your computer, you can use the Math lab computers to complete your homework. A few things to know before working with Alice: • You cannot open an Alice file by double-clicking it. You need to open Alice and open the file through Alice. • Alice is a great program but it is not perfect. It tends to freeze sometimes. Save often your programs so you will not lose all your work if this happens to you. Section 1: Storyboards (PowerPoint presentation: StoryBoardDesign) Programmers write programs to solve problems. The first steps of solving a problem is to make sure we understand well the problem and then to design a solution. Once we have the design we can write code, that is write the solution in the special programming language used by the programmer. When programming with Alice these stages will correspond to stages used by professionals in animation studios. Understanding the problem means having a clear scenario, i.e. a story to tell. The design will be expressed by a series of frames, called storyboards, which show the major steps in the story. The frame contains an image (it can be rather crude) showing the scene at that point of the story and a brief text describing the action. (See the PowerPoint entitled StoryBoardDesign for an example. ) For those of us who feel too artistically challenged for the traditional animation storyboard, the design can be a textual storyboard. In this case, the actions are described in brief concise sentences. Rather than being written as the scenario in paragraph style, the text is formatted in such a way that the order and the logic of the actions is made very clear. This will make more sense as our design get a little more complex. Here an example of a textual storyboard. Section 2: Setting up the initial scene Before we can program an animation we need to set up the stage. In Alice this will mean setting up the initial scene. We will choose a template, and add and position characters and objects in this template. The PowerPoint SettingUpWorlds shows the tools used to set up the initial scene. Section 3: From Storyboards to Code (PowerPoint presentation: StoryBoard to Code) Once we have our design, i.e. our storyboard, and created the initial scene, we are ready to write the code to animate the characters. As shown clearly by the storyboard the story can be decomposed in several actions. Moreover, we can see that some actions are specific to a character and could possible be reused in other situations. For example, in our dragon and princess story the dragon takes off. This action involves only the dragon and it is something we might want to reuse for future dragons. In the PowerPoint StoryboardToCode, we give the details how to make the dragon take off. We write some pieces of code, called methods that make the dragon perform given actions. • flapRightWing: it is used to make the dragon flap its right wing. • flapLeftWing: it is used to make the dragon flap its left wing. • flapWings: its is used to make the dragon flap both wings at the same time. To write it, we call the methods flapRightWing and flapLeftWing. • takeOff: this method allows the dragon to take off. To write it, we call the method flapWings. These methods are methods created for the dragon (they are called class-level methods) because they are specific to the dragon and do not involve any other object or character in the World. When you create a method, you first give a name to the method, and then you move to the editor window the tiles that tell what the method does. For example the method flapLeftWing might look as in Figure 1. This is similar to writing a recipe in a recipe notebook. But in the same way that writing a recipe and looking at it in the notebook does not get you much closer to a nice meal, writing a method definition and seeing it in the editor window won’t animate your characters. The method will “act” only if it is called. For example, in Figure 2 the method takeOff is called in my first method. If we click on Play, every action included in the definition of the method takeoff will be executed, including any call to other methods (here a call to the method flapWing). Figure 1- flapLeftWing Figure 2- my first method Rules to remember: 1. If an action of the storyboard involves only one character (or object) in the World, create a class- level method for this action. 2. If the action is somewhat complex, it is a good idea to decompose it in several methods. 3. A method will not execute (“play”) if it is not called. Saving a new class Once we have written method to allow the dragon to take off and to fly, we can save if as a new class that can be reused in other word. We need to change its name, for example to flyingDragon and save the class. The file will have the extension .a2c while files that contain Alice worlds have the extension .a2w. A demo on how to save a class and how to import the object in a new world is included at the end of the pdf-PowerPoint presentation StoryboardToCode. Section 4: Loops, built-in functions and parameters (PowerPoint presentation: FunctionsAndLoops) We now know how to give simple instructions to an object. We have used two constructs: • Do in order: the instructions are executed sequentially, i.e., one after the other in the order they are written. • Do together: the instructions are executed at the same time. Often we want a given instruction or a given set of instructions to be executed multiple times. For example if we know how to make a character take one step, making the character walk would require taking one step repeatedly. If we made a method to make the dragon fly forward one meter, we can repeatedly call that method to make the dragon fly to the princess. A simple way to repeat an instruction is of course to call it several times in a “Do in order” block. See Figure 3. But this is not always convenient (suppose we want to repeat the instruction 100 times!). Alice and all other programming languages provide repetition structures to indicate that an instruction or a set of instructions need to be repeated. The simplest structure in Alice is the Loop. We can replace the code in Figure 3 by the code shown in Figure 4. Figure 3 Figure 4 The set of instructions that is within the body of the loop (delimited in green) will be repeated the number of times indicated next to the word Loop. A problem that arises often is that we do not know exactly how many times the “loop” must execute. For example, the number of times the dragon must fly one meter depends on how far it is from the princess. Alice can answer the question “how far from the princess is the dragon”? Answers to such questions are given by built-in functions. We have used one tab of the object’s details area of the Alice interface: the method tab. Another tab is the function tab (see figure 5). Functions provide information about an object, such as its size and its position relative to other objects in the world. Functions return values of certain data types. For example the distance functions will return numbers while the function “is larger than” will return a Boolean value, which means a value that is either true or false. Next to the word “Loop”, you are expected to write a number. You may use any function that returns a number instead of an actual number value. See Figure 6. Figure 5 To write the Loop shown on left, first write it with any number (1, 2, 3…) in place of the function. Then drag in the function and drop it over the number. If you try to use a function that does not return a Figure 6 number in a place where a number is expected (such as behind Loop), Alice does not allow you to drop the function: the square around the function remains red. Methods with parameters The code shown in figure 6 could be the code for a method called flyToPrincess and it works well. The only disadvantage of this method is that it is very specialized. It can be used only to make the dragon fly to the princess, and just to the given princess, called princess in this world.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages9 Page
-
File Size-