CS 198: Project #1

Project 1: Computational Thinking

The purpose of this assignment is to explore how we go about describing an algorithm, which is simply a series of steps in a process. You'll also make use of the idea of a function, which is simply a method of encapsulating a process and giving it a name.

Maxwell's Frustration Rule: you should never get frustrated while working on an assignment. If you have spent a half-hour trying to solve a problem and have not made any headway, stop by, send an email, or start an ichat with the professor. Go on to something else in the meantime.


Tasks

  1. Use the soundturtle package to create a simple 5-10 note theme. Store the sequence of commands in a file called theme1.py. At the top of the file you should have the statement to import the soundturtle package.

    from soundturtle import *

    Before your theme plays, use the pitch() call to set the starting note of your theme. Try to use only the up() and down() functions to change the pitch otherwise. Use a variety of durations in your theme.

  2. Now think about how you can parameterize your theme so you can have it play on any starting pitch and at any tempo.

    For example, in your theme you used a number in your first call to pitch(). Before you call the pitch function, make a variable called base and assign it the initial pitch of your theme. Then use the variable in the call to pitch() instead of a number.

    To create a variable in python you simply assign a value to a variable name. A variable name can be any string you make up that has no spaces and consists of only letters and numbers. A variable must begin with a letter. For example, the following creates a variable called base and assigns the value 42 to it.

    base = 42

    In your theme you also used numbers to specify the duration of each note. The units of these numbers are seconds. Next to where you created the base variable, create a variable called unit and assign it the value 0.5. In every call to play(), multiply the number by the variable unit. What will happen? How would you make your theme play more slowly?

  3. Create a new python file called theme2.py. In this file create a function called themeA that takes in two arguments. A function in python is just a container for some code. You can define a function called twinkle that takes two arguments using the syntax below. You can name functions anything you like, following the same rules as for variables.
    def twinkle( base, unit ):
      # put some code here, tabbed in 
    

    Put the code you wrote earlier for your theme into the function, appropriately tabbed in. At the bottom of the python file, make some calls to your theme function with different base and unit values. For example, the following would call the them function three times with different values for base and unit.

    themeA( 50, 1.0 )
    themeA( 53, 0.5 )
    themeA( 48, 2.0 )
    
  4. Create a second theme. Put the code for it into a function called themeB. Then intersperse calls to your two themes at the bottom of the python file. Note that you have to define the function in the file before you can call it.

Once you are finished with your themes, put the two python files, and any others you want to hand in, into your handin folder on the Academic server.


Writeup

Each of you should create your own wiki page for your writeup.

Colby Wiki

Please put the label cs198s10proj1 on your writeup page (down below the editing window on the edit tab).

For this week, your writeup should consist of your answers to the following questions.