An Introduction to Programming Using Alice 2 2

  • Slides: 50
Download presentation
An Introduction to Programming Using Alice 2. 2, Second Edition Chapter 6 Text and

An Introduction to Programming Using Alice 2. 2, Second Edition Chapter 6 Text and Sound

Objectives After finishing this chapter, you should be able to: • Provide a brief

Objectives After finishing this chapter, you should be able to: • Provide a brief definition of the following terms: – Text, dialog balloon, thought bubble, personification, typeface, font, breakpoint, billboard, HSB, RGB, and tessellation • List and describe the different ways to add text to an Alice world • Use the say and think methods to add text messages to an Alice world An Introduction to Programming Using Alice 2. 2, Second Edition 2

Objectives (cont’d. ) • Place messages in a special zone below Alice’s playing world

Objectives (cont’d. ) • Place messages in a special zone below Alice’s playing world window with the print instruction • Add 3 D text objects to an Alice world • Create a billboard from a picture file and manipulate it in an Alice world • Add sound to an Alice world An Introduction to Programming Using Alice 2. 2, Second Edition 3

Adding Elements of Language to an Alice World • Show text in an Alice

Adding Elements of Language to an Alice World • Show text in an Alice world by: – Using the say and think methods to show an object’s speech and thoughts – Using the print instruction to show messages in a special zone below the playing world window – Adding 3 D text as an Alice object – Placing a picture file with an image of text in an Alice world as a billboard An Introduction to Programming Using Alice 2. 2, Second Edition 4

The say and think Methods • Dialog balloon – Shows words that are supposed

The say and think Methods • Dialog balloon – Shows words that are supposed to have been spoken by an object • Thought bubble – Shows words that reflect an object’s thoughts • Personification – Process of giving human qualities to inanimate objects An Introduction to Programming Using Alice 2. 2, Second Edition 5

An Introduction to Programming Using Alice 2. 2, Second Edition 6

An Introduction to Programming Using Alice 2. 2, Second Edition 6

An Introduction to Programming Using Alice 2. 2, Second Edition 7

An Introduction to Programming Using Alice 2. 2, Second Edition 7

The Print Instruction • Can be used to: – Display messages or the value

The Print Instruction • Can be used to: – Display messages or the value of variables and parameters in a special text zone at the bottom of a running Alice world • Often used to: – Show someone the value of a variable while a world is playing • Breakpoint – Spot in a computer program just before or just after some action occurs An Introduction to Programming Using Alice 2. 2, Second Edition 8

An Introduction to Programming Using Alice 2. 2, Second Edition 9

An Introduction to Programming Using Alice 2. 2, Second Edition 9

An Introduction to Programming Using Alice 2. 2, Second Edition 10

An Introduction to Programming Using Alice 2. 2, Second Edition 10

3 D Text in Alice • 3 D text – Implemented as its own

3 D Text in Alice • 3 D text – Implemented as its own object – Can be used to communicate with the user or as an integral element of an Alice world – Often used for titles • Local Gallery – Contains a folder to create 3 D text objects • In Alice, you cannot: – Create an instance of an object in a world while the world is running An Introduction to Programming Using Alice 2. 2, Second Edition 11

An Introduction to Programming Using Alice 2. 2, Second Edition 12

An Introduction to Programming Using Alice 2. 2, Second Edition 12

Picture Files as Alice Billboards • Billboard – Flat two-dimensional object with length and

Picture Files as Alice Billboards • Billboard – Flat two-dimensional object with length and width, but no depth – Objects that can be manipulated with primitive methods like move, turn, and roll • Common imaging formats – Graphics Interchange Format (GIF), the Joint Photographic Experts – Group format (JPG) An Introduction to Programming Using Alice 2. 2, Second Edition 13

An Introduction to Programming Using Alice 2. 2, Second Edition 14

An Introduction to Programming Using Alice 2. 2, Second Edition 14

