CS 202 Fall 2011

Homework Assignment #5 : Due Friday 5:00pm October 21

This homework has two parts. In the first part, you'll use your creativity to design and implement a Scratch program that composes music. In the second part, you'll explore how to use existing tools to visualize data sets.

Part A: Scratch Program that Composes Music (7 points + up to 2 points of extra credit)

The goal of this project is to create a Scratch program that will compose new music for the listener. The music that is composed should have a largely random component; that is, the listener does not know exactly which notes will be played until he or she hears them.

Be sure to read this entire page before proceeding. This project has a number of strict requirements that you must fulfill.

We anticipate that you will want to carefully review the material we covered about Probability Trials in Lecture. You may find it useful to look at how randomness was used to solve the Monty Hall problem, to calculate the probability of flipping heads multiple times in a row, and for calculating PI.

We strongly recommend that you look at the Mozart Musical Dice Game. Like your project, the Mozart Musical Dice Game does compose music at random; however, this Dice Game would not fulfill the requirements for this homework because it does not give the listener the option to save and playback good compositions.

In this video, music teacher, Alex Ruthmann, shows how to create music in Scratch by programming interactively; his results sound impressive!

Another source of inspiration: Madeon - Pop Culture (live mashup). This isn't a random composition, but has a lot of the same elements of mixing together different parts of different songs in interesting orders...

Specification

There are a few requirements that your music composition must fulfill.

  1. Music: Your Scratch program must compose music. Our definition of music is very broad -- it can be tonal or atonal, it can be notes or drums or interesting sound effects, it can be any musical instrument (e.g., see "set intrument to ..." for choices in Scratch). You may "Import" or even "Record" your own Sounds and play random selections of those sounds. We expect that you will use the Scratch blocks under the "Sound" category to play your music.
  2. Randomness: Your Scratch program must use randomness to "compose" a new piece of music. The piece that is composed should be different every time the Scratch program is run. We expect you will use the "pick random A to B" instruction block under "Operators" in Scratch to select random numbers. How randomness is used is somewhat up to you; for example, each note, number of beats, and/or drum style could be selected at random. Your program must call the "pick random" block many times (e.g., at least 10). For example, it isn't sufficient to obtain just one random number and use that to pick between several pre-composed songs; it also isn't sufficient to call "pick random" to just set the tempo or the instrument. We describe some of your options for randomness in more detail below.
  3. New Song vs. Playback Recording: When the Scratch program begins, the listener should be given two choices. It is up to you if listener specifies their choice by typing or clicking. The first choice is to have the program compose and play a short song (e.g., one lasting about 20 seconds). After the listener hears this song, they should be asked if they would like to save this song. If they don't want to save this song, then any previously remembered song is still remembered. The second choice is to play back the previously saved song. In this case, a new random song is not composed; instead, whichever one song was last saved by the listener should be replayed. You must use a list in Scratch to record and playback music. Hints on how to implement this are given below.
  4. Project Notes. Every Scratch project has Project Notes associated with it. Project Notes can be written from the "File" pull-down menu in Scratch. What should you write in the notes? You should describe all of the features and details of your program along with any known bugs or problems. Basically, the project notes are your way of communicating with the TA who will be grading your project; use the notes so that they can understand what you have done (or have tried to do).
Within our specification, you are welcome to create any music you like. You are encouraged to use inspiration from projects on the Scratch website. Remember to never copy any scripts directly. Please avoid any offensive material.

You may add additional features to your program as long as you adhere to the minimum specification given above. For example, you can add animation and visual effects. You can let the user select the instrument or the speed of the song.

Hints for Developing your Code

Music can be "composed" randomly in a number of different ways. We have the two specific recommendations for using randomness in your composition.

  1. Randomly generate each note: This is probably the easiest way to use randomness. The idea is to generate a random number and then use that random number as the argument (or parameter, or input) for selecting which drum (in the Scratch block "play drum for beats") or note (in the Scratch block "play note for beats") to play. This is easy, but it might not sound the best.

    You can probably improve how the notes sound together by narrowing down the range of random choices for what is played. For example, you might only want to select random numbers in the range of notes you personally find pleasant (e.g., from note 30 to 80). Or, you might want to only select notes in a single octave (e.g., from note 60 to 72). Or, you might want to only select notes that are from a single key (e.g., to play only in the key of C, pick only the random numbers 60, 62, 64, 65, 67, 69, 71, and 72).

  2. Randomly select a predefined measure:In this approach, you (the human composer and programmer) assemble different "measures" of music ahead of time. A "measure" doesn't have to follow any musical definitions; it can be just a sequence of notes. The randomness occurs in this scenario because the measure that is played is selected at random! In this way, you can ensure that sequences of notes that sound good together are always played together.

    This measure can be defined and played by your program in two different ways. First, your program could play a sound file (imported or recorded) that contains a single measure; your program will contain multiple sound files, one for each of the different possible measures. Second, it could use "broadcast" to randomly trigger another script (using "When I receive"); this other script connects multiple "play note" blocks together in order to play a series of pre-selected notes. Again, you will have multiple scripts, each playing a different measure. Hint: You may wonder how you can broadcast so that a random script will be activated. Amazingly, a variable can be used as the argument to the "broadcast" instruction block!

