1 / 21

Programming in Alice

Programming in Alice. Chapter 2 Part 2. Events Editor. Identifies what method is executed (run) when the “ Play ” button is hit. Deleting Instructions. Right-click the instruction and select delete Drag the instruction tile to the trash can. Copying Instruction.

medford
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming in Alice Chapter 2 Part 2

  2. Events Editor Identifies what method is executed (run) when the “Play” button is hit

  3. Deleting Instructions • Right-click the instruction and select delete • Drag the instruction tile to the trash can

  4. Copying Instruction • Right-click the instruction and select make copy • Drag the instruction tile to the clipboard • When the clipboard turns green, drop the tile • Click on the clipboard and drag it back to the Method Editor

  5. Objects With Custom Methods What do you think the foottap custom method does? • In addition to primitive methods some objects have custom methods • When objects are selectedfrom gallery, a listing ofcustom methods appears • Names of the custommethods give clues as towhat the method does

  6. Naming Conventions Which one coaches the Knights and which one coaches the Cougars? • Names are known as identifiers because they identify items in a program • Use a name that provides meaning • Name of method should indicate the method’s purpose

  7. Naming Conventions the periodis called a “dot” • Dot notation • world.my first method • Dot (period) separates pieces of information • Left side: object that the method belongs to • The WORLD object in this case • Right side: name of the method • “my first method” in this case

  8. Naming Conventions Most programming languages do NOT recognize spaces Alice allows spaces, good practice is to not use them method.my first method Without spaces, how do you have more than one word in names? Lower case first letter Capitalize first letter of next words Called camelCase(camel’s hump) Notethespace Notethespace Which is easier to read? onehumpcamel or oneHumpCamel

  9. Class Names • Method names begin with a lower case letter • Class names are capitalized • No spaces, so each word is capitalized • This convention is called PascalCase

  10. Renaming • Objects • Right-click object’s tile inthe object tree and selectrename • Custom methods • Select the world object • Select the methods tab from the Details Panel • Right-click the my first method tile and select rename • If right-click does not work then hit Control & click

  11. Orientation and Movement • A translation in computer graphics • Moves an object a specified distance in a specified direction • Move instruction in Alice moves object • Left, right, up, down, forward, backward • All movements of objects are egocentric • They move from their perspective, not ours

  12. Pivot Point Examples Center of rotation

  13. Turn Method • Causes rotational motion • Can turn an object • Left, right – similar to turning door on hinges • Along the horizontal plane • Forward, backward – lifting or closing hinged lid on a box • Along the vertical plane forward and backward

  14. Roll Method • Object is rotated left or right • Along the vertical plane clockwise or counter-clockwise • Rotation depends on where center is

  15. Subpart Rotation • Center for rotational motion is where subpart connects to object • Also called a pivot point • Turn rotation of Monkey’s left arm subpart

  16. Orient to Method Forward Notice change orientation of ball changed • Used when two objects need to move together synchronization • Objects might be pointing in different directions • Use orient to method to align them • Argument is object to orient to method

  17. Circling Other Objects • Object’s turn method spins theobject around • Can also get an object circle around another object • The asSeenBy optional argument causes an object to turn around the asSeenBy’s objects center point • Example: hawk turns one complete revolution around the tree from the tree’s perspective

  18. Facing and Pointing Objects • Turn to face • Causes object to turn toward another object • Point at • Aligns two objects from the center of one to center of other • Centers are not always in good spot • They could collide in odd places or cause odd movement

  19. “Move to” Instruction • Moves an object to another object • Instead of a distance with move instruction • The centers of both objects align • This will make it look like they collide • Better to use “move toward” instruction • Need to know distance though and be careful of center • Be very careful • Will match center of both objects together • If centers are at different heights the object will be moved off ground or into ground to align centers • Use “turn to face” object then move distance to object

  20. Code can be exported to an HTML file From File – Choose Export Code for Printing You MUST add your name as the author Author’s name is printed with the exported code Exporting Code for Printing Author’s name

  21. Homework • Read chapter 2 • Do lab assignments in handout • Exercise 6, 7 and custom exercise of fish circling island • Due one week after its assigned

More Related