Picture Files as Alice Billboards (cont’d. ) • Common imaging formats (cont’d. ) –

Picture Files as Alice Billboards (cont’d. ) • Common imaging formats (cont’d. ) – Bitmapped file format (BMP) – Tagged Image File Format (TIF) – Portable Network Graphics (PNG) format • Many graphics-manipulation programs: – Allow a user to create and save text as an image file An Introduction to Programming Using Alice 2. 2, Second Edition 15

An Introduction to Programming Using Alice 2. 2, Second Edition 16

An Introduction to Programming Using Alice 2. 2, Second Edition 16

Sounds in Alice • Each object in an Alice world: – Has a primitive

Sounds in Alice • Each object in an Alice world: – Has a primitive play sound method that can be used to play a sound file • Sound files are most often used in Alice worlds to: – Add special effects, such as the sound of a doorbell – Play background music as a scene unfolds An Introduction to Programming Using Alice 2. 2, Second Edition 17

An Introduction to Programming Using Alice 2. 2, Second Edition 18

An Introduction to Programming Using Alice 2. 2, Second Edition 18

Tutorial 6 A – Using the say and think Methods • Open the hello

Tutorial 6 A – Using the say and think Methods • Open the hello world Alice world created in Tutorial 1 C • If you cannot see the instructions in world. my first method: – Select the world tile in the Object tree and the methods tab in the Details area – Click the edit button • Click the word more following the phrase Hello, Dr. Kernighan! in the second say instruction • Select font. Size, then 30, and then save An Introduction to Programming Using Alice 2. 2, Second Edition 19

An Introduction to Programming Using Alice 2. 2, Second Edition 20

An Introduction to Programming Using Alice 2. 2, Second Edition 20

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To change values: – Click the word more after Hello, World! in the say Hello, World! instruction – Select bubble. Color – Select yellow as the new bubble. Color – Click the word more after the bubble. Color parameter and change the text. Color to brown – Play the world An Introduction to Programming Using Alice 2. 2, Second Edition 21

An Introduction to Programming Using Alice 2. 2, Second Edition 22

An Introduction to Programming Using Alice 2. 2, Second Edition 22

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To describe the color of a pixel: – Click the bubble. Color parameter in the say Hello, World! instruction tile and select other – Pick a light green color from those available on the palette and click OK – Click the bubble. Color parameter and select other again – Click the RGB tab – Select the HSB tab – You can enter numbers in the input boxes for hue, saturation, and brightness An Introduction to Programming Using Alice 2. 2, Second Edition 23

An Introduction to Programming Using Alice 2. 2, Second Edition 24

An Introduction to Programming Using Alice 2. 2, Second Edition 24

An Introduction to Programming Using Alice 2. 2, Second Edition 25

An Introduction to Programming Using Alice 2. 2, Second Edition 25

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To

Tutorial 6 A – Using the say and think Methods (cont’d. ) • To describe the color of a pixel (cont’d. ): – Click the S (for saturation) radio button – Click the B (for brightness) radio button – The text. Color parameter is changed the same way as the bubble. Color parameter – Experiment with setting the colors and playing the world An Introduction to Programming Using Alice 2. 2, Second Edition 26

Tutorial 6 A – Using the say and think Methods (cont’d. ) • Change

Tutorial 6 A – Using the say and think Methods (cont’d. ) • Change the typeface by changing the font. Name parameter – Click the word more after the text in the bunny say Hello, Dr. Kernighan! Tile – Select font. Name from the menu that appears, and then select other – Type Times New Roman as the new font. Name, and then click OK – Play the world An Introduction to Programming Using Alice 2. 2, Second Edition 27

An Introduction to Programming Using Alice 2. 2, Second Edition 28

An Introduction to Programming Using Alice 2. 2, Second Edition 28

Tutorial 6 B – The Print Instruction • Print the distance between two penguins

