programming with alice - department of computer sciences
TRANSCRIPT
![Page 1: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/1.jpg)
Programming With AliceMike Scott, Lecturer, Computer Science Department
![Page 2: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/2.jpg)
2
Alice• Alice is a simple programming
environment that allows you to create 3D movies.
• If not logged in:– move mouse to wake up computer– click "Logon" button– use your provided login id and password (FB01 –
FB60), password, byte– click the "OK" button– Select Start -> Programs -> Programming ->
Alice– It takes a minute to load
![Page 3: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/3.jpg)
3
Creating an Alice Program
• You can either try to create a movie on your own
• OR the handout describes the steps necessary to build an Alice program with a simple version of the charades scene from Finding Nemo
• Any questions, please ask!
![Page 4: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/4.jpg)
4
An Extended Example
• These slides step you through an extended example to learn the basics of programming in Alice
• To do your movie you will need to generalize some of these things.– apply them in a slightly different way
• Feel free to try and do something else
![Page 5: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/5.jpg)
5
Getting Started
• Close the opening splash screen by x-ing it out.
![Page 6: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/6.jpg)
6
Create an Alice World
• Start Alice• Select “File”, “New World”• Click on Water picture
• Click on “Open”
![Page 7: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/7.jpg)
7
Find Fish objects
• Click on “add objects”
• Scroll over to “people” folder and click on it
![Page 8: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/8.jpg)
8
Add Blueminnow to World
• Click on Blueminnow(for Dory) and you will see:
• Click on “Add instance”
• Blueminnow appears in world
• Can also add my clickingon object and dragging intoscene
![Page 9: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/9.jpg)
9
Add Pinkminnow to world and adjust• Click on Pinkminnow
(Marlin) and add to the world
• Click on arrow key• Click and hold on fish to
move.• Click on move up and
down to move fish up and down. (Okay if not in water.)
![Page 10: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/10.jpg)
10
Position fish and camera so world should look something like this:
Not sure why placed so high initially!
![Page 11: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/11.jpg)
11
Add Dummy Object• When setting up a scene it is often
necessary to move camera and then return to original position.
• Click the more controls button
• Select the drop dummyat camera
![Page 12: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/12.jpg)
12
Add More Fish• Add 5 Goldfish to world to be the
school of fish• Clicking and dragging into scene works
better.
![Page 13: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/13.jpg)
13
Move School of Fish Down• In our movie the school of fish
will appear later. We want them to disappear now.
• Could use the move down arrow to move below surface but we want them all to move down same amount.
![Page 14: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/14.jpg)
14
Move School of Fish Down • Select each Goldfish from Object Tree and drag into scene
• From pop up menu choose move, then down, then 1 meter
![Page 15: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/15.jpg)
15
Position Dory and Marlin
• Move Dory and Marlin a little to the left as looking at the scene and rotate them
![Page 16: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/16.jpg)
16
Setup Done!• All goldfish are below surface
of water, but still part of world.
• Could move camera down to see goldfish.
• To return camera to start position drag camera into scene and select moveTocommand and select dummy from menu and then select the orient to command to return camera to original position
![Page 17: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/17.jpg)
17
Save World
• Select the file option from the menu and the select Save world: File -> Save World
• Type in a name such as: nemo and then “save”
• Alice will remind you to save your work every 15 minutes
![Page 18: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/18.jpg)
18
Now Ready to program!
• Click on done• Should now see myFirstMethod
![Page 19: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/19.jpg)
19
• This is the object tree, a list of all your objects in the world
• Now click on the word “pinkminnow” to highlight it
• You should see methods below it (things the snowman can do) such as move, turn, roll, …
Make fish move
![Page 20: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/20.jpg)
20
Add code to move fish• Click left mouse button on pinkminnow move AND HOLD IT DOWN, then Drag it over to the World.my first method and release the mouse button
![Page 21: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/21.jpg)
21
Move fish
• From the pop up menu select forwardand then other
• In the calculator thatpops up type in 0.5
• You have added acommand!
![Page 22: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/22.jpg)
22
Run the Program
• Click on Play
Close the movie player by x-ing it out when you are finished to go back to programming.
![Page 23: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/23.jpg)
23
Have Dory move• Select the blueminnow in the object
tree and drag over a move command for it. Place it after the command for the pickminnow
• Code is now:
• Play again
![Page 24: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/24.jpg)
24
Sequential Execution
• Commands in the program are carried in the order they appear.
• Alter order of movement so Dory moves first and play movie. Click and drag commands in the My first method screen– See the difference?
![Page 25: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/25.jpg)
25
Movement
• All movement for Alice objects is based on their own frame of reference.
• Moving fish forward based on what they think is forward
• Blue: forwardRed: rightGreen: up
![Page 26: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/26.jpg)
26
Duration• Can change duration of actions by
clicking on more drop down menu in command and picking duration.
![Page 27: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/27.jpg)
27
Changing amounts
• Can also change amounts by clicking on drop down menu for command.
• Change movement from 0.5 to 0.75 meters
• Play movie
![Page 28: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/28.jpg)
28
Move together
• To get the fish to move together drag a Do together command from the bottom of the window into the program
![Page 29: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/29.jpg)
29
Move together
• Drag both move commands into the Do together block
• Play!
• Order inside do together does not matter
![Page 30: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/30.jpg)
30
turn to face• Click on pinkminnow to see
methods• Select the turn to face
method from lower in list and drag into program after the move commands
• Select blueminnow from the popup
• Play!
![Page 31: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/31.jpg)
31
Have fish talk
• Have fish talk to each other.• Drag say command for pinkminnow
and pick other from menu.• Type in question.
• Select blueminnow and type in response: What's Syndey?
![Page 32: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/32.jpg)
32
Program so far
• Play!
![Page 33: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/33.jpg)
33
Adding methods
• Program getting longer. • We are going to have Marlin react to
Dory forgetting what Sydney is.• We are going to repeat his reaction
twice• To try and keep program simple and
to reuse commands we are going to make a new method for Marlin,
![Page 34: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/34.jpg)
34
Add a New Method• Select pinkminnow in object tree• In method tab click the create new method button.
• Name new method go crazy
![Page 35: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/35.jpg)
35
Go crazy• when creating new method a blank
program screen pops up
• Add commands to this method• Have Marlin turn around 3 times to
the left in 1.5 seconds, then 3 times to the right in 1.5 seconds while saying NO!!!! at the same time
![Page 36: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/36.jpg)
36
Completed go crazy
![Page 37: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/37.jpg)
37
Call go crazy• Select the My first method tab to go
back to the main program• Call the go crazy method• then have Marlin say "How could you
forget Sydney?"• then call the go crazy method again
![Page 38: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/38.jpg)
38
Calling new method
![Page 39: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/39.jpg)
39
Move School of Fish Up• Now have the school of
goldfish appear.• They will all have to move up 1
meter at the same time.• When a method involves more
than one object it should be a world level method. (go crazy was a class level method.)
• Select world from object tree and create new method from the object tab
![Page 40: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/40.jpg)
40
World Level Method• Call the new method
school appears.• Add a do together
block and a command to move each of the goldfish up 1 meter
• Call the method in my first method
• Play!
![Page 41: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/41.jpg)
41
Get Attention• The leader of thge
school of fish want sto get the attention of Dory and Marlin
• He is going to move forwards and backwards 7 times quickly while saying "We know how to get to Sydney!"
![Page 42: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/42.jpg)
42
Repeated Actions• Create a method for the goldfish at the
front of the school named get attenetion• One way would be to use multiple moves as
shown, but don't do this!
![Page 43: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/43.jpg)
43
Loops• Previous approach is cumbersome• Instead, use a loop!• Drag Loop from bottom of commands to do together in get attention method
• Set number of times to 7 byusing other choice
![Page 44: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/44.jpg)
44
Loop• Now add a single move
forward and backward command to inside the loop.
• Call get attentionmethod in my first method
• Play!• Make sure times
match for say and total movement back and forth. 2.8 seconds
![Page 45: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/45.jpg)
45
Saving new classes and objects• Creating the get attention method for
one goldfish does not give the other goldfish that method.
• But we could save a new class with the get attention method and then add objects of that new, smarter type to our program.
![Page 46: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/46.jpg)
46
Saving New Classes• right click on
goldfish in object tree with get attention method and select save object
• Name new class Smart Goldfish
![Page 47: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/47.jpg)
47
Using New Classes
• To add objects of the new type to a world go to the add objects window
• Select file from the top menu and Import
• Browse to the location of the file and select it. A copy will be added to the world
• This feature can be used to allow people to work on different parts of a world / movie.
![Page 48: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/48.jpg)
48
Charades!• Create new world level method named
charades• Start by having the lead goldfish say
"Guess what we are and we will tell you how to get Sydney!"
![Page 49: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/49.jpg)
49
Changing Properties in the Program• The school of fish are going to
pretend to be a propeller.• This can be done easily by
changing the vehicle property of the fish
• Select each fish besides the center fish from the object tree
• Select the propertiestab
• Drag vehicle property into charades method and change to goldfish at center
![Page 50: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/50.jpg)
50
Change Vehicle Property
• Select entire Goldfish• Repeat for all the
other goldfish except the one at the center of the group
![Page 51: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/51.jpg)
51
Effect of Vehicle• Now that the center
goldfish is the vehiclefor all the other
goldfish when it moves the other goldfish move as if they were attached to that goldfish
• In charades method have center goldfish rotate around 7 times
• Call charades from my first method and PLAY!• Other properties can be changed as well (Color,
isShowing, opacity)
when this goldfish movesothers move as if attached
![Page 52: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/52.jpg)
52
Completed charades method
![Page 53: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/53.jpg)
53
My first method so far
![Page 54: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/54.jpg)
54
Affecting subparts• Go back to the get
attention method for the lead goldfish
• We want the goldfish to move its tail while going back and forth
• In the object tree select the lead goldfish and expand the object
![Page 55: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/55.jpg)
55
Affecting Subparts• Most objects have subparts• The goldfish has a tail and right and left
fins• subparts can be given commands just like
the whole object• Add a Do in order block to the inside of
the do together block in get attenetion
![Page 56: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/56.jpg)
56
Affecting subparts• In the object
tree select the lead goldfish's tail
![Page 57: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/57.jpg)
57
Moving the Tail• Add commands in the do together to move
the turn the tail left .1 revolutions• Then a loop to move right and left .2• Then right .1• Make durations .1 seconds• To make more realistic change style to abruptly
![Page 58: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/58.jpg)
58
Completed get attention Method
![Page 59: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/59.jpg)
59
Events• Events are parts of the program that can
respond to user input• Initially only event is when world starts
do the my first method method
![Page 60: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/60.jpg)
60
Add an Event
• Click the create new event button
• From the pop up menu select when a key is typed
![Page 61: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/61.jpg)
61
Change Event• Result of creating
new event show• Use drop down
menu to change any key to letter A
![Page 62: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/62.jpg)
62
Change Event Handler• Select goldfish with get attention method
• Drag the get attentionmethod to replace the nothing in the event
• Dragging and dropping can be used to replace many thing in Alice. Green means it is okay to replace!
![Page 63: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/63.jpg)
63
Finished Event
• Now, whenever program is playing and A key is pressed get attention will be carried out!
• Play and wait until movie plays out then try the event
![Page 64: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/64.jpg)
64
Add 3D Text• Go to the add
objects screen• Go to end of
objects gallery to the add 3d text folder and click on it
![Page 65: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/65.jpg)
65
Add 3d Text• Type in message to show at end of
movie and press okay• Rotate 3d text so it faces camera
![Page 66: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/66.jpg)
66
Make 3d Text Invisible• Go back to programming screen• Change property of 3d text to make its
opacity 0. (Don't drag into program just change it)
![Page 67: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/67.jpg)
67
Make 3d Text Visible• Next drag opacity property into end of
my first method to change to 100%• Play!!!
![Page 68: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/68.jpg)
68
Add a Billboard• Download an image
of the city of Sydney from the web and store it on your computer
• From the File option in the menu select Make Billboard
![Page 69: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/69.jpg)
69
Add a Billboard• Browse to the
location of you image and select it.
• Once added the billboard can be moved, resized, given commands, and have its properties altered just like other objects
![Page 70: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/70.jpg)
70
Swim to Sydney• Move Sydney billboard
to background• Change opacity to 0• Add commands for
Dory and Marlin to guess and goldfish to direct them to Sydney
• Have Sydney appear and fish swim towards it
![Page 71: Programming With Alice - Department of Computer Sciences](https://reader031.vdocument.in/reader031/viewer/2022021022/620495b54b1be21e4726f6cf/html5/thumbnails/71.jpg)
71
Add Sound• Add sound to world• Select world in
object tree• Select properties
tab• click import sound
button (wav or mp3)• drag sound into
program to play