ITC 101 Programming Module


Published on

Exploring Computer Programming with Alice
ITC101, Introduction to Information Technology.

Designed by Prof. Beth Scott, Funded by BATEC, an NSF ATE Center project.

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • The Alice Integrated Development Environment is named in honor of Lewis Carroll’s Alice in Wonderland.Introduce:MyselfWhat we plan to do today
  • Objects haveBehaviors (methods)Characteristics (properties)
  • Let’s open Alice from our desktop.
  • EncapsulationExample: Class: animalDogPigPropertiesDescribe the objectcolorMethodsBehaviorsInteractionsExample: speakAsk the class how the object speaksDiscuss inheritance, encapsulation
  • In this first demo, we explore examples of the two different types of animation in Alice.Open and run the first world together.Students open 2nd world and play on their own.
  • In this first demo, we explore examples of the two different types of animation in Alice.Open and run the first world together.Students open 2nd world and play on their own.
  • Refer back to the examples:Which was a “Movie” and which was “Interactive”?
  • Follow along!
  • For this demonstration, select grass.
  • White board: class/objectClass is the cookie cutterObject is the cookie
  • Place the bunny on the grass.
  • We will experiment with each set of tools.
  • Experiment with the Mouse Controls.Copy bunny.Now have two bunnies.
  • Move camera:Up, down, left, rightBackward and forwardTiltExperiment with the camera controls
  • Position bunnies relative to one another.
  • Draw on white board.Emphasize the objects are 3 dimensional with 6 degrees of freedom fowr
  • Select bunny’s right ear.Tumble.
  • Have students work on this individually or in pairs to complete these instructions.Gallery->environmentsGroundHillSkys->happy sky
  • Ask the class what is a story board?Why is a story board a good design and documentation technique for this type of programming?
  • The problem we are solving is to animate this scenario.
  • Have 3 student volunteersHave each student stand up one after the otherDo in orderHave students stand up togetherDO TOGETHERDiscuss when to use each idea.
  • On the white board, demonstrate nested blocks.
  • Ask the students what the benefits of this approach might be?
  • // comment
  • Always start with “my first method”
  • Demonstrate program.
  • Distinguish world level and class level behaviors.Ask the students to looks at the Bunny’s methods.Is there a hop method?What to do?
  • Review the bunny’s methods.The bunny does NOT have a hop method!Let’s create this method.
  • Break down the idea of hopping…
  • Discuss data types.Note we are now in the bunny.hop method.Note we are no longer in the world.myfirstmethod method
  • Test the program here.
  • Good time for a break
  • Use function, bunny distance to
  • Review computer terms
  • ITC 101 Programming Module

    1. 1. Exploring ComputerProgramming with Alice Middlesex Community College Introduction to Technology Fall 2011 Prof. Lori Weir
    2. 2. Student Learning Outcomes• Introduction to Computing Careers• Introduction to Alice• Setting up an initial scene in Alice• Designing an animated scenario• Implementing a design• Programming• Summary• Going forwardFall 2011 Middlesex Community College 2
    3. 3. Getting Started with Visual Programming INTRODUCING ALICEFall 2011 Middlesex Community College 3 <<DRAFT>>
    4. 4. What is Alice?• Alice is a visual programming language.• Alice is an object based language. The objects in Alice are 3 dimensional models.• The output of Alice programs is an animation. – Objects can be made to move around the virtual world: • A video game • A simulationFall 2011 Middlesex Community College 4 <<DRAFT>>
    5. 5. The Alice Software• A 3D interactive animation environment•• A tool for teaching fundamental programming concepts – object based• System developed at Carnegie MellonFall 2011 Middlesex Community College 5 <<DRAFT>>
    6. 6. Visual Programming• Programming tasks are performed in an Integrated Development Environment(IDE).• Programming is done by pointing and clicking, dragging and dropping, selecting from menus, and some typing.• Syntax errors removed from the equation – no braces, no semi colonsFall 2011 Middlesex Community College 6 <<DRAFT>>
    7. 7. Object Tree World View Event EditorDetails Panel Code Editor College Control Fall 2011 Middlesex Community <<DRAFT>> Primitives 7
    8. 8. Object-Based Programming• Built in library of models.• More available on the web.• All objects have certain methods and behaviors – move, turn, say, roll, resize• New methods can be added to an objectFall 2011 Middlesex Community College 8 <<DRAFT>>
    9. 9. Alice Models• Main programming data are 3d models• Many built in and more on webFall 2011 Middlesex Community College 9 <<DRAFT>>
    10. 10. Output• Output is a 3d movie – run the program, play a movie – can also add sound to programs• Much easier to recognize logic errors – "Why do my ninjas arms keep flying away?"Fall 2011 Middlesex Community College 10 <<DRAFT>>
    11. 11. Downloading and Exploring Alice Worlds ACTIVITY 1Fall 2011 Middlesex Community College 11 <<DRAFT>>
    12. 12. Downloading Alice• From your browser, navigate to the Alice download page: =downloads/download_alice• Follow the instructions for your platform (Windows, Linux, or MAC).Fall 2011 Middlesex Community College 12 <<DRAFT>>
    13. 13. Exploring Alice Worlds• Open Alice from the DeskTop• Load and run a world: – Octopus (movie) – Skater (interactive)Fall 2011 Middlesex Community College 13 <<DRAFT>>
    14. 14. Types of Animation Movie Interactive• Passive • User clicks on• User watches the mouse or types a animation key on the keyboard. • Actions of user are called eventsFall 2011 Middlesex Community College 14 <<DRAFT>>
    15. 15. Getting Started Programming in Alice SETTING UP A SCENE IN ALICEFall 2011 Middlesex Community College 15 <<DRAFT>>
    16. 16. Alice Programming• Problem solving and programming in Alice – given a scenario create program to enact the story• Example scenario: – A bunny is hopping in a field of fern and one tulip. – The bunny notices the tulip. – The bunny hops over to the tulip. – Accidentally, the bunny knocks the tulip.Fall 2011 Middlesex Community College 16 <<DRAFT>>
    17. 17. Creating a New WorldFall 2011 Middlesex Community College 17 <<DRAFT>>
    18. 18. Selecting a TemplateFall 2011 Middlesex Community College 18 <<DRAFT>>
    19. 19. Objects in The World• An object is: – Any thing that can be identified as unique from other things.• How is an object unique? – Name – Properties • Width, height, color, location – Can perform actions • Referred to as methodsFall 2011 Middlesex Community College 19 <<DRAFT>>
    20. 20. Adding Objects to the WorldFall 2011 Middlesex Community College 20 <<DRAFT>>
    21. 21. Adding Objects • Two ways to add objects: – Drag and Drop – Click on picture then click on Add InstanceFall 2011 Middlesex Community College 21 <<DRAFT>>
    22. 22. Techniques and Tools Camera Drop-downMouse is used Quadview is navigation is menu methods to used to used to are used to: Approximately Position one Set the camera position objects Resize objects object relative point of view in the scene. to another Precisely position objects in the sceneFall 2011 Middlesex Community College 22 <<DRAFT>>
    23. 23. Mouse Control Tools KitDefault. Move selectedobject left, right, forward, Copy objects.backwards.Move selected Resize objects.object up and down. Tumble objects. Turn object forwards and Turn object left and right. backwards. CTRL Z or Undo Button to undo mistakes!Fall 2011 Middlesex Community College 23 <<DRAFT>>
    24. 24. Camera ControlsAlter position of camera with these controls. Fall 2011 Middlesex Community College 24 <<DRAFT>>
    25. 25. Alternate Positioning Techniques • Right click on object in world on object tree and select method • Drag and drop method from the details panel.Fall 2011 Middlesex Community College 25 <<DRAFT>>
    26. 26. Quad View• Use worlds absolute frame of reference to view relative position of objectsFall 2011 Middlesex Community College 26 <<DRAFT>>
    27. 27. Objects Frame of Reference• Objects in Alice – Have their own frame of reference – forward – backwards – up – down – left – rightFall 2011 Middlesex Community College 27 <<DRAFT>>
    28. 28. Frame of Reference• Clicking on object brings up its bounding box• Can also see center point• .. and axesFall 2011 Middlesex Community College 28 <<DRAFT>>
    29. 29. Frame of Reference UP CENTER POINT RIGHTFall 2011 FORWARD Middlesex Community College <<DRAFT>> 29
    30. 30. Subparts• Objects often have sub parts – may have their own frame of reference• Clicking affect subparts box allows selection and movement of subpartsFall 2011 Middlesex Community College 30 <<DRAFT>>
    31. 31. Subparts• Bigger earFall 2011 Middlesex Community College 31 <<DRAFT>>
    32. 32. Finding Objects• To reposition in a quad view – select zoom in and out from mouse controls – zoom way out – select scroll from mouse controls to center objects – zoom back inFall 2011 Middlesex Community College 32 <<DRAFT>>
    33. 33. Back to Programming View• When setup complete click the green done button to go back to the programming view.Fall 2011 Middlesex Community College 33 <<DRAFT>>
    34. 34. Saving a World• Writing and testing an animation is an intense load on the computing system – a crash can occur.• Best solution – Save your world very 15 minutes (or at least every half hour). – Also, save to a backup device • Zip drive • Memory keyFall 2011 Middlesex Community College 34 <<DRAFT>>
    35. 35. Creating a World ACTIVITY 2Fall 2011 Middlesex Community College 35 <<DRAFT>>
    36. 36. Setting Up the Initial Scene• From the Alice programming environment: 1. create a new world. 2. Add bunny 3. Add fern and flower • local gallery -> nature – Fern – Tulip 4. Resize bunny to make her smaller • Use the drop down menus or drag and dropOctober 16, 2011 Middlesex Community College 36 <<DRAFT>>
    37. 37. From a storyboard to a program PROGRAMMING THE WORLDOctober 16, 2011 Middlesex Community College 37 <<DRAFT>>
    38. 38. Step 1: Design• A program is a solution to a problem.• Determine the problem to be solved.• Design a solution to the problem. – We will use a storyboard design technique. – Commonly used in the film and gaming industries.Fall 2011 Middlesex Community College 38 <<DRAFT>>
    39. 39. Example Story• A bunny is sitting in a field of fern.• The bunny notices a beautiful tulip.• The bunny hops over to tulip.• The bunny accidentally knocks over the tulip.• Lets add some detail at the start of the movie. – The bunny first turns to face the camera. – Then the bunny hops up and down.Fall 2011 Middlesex Community College 39 <<DRAFT>>
    40. 40. Options for Storyboards• Sketches• Screen shots from Alice• Text – A to-do list of stepsFall 2011 Middlesex Community College 40 <<DRAFT>>
    41. 41. Step 2: Implementation• To implement the storyboard, translate the actions in the storyboard to a program.• Program (a.k.a. script) – A list of instructions to have the objects perform certain actions in the animation.Fall 2011 Middlesex Community College 41 <<DRAFT>>
    42. 42. Action Blocks in Alice Sequential Action Block Simultaneous Action Block Actions occur one after another Actions occur at the same timeFall 2011 Middlesex Community College 42 <<DRAFT>>
    43. 43. Concepts in this First Program• Program instructions may have arguments – Example: for the move instruction, the arguments we used where: • Direction • Distance – Do Together and Do In Order blocks can be nested one inside the otherFall 2011 Middlesex Community College 43 <<DRAFT>>
    44. 44. Testing• An important step in creating a program is to run it – be sure it does what you expect it to do.• We recommend you use an incremental development process: – Write a few lines of code, then run it – Write a few more lines of code, then run it – Write a few more lines or code…Fall 2011 Middlesex Community College 44 <<DRAFT>>
    45. 45. Comments• While Alice instructions are easy to understand, a particular combination of the instructions may perform an action that is not immediately obvious.• Comments document the code – explain the purpose of a particular segment of the program to the human reader.Fall 2011 Middlesex Community College 45 <<DRAFT>>
    46. 46. Methods• Select the world object from the object tree and the methods tab in the details panel.• The world starts with a single method, "my first method"• Like main in a Java or C++ program.Fall 2011 Middlesex Community College 46 <<DRAFT>>
    47. 47. Adding to „My First Method‟ ACTIVITY 3October 16, 2011 Middlesex Community College 47 <<DRAFT>>
    48. 48. Adding Commands to a Method• If the "my first method" is not displayed in the code editor click the edit button next to the method in the detail panel.• Commands are added by dragging and dropping them into a method.• Select the bunny from the object tree.• Drag the turn to face command into the code editor.• TEST!Fall 2011 Middlesex Community College 48 <<DRAFT>>
    49. 49. Adding Commands • turn to face is a method • When adding a method to the code editor if any parameters are required a menu pops up to select the arguments. • Select the camera.Fall 2011 Middlesex Community College 49 <<DRAFT>>
    50. 50. More Parameters• After adding the bunny.turn to face command the "my first method" will look like this:• Click on the "more" option to see what other parameters can be changed – duration, style, asSeenBy – change duration to 3 secondsFall 2011 Middlesex Community College 50 <<DRAFT>>
    51. 51. Test• Click the play button to see the movie / output of the program.• "my first method" will execute.Fall 2011 Middlesex Community College 51 <<DRAFT>>
    52. 52. Built-in Functions and Expressions PROGRAMMING: PUTTING TOGETHER THE PIECESFall 2011 Middlesex Community College 52 <<DRAFT>>
    53. 53. Adding Behaviors• Next we want the bunny to hop.• Methods can be world level or class level. – world level methods belong to the world. • a method should be world level method if it involves two or more objects – class level methods belong to a particular class / object. • a method should be a class level method if it involves only one objectFall 2011 Middlesex Community College 53 <<DRAFT>>
    54. 54. Creating a Hop Method• The bunny does not have a hop method so we will create one.• Select the bunny from the object tree and click on the create new method button in the details panel.Fall 2011 Middlesex Community College 54 <<DRAFT>>
    55. 55. Creating a Hop Method• A window pops up asking for the name of the method – try various names to see what is a legal identifier and what is not• After giving the new method a name a new tab pops up in the code editor• Should hop be one hop or parameterized?• Should parameter be time to hop or number of hops to make?• Any other way to make it more general?Fall 2011 Middlesex Community College 55 <<DRAFT>>
    56. 56. Adding Parameters• Lets add parameters for distance to hop up and the time to do the hop• Click the create new parameter button in the code editor.Fall 2011 Middlesex Community College 56 <<DRAFT>>
    57. 57. Adding Parameters• Give the parameter a name and pick the data type – distance -> a Number – time -> a Number• When called the hop method now requires two parametersFall 2011 Middlesex Community College 57 <<DRAFT>>
    58. 58. Adding Commands to Hop• To hop the bunny will move up and then down.• Drag the move command into hop and fill in the parameters.• Drag another move command into hop and fill in the parameters.Fall 2011 Middlesex Community College 58 <<DRAFT>>
    59. 59. Adding Commands to Hop• To change the duration of moving up select the more option from the move command.• Select duration then expressions then time (or the name of your parameter for time)Fall 2011 Middlesex Community College 59 <<DRAFT>>
    60. 60. Adding Commands to Hop• To change the duration of the move to half of the time parameter click on the triangle to open the drop down menu.• Select math and divide time by 2.• Do the same for the move down.Fall 2011 Middlesex Community College 60 <<DRAFT>>
    61. 61. Completed Hop MethodFall 2011 Middlesex Community College 61 <<DRAFT>>
    62. 62. Back to my first method• Now that the bunny can hop and the broccoli can grow we can complete the first part of the story board• After the bunny turns to face the camera we want the bunny to hop.Fall 2011 Middlesex Community College 62 <<DRAFT>>
    63. 63. Hopping• We want the bunny to hop for 5 seconds.• Back to my first method• Have rabbit hop up and down .25 meters at 0.5 seconds per hop• How many hops?Fall 2011 Middlesex Community College 63 <<DRAFT>>
    64. 64. Looping• A counted loop is used when the number of repetitions can be calculated• Drag a Loop primitive into the Do together block• Number of times to loop is 10Fall 2011 Middlesex Community College 64 <<DRAFT>>
    65. 65. Hopping• After Loop is added to Do together • drag and drop the bunny hop method into the loop • Select 0.25 meters for distance to hop and 0.5 seconds for time • Test!Fall 2011 Middlesex Community College 65 <<DRAFT>>
    66. 66. Noticing the Tulip• Now we want the rabbit to – turn to face the tulip, – Think “Pretty!” – hop over to the tulip – Accidentally knock over the tulip.Fall 2011 Middlesex Community College 66 <<DRAFT>>
    67. 67. Test• Test function by playing movie• Test further by changing initial set up of broccoli to change which broccoli is closestFall 2011 Middlesex Community College 67 <<DRAFT>>
    68. 68. Noticing the Tulip• Do together • Bunny turn to face tulip • Bunny thinks “Pretty!” • Tulip orients to bunny.Fall 2011 Middlesex Community College 68 <<DRAFT>>
    69. 69. Hopping Forward• Create a new method hopForward• Parameters for total distance and distance per hop – lots of other ways to do thisFall 2011 Middlesex Community College 69 <<DRAFT>>
    70. 70. Completing the Hopping• Back in my first method call the hopForward method.• Pick a dummy value for totalDistance.• Replace dummy value with distance from bunny to tulip minus some offset. (no collision detection)Fall 2011 Middlesex Community College 70 <<DRAFT>>
    71. 71. Testing your Knowledge ACTIVITY 4Fall 2011 Middlesex Community College 71 <<DRAFT>>
    72. 72. Testing your Knowledge• Working with a partner, make the flower shake and fall after the bunny stops hopping.• What programming constructs do you need?• Which methods will you use?• What will the bunny say?• Experiment with your closing camera position.Fall 2011 Middlesex Community College 72 <<DRAFT>>
    73. 73. Exporting/Publishing• Animated file• Web pageFall 2011 Middlesex Community College 73 <<DRAFT>>
    74. 74. What Next?• Expand by adding more flowers – lists and variables to manage• Add sounds• Add scenery• Add events – Interactive programs can be created by adding events that program responds to.Fall74 2011 Middlesex Community College <<DRAFT>>
    75. 75. Summary• Learning Alice helps prepare you for an object-oriented language: – C++ – JavaFall 2011 Middlesex Community College 75 <<DRAFT>>
    76. 76. Adding Detail to the Hop MethodFall 2011 Middlesex Community College 76 <<DRAFT>>
    77. 77. Going Forward• Questions about computer science• Interest level?• Help – Example worlds – Tutorial – www.alice.orgFall 2011 Middlesex Community College 77 <<DRAFT>>