Tutorial 6 B – The Print Instruction • Print the distance between two penguins in the nervous penguin world – Open the nervous penguin world that was created as part of Tutorial 5 B – Select the nervous. Penguin tile in the Object tree and the methods tab in the Details area – Click the edit button next to the react method tile on the methods tab – Drag a print instruction tile from the bottom of the Editor area and drop it in the method An Introduction to Programming Using Alice 2. 2, Second Edition 29

Tutorial 6 B – The Print Instruction (cont’d. ) • Print the distance between

Tutorial 6 B – The Print Instruction (cont’d. ) • Print the distance between two penguins in the nervous penguin world (cont’d. ) – Select text string and an Enter Text String window will appear – Type begin reaction and click the OK button – Play the world and use the arrow keys to control the moving penguin An Introduction to Programming Using Alice 2. 2, Second Edition 30

Tutorial 6 B – The Print Instruction (cont’d. ) • Display the value of

Tutorial 6 B – The Print Instruction (cont’d. ) • Display the value of the index variable – Open the triple jump random world from Tutorial 5 A – If you cannot see world. my first method in the Editor area, select the world tile in the Object tree and the methods tab in the Details area – Click the edit button – Drag the print instruction from the bottom of the Editor area and drop it in world. my first method – Select object, then expressions, and then determinant – Play the world An Introduction to Programming Using Alice 2. 2, Second Edition 31

An Introduction to Programming Using Alice 2. 2, Second Edition 32

An Introduction to Programming Using Alice 2. 2, Second Edition 32

Tutorial 6 C – Three-Dimensional Text • Add an opening title using the object

Tutorial 6 C – Three-Dimensional Text • Add an opening title using the object gallery – Open the triple jump world created in Tutorial 2 B – Click the ADD OBJECTS button to enter Scene Editor mode – Click the Create 3 D Text tile – Click the OK button – Right-click the 3 D Text tile in the Object tree and rename the tile opening. Title – Click the opening. Title tile and then click the properties tab An Introduction to Programming Using Alice 2. 2, Second Edition 33

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Add an opening title using

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Add an opening title using the object gallery (cont’d. ) – Click the words The quick brown fox next to the text property on the properties tab and change the text to Triple Jump – Press the Enter key after you have finished changing the text An Introduction to Programming Using Alice 2. 2, Second Edition 34

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use the font property –

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use the font property – Click the button next to the font tile on the properties tab in the Details area – Click the typeface button, and a scrolling menu with the names of all the typefaces currently available will appear – Take a moment to try a few of the typefaces from the list An Introduction to Programming Using Alice 2. 2, Second Edition 35

An Introduction to Programming Using Alice 2. 2, Second Edition 36

An Introduction to Programming Using Alice 2. 2, Second Edition 36

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use primitive methods to position

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use primitive methods to position the opening. Title title – Right-click the opening. Title tile in the Object tree, and select methods – Select the opening. Title move method, select up, and then select 2 meters – If 2 meters is not an available option, select other and type 2 in the Custom Number dialog box, and then press Enter An Introduction to Programming Using Alice 2. 2, Second Edition 37

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use primitive methods to position

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Use primitive methods to position the opening. Title title (cont’d. ) – Right-click opening. Title in the Object tree, select methods, and run the opening. Title turn to face method to make the text face the camera – If the entire title does not fit in the world window, rightclick opening. Title in the Object tree – Select methods – Run the opening. Title move method to move the title backward a few meters An Introduction to Programming Using Alice 2. 2, Second Edition 38

An Introduction to Programming Using Alice 2. 2, Second Edition 39