We promised some hints on how to record and playback compositions. Here is what we suggest.

  1. Recording: When your program is "composing" a song, it must tentatively remember what it has composed in case the listener decides they like this song and they choose to keep it. To tentatively remember what notes (or measures or drum or beats or sound effects) your program has played, it needs to record this information somewhere. A simple variable won't work because there will be many, many notes; therefore, your program needs to use a list. As your program generates random numbers, it should "add" the random numbers to a list; the list will contain all of the random numbers used to generate this one particular song. For clarity, imagine this list is named "Temp".

    If the listener indicates that they like this song, your program will need to ensure that this Temp list is kept around. To do this, you should copy each of the elements of Temp list to another one; let us call this list "Saved". You'll need to write a script to copy each of the elements one by one from the Temp list to the Saved list. (Hint: You'll need a "repeat" loop and the "add" block).

    If the listener did not like this new song, do not delete or copy over the Saved list!

  2. Playback: If the listener decides to playback the recorded song, then instead of randomly generating new numbers, the program will instead use the numbers stored in the Saved list. (Hint: To access each of the numbers stored in the Saved list, you will use the Scratch block "item X of List". X is a variable that your program will increment from item 1 up to the length of the list; your program needs to use each element of the Saved list in the same order they were used the first time!)

You may find lists difficult to use at first, but once you get the idea, there are relatively straight-forward. We recommend writing small amounts of code and immediately testing that code to see that it works correctly before writing more code. Get each step working correctly before you move on to the next step!

As always, programming assignments and projects in this class should be done on your own. You may ask other students in the class questions, but you may not share code with anyone in the class. You may not use existing code that you find elsewhere, including the Scratch website. You may look at the behavior of existing Scratch projects for inspiration, but you should develop all of your code as a completely new project and not modify, re-mix, or build from any one else's code.

The Instructor and the TA are very happy to give you suggestions on how to implement your ideas. We won't necessarily give the answer, but we will try to guide you to a reasonable implementation. If you have bugs in your code (i.e., it isn't behaving like you expect), we are happy to take a look and see if we can see the problem. But, again, don't wait until the last minute to do your project if you are hoping for any advice!

Extra Credit (Optional)

For extra credit, you may share your game with the class. You can obtain up to two points of extra credit: one point for participating in voting one point for getting a significant number of votes.

To correctly share your picture, follow these steps carefully:

  1. Save your complete project.
  2. "Share" this project on the Scratch website by clicking "Share" and then selecting "Upload project to website". (Of course, you must be connected to the network to do this!)
  3. Use a web browser to go to the Scratch website and visit the gallery UPDATED LATER. Click on the button on the right-side of the page saying "add my projects". In the pop-up box, select your project that you want to add and click "Accept".
  4. Verify that your project with the picture you like is showing up the gallery.
  5. You will then have to vote on a favorite project in your gallery; more details later!

More details will be given later about the voting process.

Part B: Visualization (3 points)

A number of fascinating data sets exist on-line as well as tools to help you visualize that data. Many Eyes and Google Public Data Explorer are two popular sites for sharing visualizations.

In this part of the assignment, you will use Google Public Data Explorer to visualize a data set; you should pick a data set that allows you to answer a social question you find interesting or that could help steer public policy. (For example, the questions we discussed in the Lecture on Big Data.) A huge number of data sets are available for you to use.

After you've picked a data set of interest, explore the four different types of graphs you can produce: line, bar, map, and scatter. You can select the type of graph by picking one of the four icons near the top left of the page.

In many cases, to visualize interesting results you'll want to change what is being Compared and/or what is shown on one of the axes. To change this, use the dropdown menus along the left side of the page and along the axes. For example, many of the data sets default to comparing data across different States of the US. But, you can change this by selecting the dropdown arrow symbol and selecting a different category for comparison. Likewise, for the scatter graph, the default uses the same metric along both the x and y axes resulting in a boring x=y graph; you will want to change the metric being shown on either the x or y axis to look at correlations.

After you've explored some data, tell us what you found. To do this, you must produce three graphs; all three graphs will probably be of the same data set, but they must compare different categories of data, use different metrics, or be of different types (e.g., line, bar, map, or scatter).

  1. Include in a single document (e.g., MSWord) your three graphs. Don't just include links to your graphs on the google website. The easiest way to include the graphs directly is probably to grab a screenshot. Make sure the graphs include the x and y labels and data categories being shown.
  2. State the societal or public policy question you are trying to answer with the data shown on the graphs.
  3. Describe what is being shown in each of the three graphs. We expect a few sentences about each graph.
  4. Explain in a few paragraphs how the data across the graphs helps you to answer your societal question.

Save your file as a .doc, .docx, or .pdf file.

Turning in your Homework

You should turn in both parts of this assignment through your Learn@UW account. To do this, we think you can follow these steps:
  1. Login into LearnUW : "learnuw.wisc.edu" using UW NetID and password.
  2. Click on the link "compsci202:Introduction to Computation" under student tab.
  3. Click the Dropbox option which is on Top-Left of your web page.
  4. Click the link to the corresponding HomeWork you need to upload. It directs you to a page where you can upload files.
  5. Upload the desired files and submit them. Your Scratch program will be saved in a file with the extension ".sb". For example, if you named your program "homework4", then you will see a file with the name "homework3.sb" that you should upload. Your write-up for Part B should be in a file with an extension of .doc, .docx, or .pdf.
If you have any questions about how to do this, please don't hesitate to ask. We don't want you to get stuck on steps like handing in your homework.

Menu

Fall 2010
Time: MWF 9:55-10:45
Room: 1221 CS
Lab: 1370 CS (1st floor)


Instructor:
Prof Andrea Arpaci-Dusseau
Office Hours
Mon 11-12, Wed 11-12
Office:
7375 Computer Sciences
Email: dusseau "at" cs.wisc.edu

  • CS202 Home
  • TAs and Lab Hours
  • Lecture Schedule w/ Slides
  • Grading
  • Homeworks
  • Projects
  • Exams
  • Scratch Examples
  • Readings
  • Computing Resources
  • Outreach Opportunity
  • Interesting Links
  • Scratch
  • UW Computer Sciences Dept