1 / 18

CS320n –Visual Programming

Learn the importance of parameters in methods and enhance animation creation with flexible programming techniques. Explore how to use parameters to specify band members and music in an interactive bug band performance. Get hands-on with demonstrations and step-by-step guidance on implementing parameters effectively.

hopkinsm
Download Presentation

CS320n –Visual Programming

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. CS320n –Visual Programming Parameters Mike Scott (Slides 4-2)

  2. What We Will Do Today • Learn how to use parameters in methods • (reminder. Clipboard) Parameters

  3. Overview • The need for more flexible methods • Snowman example. What if there are lots of snowwomen or other objects and we want the snowman to try and get the attention of any one of them? • Passing a parameter to a method • Demos • Using the Alice interface to write code for a parameter object Parameters

  4. A beetle band • Our task is to create an animation for a bug band as an advertisement for their next concert. • In the animation, each band member will perform a short solo. Parameters

  5. Storyboards • Each bug band member will perform a solo. Do together Do in order georgeBeetle move up georgeBeetle move down play sound Do together Do in order ringoBeetle move up ringoBeetle move down play sound Do together Do in order paulBeetle move up paulBeetle move down play sound Do together Do in order lennonBeetle move up lennonBeetle move down play sound Parameters

  6. Code for georgeBeetle solo • This code will only work for georgeBeetle. • Since each band member performs a solo, we will need four versions of the code. SHOW PROGRAM Parameters

  7. A Better Solution • Four versions of very similar code seems a bit tedious. The only things that change are the beetle and the music that plays. • A better solution is to write a more flexible method. • one where the object that does the solo AND the music it plays can be specified in some way Parameters

  8. Parameters • Built-in methods provide flexibility by providing parameters such as distance and direction. • Parameters allow you to pass in values (we call the values arguments). • Example Parameters: distance, direction Arguments: 0.5 meters, 0.5 seconds Parameters

  9. Kinds of Parameters • Alice provides several kinds of parameters that can be used in your own methods. Parameters

  10. The storyboard Solo: Parameters: bandMember, music Do together Do in order bandMembermove up bandMember move down playmusic • Back to our problem… • We want to write only one method and • use parameters to specify • which band member is to perform and • which music should be played. Parameters

  11. Demo • Demonstration of creating a method named solo that can be used for any band member. • We will need • an Object parameter -- which band member is to play a solo • a Sound parameter -- which music should be played Parameters

  12. World.solo with parameters . Parameters

  13. Calling the solo method Note that in each call to the method, arguments must be given for both parameters. Parameters

  14. Specifying Arguments • When adding one of your methods with parameters to a program a pop up menu is used to specify the arguments • order important Parameters

  15. A Number parameter Let's add a Number parameter to specify the height the bandMember jumps up and down. Parameters

  16. Demo • Demonstrate the use of a Number parameter to specify the height the bandMember is to jump Parameters

  17. Adding Sound to Animations • In the file Alice/required/sounds are the default sounds • call the play sound method for an object and a menu of sounds is presented, based on the files in this directory Parameters

  18. Adding Sounds • You can also import sounds • search computer for sound files • .wav and .mp3 • any sound in the Alice/required/sound directory is a default choice • DEMO: make all the beetles jump up and play the same sound at the same time Parameters

More Related