Lab 1

Pair Programming [1 min]

You will be working in pairs during labs. Pairs consist of a pilot and a co-pilot. The pilot types at the keyboard while the co-pilot looks over the pilot's shoulder. Remember if the plane goes down, you are both in trouble.

Finger exercises

Start DrScheme. Make sure that the language level is set to "Beginning Student" (if you change the language level, it will not take effect until you hit the "Run" button).

Exercise 1: Experiment with using DrScheme's Interactions window as a calculator. See what operations you can use to calculate. Make sure to try big numbers and fractions. [1 min]

Exercise 2: Design a function that given an integer that represents time in hours will return back the time in minutes. Use the interactions window to test your function. [3 mins]

Exercise 3: Design a function that given an integer, representing time in minutes will return back the time in hours rounding up to whole hours.

Hint: DrScheme comes with a help system called Help Desk. Open the Help Desk and click "Manuals", then click "Beginning Student". That gives you a reference for the Beginning Student language. You can also highlight the name of a function and press F1, this will search Help Desk for the highlighted text.

There are three kinds of errors you can make when writing a program in DrScheme. [17 mins]

  1. syntax error
  2. run-time error
  3. logical error

Partner Switch [1 min]

Pilots stand up and switch with your co-pilots.

Images and Scenes [50 mins]

Add the "world.ss" teachpack to DrScheme. In the menubar, click "Language" then "Add Teachpack...". A file selector window should popup. Navigate to the "htdp" directory, then to the file "world.ss". Press "ok" and then press the "Run" button. The teachpack should be listed in the Interactions window.

Teachpacks come with documentation. In the Help Desk, search for "world.ss".Also have a look at the documentation of the image.ss teachpack titled "Images (image.ss)".

Exercise 4: Download an image off the web and insert it into your Definition window. Use define to give it a descriptive name. Examples: cars, boats, planes etc.

Exercise 5: Use place-image and empty-scene to create scenes with your image.

Exercise 6: Create rectangles with the following dimensions

  1. 2x4
  2. 4x8
  3. 8x16
  4. 16x32
  5. 32x64
  6. 64x128

Exercise 7: Design the function rec-sequence that given an index within the series of rectangles will return the corresponding rectangle at that index, e.g., (rec-sequence 2) returns a rectangle of size 4 by 8.

Animation

Using the world.ss teachpack we can create animations. The teachpack allows you to model a world. Every time the clock ticks, the teachpack uses one of your functions to create a new world, which becomes the current world. The teachpack uses a second of your functions to create an image of your world.

  1. Our "world" will represent the number of ticks,
     
          ;; World = Number (positive) 
          
  2. a function that will calculate the next world
     
          ;; World -> World 
          ;; calculates the next snapshot in the series 
          (define (next-world w)
            (add1 w))
          
  3. a function that will create a snapshot form a world
          ;; World -> Image
          ;; draw the image for snapshot no. w
          (define (world-draw w)
            (circle w 'solid 'black))
          

    Switch Partner


  4. Genesis (lookup big-bang in Help Desk).
     
          ;; canvas is 200 by 200, the clock ticks every .1 seconds
          ;; and we start at world no 1
          (big-bang 200 200 .1 1)
           
  5. Connect the clock ticks with our function that calculates the next snapshot number (lookup on-tick-event in Help Desk).
     
          ;; every clock tick, gets the next snapshot number 
          (on-tick-event next-world)
          
  6. On a redraw, update our image to its correct snapshot (lookup on-redraw in Help Desk).
     
          ;; on-redraw play the world's image on the screen
          (on-redraw world-draw)
          

Exercise 9: Change the animation above so that the disk moves across the canvas. Try left to right, top to bottom and diagonal.

Exercise 10: Read the documentation of the image.ss teachpack and create an image of a car using circles and rectangles.

Exercise 11: Use the car image from Exercise 10 and create an animation with the car moving across the canvas.


Pick Homework Partners [10 mins]

Each of you will have a blue book. You will record in this book your partners information (name, email, IM, telephone no.) as well as the dates and times that you meet with your partner. At each meeting, you will agree to a next meeting recording the time and place. You should always carry the blue book with you. You might be asked to show your blue books at any time during the semester.