On this page:
1 Finger exercises
2 Functions
3 Images
4 Animation

Lab 1: Getting started

This lab will introduce using DrRacket and Beginning Student, using the Handin Server, and defining simple functions.

1 Finger exercises

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

Exercise 1: Experiment using DrRacket’s Interactions Window as a calculator. See what operations you can use to calculate. Make sure to try fractions.

Exercise 2: Define a variable big-number to be a big number. Then, define another variable bigger-number to be the result of multiplying big-number by itself. Finally, define a number that is bigger than bigger-number.

Exercise 3: There are three kinds of errors you can make when writing a program in DrRacket. Come up with examples of each and try them out. Examine any error messages you get back.

2 Functions

Exercise 4: Define a function that when given an integer that represents distance in miles will return the time (in hours) it takes to travel that distance when going 60 MPH. Write your function in the Definitions Window, click Run, then use the Interactions Window to test your function.

Exercise 5: Define a function that given an integer representing time (in minutes) will return the distance traveled when going 70 MPH, rounding up to whole miles.

Exercise 6: Define a function that converts a temperature in Fahrenheit to a temperature in Celsius. Here is the formula.

Exercise 7: Define a function that converts a temperature in Celsius to a temperature in Fahrenheit. In the Interactions Window, apply this function to an integer and apply the function from Exercise 4 to the result and see that you get the same number back.

Hint: DrRacket comes with a help system called Help Desk. Open the Help Desk and click "How to Design Programs Languages", then click "Beginning Student". You will get a reference for the Beginning Student language.

3 Images

Access the 2nd edition HtDP "universe" and "image" libraries in DrRacket. Put the following magic text at the top of your Definitions Window:

(require 2htdp/image)
(require 2htdp/universe)

Libraries come with documentation. In the Help Desk, search for "universe". Also have a look at the documentation of the image library titled "2htdp/image".

Exercise 8: Download a tiny image off the Web and insert it into your Definitions Window. Use define to give it a descriptive name. Examples: cars, boats, planes, etc.

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

Hint: DrRacket comes with a help system called Help Desk. Open the Help Desk and click "How to Design Programs Teachpacks", scroll down to "HtDP/2e Teachpacks", then click "Basic Images". You will get a reference for the 2htdp/image library.

Exercise 10: Create rectangles with the following dimensions.
  • 10x25

  • 20x50

  • 30x75

  • 40x100

  • 50x125

  • 60x150

Exercise 11: Create an image that resembles the Indianapolis flag:

A white star within a red circle within a white circle, with four white stripes moving outward perpendicularly, on a field of navy blue.

Don’t download any image off the Web. Instead, combine the results of star, circle, and rectangle.

4 Animation

Exercise 12: Define a function which given a number, places a circle with that radius in the middle of a large empty scene.

Exercise 13: Use the function you just created, along with animate, to produce an animation.

Exercise 14: Create your own animation, using any functions that you want from the 2htdp/image library.