On this page:
1 Sign up for Discord
2 Pay attention to announcements
3 Arithmetic and constants
4 Images
5 Functions
6 Food
7 Animation
8.12

Lab 1: Getting started🔗

This lab introduces DrRacket and Beginning Student.

Lab attendance is required.

1 Sign up for Discord🔗

We will use Discord to ask and answer questions, make announcements, and hang out. Sign up with the link we announced on Canvas when the course started. Change your nickname on Discord to the full name you’d like us to use in this class. Then, introduce yourself in the #introductions channel.

If you would like to talk to only instructors on Discord, type /breakout (with a forward slash at the beginning of the message) then hit Enter. This should create a “breakout channel” that only you and the staff can see.

Two safety tips on Discord (actually, on any network): First, enable two-factor authentication (next to your password setting). Second, don’t open any download you receive through a private message.

2 Pay attention to announcements🔗

Read the Syllabus section of this Web site. Then, start DrRacket and answer the following questions by putting comments in your Definitions Window, like this:
; Exercise 1
; Answer:

Exercise 1. Alex started early on problem set 1 and submitted their work already on Wednesday. Unfortunately, they made a critical mistake and only got 5 out of 10 points. Where can they get personal feedback about their homework? How can they raise their grade on this assignment? When? By how much?

Exercise 2. Bri plans to work on problem set 1 this weekend and submit their work by Monday morning. According to this plan, what grade will they receive?

Exercise 3. When is problem set 2 due? When is midterm 1 scheduled? Where and when can you find your lab instructors at tutoring?

Exercise 4. Name three ways to get help in this course if you get stuck.

Don't procrastinate and always ask for help

Exercise 5. According to anonymous surveys of students, students spend at least 5 hours per week on average working on this course, in addition to the required lectures and labs.
  1. Decide when you are going to work on this course every week.

  2. Put at least 2 hours as a weekly appointment on your calendar. If you have never used a calendar, start using one, such as the one on your phone.

  3. Then, enter the time you chose at When2meet. This way, y’all can find study buddies.

3 Arithmetic and constants🔗

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

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

Exercise 7. Define a variable big-number to be a big number. (If you’re not sure how to define a variable, review Lecture 2: Definitions Exercise 1.) 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.

Hint: DrRacket comes with a help system called Help Desk, under the Help menu. 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. You can also search in the Help Desk for documentation about a particular function, such as expt.

4 Images🔗

Put the following text at the top of your Definitions Window, to access the 2htdp/universe and 2htdp/image libraries.
(require 2htdp/image)
(require 2htdp/universe)

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: vehicles, plants, foods, etc.

Exercise 9. Use place-image and empty-scene to create scenes with your image. (If you’re not sure how to use a function, review Lecture 1: DrRacket and arithmetic Exercise 12.) Andy Warhol used this rubber stamping technique to create art such as Stars and Half Moons, 1960, to the right.

Hint: DrRacket comes with a help system called Help Desk, under the Help menu. 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. You can also search in the Help Desk for documentation about a particular function, such as rectangle.

Exercise 10. Using the rectangle function provided by the 2htdp/image library, create
  • a rectangle that is tall and narrow,

  • a rectangle that is short and wide, and

  • a square.

Then, using the circle function provided by the 2htdp/image library, create a circle that would fit perfectly inside the square. Finally, using the overlay function provided by the 2htdp/image library, put the circle inside the square.

Exercise 11. Create the image below. It can be printed, folded up, and taped together to make a cylinder (in other words, a soup can). The diameter of the cylinder is 75, and the height of the cylinder is 105.

To compute the width of the rectangle, use the constant pi provided by the Beginning Student language. To put images on top of each other, use the function above provided by the 2htdp/image library. Remember that using something means putting its name in your code.

Exercise 12. Create the image below. It can be printed, folded up, and taped together to make a cylinder (in other words, a tuna can). The diameter of the cylinder is 85, and the height of the cylinder is 40.

5 Functions🔗

Exercise 13. Define a function that, when given a diameter and a height, will produce an image that can be printed, folded up, and taped together to make the cylinder of the given diameter and height. Name your function can. For example, the images you just created should be just as well produced by (can 75 105) and (can 85 40).

Exercise 14. Define a function that, when given a diameter and a height, will compute the surface area of the cylinder of the given diameter and height.

Exercise 15. 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.
  • syntax error, when you write something that DrRacket doesn’t recognize as a program

  • run-time error, such as when you provide the wrong kinds of inputs to an operation

  • logical error, when your program produces an answer, but it’s the wrong answer

6 Food🔗

Exercise 16. Define a function that, when given a number, will produce a crude image of some food. The image produced should depend on the number given. For instance, you could define a function that depicts a pizza of the given diameter, a sub sandwich of the given length, or a hamantash whose filling color depends on the given number in some way. Here’s a hamantash:

(overlay
 (triangle 30 "solid" (make-color 190 70 10))
 (triangle 60 "solid" (make-color 250 230 190)))
If you’re not sure what to draw or how to draw it, work with other students.

Exercise 17. What happens if you feed the number -1234567/89 to the function you just defined? What range or kind of numbers can your function actually handle correctly? Write down your answer clearly.

7 Animation🔗

Exercise 18. Define a function which produces an image when given a number. The image produced must have the same size no matter what number is given. For instance, you could define a function that places a circle with the given radius in the middle of a large empty scene.

Exercise 19. Use the function you just created, along with animate, to produce an animation. Remember that using something means putting its name in your code.

That’s it for this lab! Your lab instructors will grade your work and give you friendly feedback. For later reference, you should also save your work using the Handin server, as assignment lab1.