programming in alice n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Programming in Alice PowerPoint Presentation
Download Presentation
Programming in Alice

Loading in 2 Seconds...

play fullscreen
1 / 41

Programming in Alice - PowerPoint PPT Presentation


  • 144 Views
  • Uploaded on

Programming in Alice. Chapter 2. Today’s Agenda. Designing a Program Writing Methods Executing Instructions Simultaneously Comments Tips for Setting Up an Initial Scene. Terminology. Algorithm – step by step structure to solve a problem

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Programming in Alice


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
    Presentation Transcript
    1. Programming in Alice Chapter 2

    2. Today’s Agenda • Designing a Program • Writing Methods • Executing Instructions Simultaneously • Comments • Tips for Setting Up an Initial Scene

    3. Terminology • Algorithm – step by step structure to solve a problem • Program – implemention of algorithm using a programming language • Instruction – an action to be performed • Pseudo code – loose set of instructions not tied to any program environment

    4. Steps in Creating Programs • Four step process • What is problem? • Design or plan ahead • Implement or write the program • Test to see if it works

    5. Scenario • Problem statement or story • Also called requirement specifications • In Alice consists of • World scene • Objects • Actions

    6. Scenario Provides Answers To • What story is to be told? • What objects are needed? • Primary objects • Background objects • What actions are to take place? • Become instructions in program

    7. Scenario: First Encounter • After traveling through space, a robot-manned craft just landed on a moon. • Robot sets up camera so scientists in Houston can view this historic event. • Camera view shows robot, lunar lander and nearby rocks. • Alien surprises robot when it peeks out from behind a rock. • Robot sees alien and walks over for closer look. • The alien is frightened and hides behind rocks. • Robot calls Houston to report alien

    8. Step 1: What is Problem? • What story will be told? • Humorous story about robot’s first encounter with an alien on a distant moon • What objects are used? • Robot, lunar lander, alien, lunar background • What actions take place? • Alien peeks out from behind rock • Robot turns head around & moves toward alien • Alien hides behind rocks • Robot sends message back to earth

    9. Pseudo Code • Lists of English worded steps to perform task • Provides algorithmic structure • Breaks problem down into smaller tasks • List all things that will be done in scene • Can make basic drawing to better illustrate scene you wish to create

    10. Pseudo Code Example Sketch

    11. Pseudo Code Scene • Not intended to be artistic • Can use simple circles, squares and lines • Label color of shapes • Just give idea of what scene will look like

    12. Create Initial World • Use Alice scene editor to add objects • Arrange objects in various poses • Capture screen as each successive scene is created for storyboard

    13. Pseudo Code Example • Do following steps in order • Alien moves up • Alien says "Slithy toves?" • Robot's head turns around • Entire Robot turns to look at alien • Do together • Robot moves toward alien • Robot legs walk • Alien moves down • Robot turns to look at camera • Robot’s head turns red to signal danger • Robot says “Houston, we have a problem!”

    14. Step 3: Pseudo Code Implementation • Translate pseudo code actions into program • Program • A list of instructions to have objects perform animation actions • When programming you need to be concerned with • Syntax – statement structure and punctuation • Alice takes care of this for you • You drag instruction to method editor • Semantics – meaning of statements • Sequence – order of programming instructions

    15. Translating the Design • Some pseudo code steps can be written as single instruction • Ex: robot turns to face alien • Other steps are composite actions that require more than one instruction • To make the robot legs walk, at least two robot legs must bend at a joint

    16. Writing Methods • What is a method? • Set of instructions • Create methods by dragging tiles from details pane into the Method Editor • These tiles are the instructions • Method Editor not available in Scene Editor mode my first method Method Editor

    17. Dragging Method Tile to Editor • To place instruction in method editor drag from details pane • Pop-up menu appears asking for direction, select one • Pop-up menu appears asking for distance amount • Example: move instruction • Arguments used in example • Distance amount (can predefine values or other (enter value with keyboard) • Direction Drag method to editor

    18. Method with Instruction Tiles • Methods execute the instructions (tiles) that are dragged into the Method Editor

    19. Terminology • Calling a method - executing a method • Parameter – tells method specifics of what to do • Argument –information sent to method • For method hare.move what direction to move? • Possibilities for direction parameter are up, down, left, right • How far to move is another argument to send move method • Passing arguments • A method is called with arguments sent to its parameters argument argument object method name editing tag

    20. Entering Custom Number • When other is chosen • A number pad pops up • Can enter number with keyboard • Click on number pad • Does not always work • Click Okay or Cancel when done • ‘/’ is for fractions instead of you manually calculating it

    21. Editing Tag • Holds optional arguments • What appears depends on the method called • Ex: Duration - amount of time for action to take place • Default - 1 second

    22. Duration Argument • Each instruction takes 1 second to execute by default • Can change time with duration option • Increase or decrease duration for realism • Increase to show movement over long distance and time • Decrease to speed up action • Synchronize objects together • Example: leg move in sync with lunar robot • Lunar robot moved 1 sec at time • Each leg needed to move forward and backward in 1 sec • Therefore move forward ½ sec and backward ½ sec

    23. Style Argument • Specifies how smoothly one movement instruction will blend into next one • Gently – begin and end gently • Abruptly – begin and end abruptly • Sometimes needed to transition well since gently takes too long • Begin gently – ends abruptly • End gently – begins abruptly

    24. Instructions (Methods) • Methods available to use are: • Move – forward, backward, up, down, left, right (in meters) • Turn – left, right, forward, backward (revolutions) • Roll – left, right (revolutions) • Resize – increase or decrease size • Say – put thought bubble over object • Turn to face – select who to turn and face

    25. Primitive Methods • All objects have common set of built-in methods for performing actions • These “primitive methods” get objects to move, turn, change size, etc • Seen in methods tab of details pane • See list in Table 2-1 (pp. 65-66) with explanation of each one dot notation: hare.move

    26. Control Statements • Instruction (action) sequence • Drag instruction to code editor • Sequential Action Block • Actions occur one after another • Simultaneous Action Block • Actions occur at same time Drag block into editor Do in order

    27. “Do in order” Structure • By default, instructions are executed one after the other in the order they appear in the Method Editor • It is better if you place instructions in “Do in order” block • Will be easier to move group of instructions if needed later

    28. The “Do Together” Structure • For simultaneous actions, drag“Do together” into the MethodEditor • Place the instructions you want to be executed simultaneously in the “Do together” block • Make sure the duration for allitems in “Do together” are same • Otherwise some will finish quicker than others

    29. Nesting • Sometimes a group of instructions need to be executed simultaneously • This is done by placing a “Do in order” block within a “Do together” block • Example has brother penguin turn head right and left at same time as sister penguin does • If all done together nothing would happen • Head would turn right and left at same time

    30. Create Program • Choose what sequence to execute instructions • At same time • Consecutively • Refer to pseudo code to find instruction order

    31. FirstEncounter Program

    32. Demonstrate Program • Demonstrate creating FirstEncounter

    33. Step 4: Testing • Important step in creating a program is to run it • To be sure it does what you expect it to do • Use an incremental development process • Write a few lines of code then run it • Write a few more lines and run it • Write a few more lines and run it • Allows finding many problems and fix them as you go • Called debugging – find bugs or errors in program

    34. Comments • Makes the code understandable • Not all combination of instructions are immediately obvious • Explains purpose of segment of program to human reader • Helps • You read program later • Others when determining what program does • Alice ignores comments when executing program

    35. Comment Example Comment //comment tile

    36. Can set initial position of objects in scene Select object in “Object Tree” then select a method Tips for Setting Up Initial Scene

    37. Moving Object to Center of World • Use move tomethod and choose entire world as method’s argument • Places object’s center point at world’s center point of (0, 0, 0) • This drives hare’s lower body into ground • Center of gravity of hare is in abdomen • Useful when lose object in scene or as starting point

    38. Positioning Character’s Arms

    39. Tips for Setting Up Initial Scene • Positioning objects a specified distance apart • Ex: position teapot’s center point ½ meter to right of plate’s center point • Move teapot object so its center point is same location as plate’s center point • Set pointOfView in properties to position: 0,0,0 • Place the object’s center point at the world’s center point of (0, 0, 0) • Use move method for teapot, choose rightthen ½ meter under amount

    40. Moving Camera To An Object • Right-click the object and choose Camera get a good look at this • Camera moves to a position so the object is in plain view

    41. Homework • Read chapter 2 • Do tutorials • Tutorials 2-1, p 62 • Tutorials 2-2, p. 67 • Tutorials 2-3, p. 82 • Tutorials 2-4, p. 89 • Tutorials 2-5, p. 98 • Answer questions in handout • Do lab assignments after handing in answered questions • Due one week after assigned with 1 week grace