An Introduction to Programming Using Alice 2. 2, Second Edition 39

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Make the title invisible –

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Make the title invisible – Select the world tile in the object tree and the methods tab in the Details area – Click the edit button next to my first method – Drag a copy of the Wait instruction tile from the bottom of the Editor area and drop it into world. my first method as the first instruction in the method – Set the duration to 2 seconds An Introduction to Programming Using Alice 2. 2, Second Edition 40

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Make the title invisible (cont’d.

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Make the title invisible (cont’d. ) – Click the opening. Title tile in the object tree, and then click the properties tab and drag a copy of the is. Showing property tile into the method – Select false – Play the world and watch what happens An Introduction to Programming Using Alice 2. 2, Second Edition 41

An Introduction to Programming Using Alice 2. 2, Second Edition 42

An Introduction to Programming Using Alice 2. 2, Second Edition 42

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Cause a fade to occur

Tutorial 6 C – Three-Dimensional Text (cont’d. ) • Cause a fade to occur by using the opacity property – Right-click the opening. Title set is. Showing to false instruction tile – Select delete – Select the opening. Title tile in the object tree and the properties tab in the Details area – Drag a copy of the opacity property tile into the method below the Wait instruction – Select 0%: invisible – Play the world An Introduction to Programming Using Alice 2. 2, Second Edition 43

Tutorial 6 D – Picture Files as Alice Billboards • Put the picture file

Tutorial 6 D – Picture Files as Alice Billboards • Put the picture file someplace it can easily be found inside Alice • Start a new Alice world with a grass template • Click File on the menu bar, and then click Make Billboard • Find the directory where you stored the file Mona Lisa. jpg • Click the name of the file, and then click the Import button An Introduction to Programming Using Alice 2. 2, Second Edition 44

Tutorial 6 D – Picture Files as Alice Billboards • Texture map that can

Tutorial 6 D – Picture Files as Alice Billboards • Texture map that can be used for other objects – Click the ground tile in the Object tree, and then the properties tab in the Details area – Click ground. Grass. Texture next to the skin texture tile – Select the skin texture for the ground – Save the world as tessellation sample An Introduction to Programming Using Alice 2. 2, Second Edition 45

An Introduction to Programming Using Alice 2. 2, Second Edition 46

An Introduction to Programming Using Alice 2. 2, Second Edition 46

Tutorial 6 E – Sound in Alice Worlds • Start a new Alice world

Tutorial 6 E – Sound in Alice Worlds • Start a new Alice world with a grass template • Click the ADD OBJECTS button to enter Scene Editor mode and add a Chicken to the world from the Animals folder • Click the DONE button after you have added the Chicken to the world • Click the create new event button in the Events area and select When a key is typed • Click the any key box in the tile for the new method and select Space from the menu that appears An Introduction to Programming Using Alice 2. 2, Second Edition 47

Tutorial 6 E – Sound in Alice Worlds (cont’d. ) • Make sure that

Tutorial 6 E – Sound in Alice Worlds (cont’d. ) • Make sure that Chicken is selected in the Object tree, and then click the methods tab • Drag a copy of the Chicken play sound tile from the methods tab and drop it in the new event in place of the word Nothing • Select chicken • Play the world • Click more to: – Adjust the duration and volume of the sound An Introduction to Programming Using Alice 2. 2, Second Edition 48

Summary • You can show text in an Alice world by: – – Using

Summary • You can show text in an Alice world by: – – Using the say and think primitive methods Using the print instruction Adding 3 D text as an Alice object Placing a picture file with an image of text in an Alice world as a billboard • Sound files containing verbal messages can be added to an Alice world • The say and think methods: – Can be used with every object in Alice An Introduction to Programming Using Alice 2. 2, Second Edition 49

Summary (cont’d. ) • Print instruction can be used to: – Display messages or

Summary (cont’d. ) • Print instruction can be used to: – Display messages or the value of variables and parameters in a special text zone at the bottom of a running Alice world • 3 D text is implemented in Alice as its own object • Picture files can be added to an Alice world as a billboard • Each object in an Alice world has a primitive play sound method • Several sound recordings are included with Alice An Introduction to Programming Using Alice 2. 2, Second Edition 50