Submission Details
Getting Started
In this assignment you’ll play with simple functions for making images that we’ll use later on in the course. There is no need for any lambda expressions in ANY of these activities.
Note: We’ve tried to make this assignment accessible to those who have trouble seeing colors, but please let us know if we can provide additional help.
In order to start this assignment, please download the following ZIP file, extract its contents, and open up exercise_1.rkt
.
What's a ZIP file?
This download is a ZIP file which must be extracted before the files can be edited. On a Mac, you can double click on the ZIP folder and it will extract the files for you. On a Windows computer, you can use these instructions from Microsoft to extract the template files.Where should I put this stuff?
We highly recommend moving the extracted folder to a CS 111 work folder somewhere on your machine (so you have all your 111 stuff in the same place) and renaming it to make sure you submit the file you mean to later when you go to submit.Activity 1. Red Square
First, let’s make a 100x100 red square like the below:
Now you should give this square a name. In the Definitions Window type:
(define a-red-square your-code-for-the-square)
and hit run.
You can now refer to the square by typing a-red-square
into the interaction window or any code you write.
VERY Important Note: The names you give your images (i.e. the names after the word “define”) must be exactly as described otherwise the autograder will reject your submission!
Activity 2. Blue Circle
Now let’s make a blue circle of radius 50.
Define it as the name: a-blue-circle
.
Activity 3. NU Stop Sign
There’s a ton of built-in colors in the ISL, stored in special data object called the color-database<%>
. We won’t worry about the details of this more complex piece of data right now, but suffice it to say that when Racket sees you’ve given it a String
as a color input, it looks that string up in this database to see if it has a matching color and replaces that string with the actual “recipe” for that color.
How do we make our own colors?
Colors are represented on computers as mixtures of Red, Green, and Blue values – you can imagine it like mixing together red, green, and blue paints to get different colors. Each pixel (i.e. tiny square) on your computer screen gets assigned a different "intensity" of red, green, and blue which mix together to form its color. This means that we don't actually have to use a color's name as inputs for these shape functions; instead we can specify the exact mixing of red, green, and blue light that we'd like (these intensities are lowest at a numeric value of 0 and highest at a numeric value of 255).
For instance, surprisingly
"Northwestern Purple"
is not a recognized color in ISL. "Northwestern Purple" is officially hexadecimal color #4E2A84
which has a red value of 78, a green value of 42, and a blue value of 132. To make a color in the ISL, we can use the make-color
function which has the following type signature (i.e. recipe): ; make-color: number number number -> Color ; or slightly more specifically... ; make-color: (integer-in 0 255) (integer-in 0 255) (integer-in 0 255) -> Color
The first input must be the red intensity, the second must be the green intensity, and the third must be the blue intensity.
Use the make-color
function to create our new color and then use that as an input to some function that allows us to make a regular octagon that is solid and has a side length of 100.
Define it as the name: a-northwestern-stop-sign
.
Activity 4. Outline Mode
Repeat Activities 1, 2, and 3 but use outline mode:
outlined-square | outlined-circle | outlined-stop-sign |
---|---|---|
Define them as the names outlined-square
, outlined-circle
, and outlined-stop-sign
respectively.
Activity 5. Compound Images
Now let’s make compound images from simpler images. Use overlay
, above
, and beside
to make the following compound images, defined as follows:
row-of-hexagons | |
---|---|
column-of-hexagons | |
nested-hexagons |
Make sure to draw out the dataflow diagrams for each of these. You don’t need to turn them in–just draw them on some scratch paper or a whiteboard to make sure you understand how the data moves through the chain of calls.
Activity 6. Debugging Exercise
In the starter file under activity 6, you’ll see a “commented” line of code that looks like the below but is preceded by a semi-colon.
(overlay (circle 30 "solid" "green" square 100 "solid" "orange")))
What does it mean for code to be commented?
While the code we write is mainly intended for the computer, we're often also writing code with a human audience as well. Whether our future selves or a colleague. Sometimes, the names we use in our code doesn't communicate everything we need to know about how a program works. Additionally, sometimes we solve problems that we think we might forget later and want to leave a note. Obviously the computer doesn't care about this note, so nearly every programming language has a concept of commenting: marking the text we see in our editor as specifically for human consumption rather than part of the program.
In ISL+, we do this by preceding any notes with a
;
(semi-colon). DrRacket, when it runs your program, will stop reading any lines in your program that begin with a semi-colon. This function call is supposed to generate the following shape:
First uncomment the line (remove the preceding semi-colon) and run your program again. You should see an exception in DrRacket and it should also highlight the responsible function call. You have three tasks here:
- Restyle the code so it fits our style guidelines (see Lecture 2 - the function call should be 7 lines long if correctly styled)
- Think about how this function call should work by drawing a Data Flow Diagram for it on a piece of paper. See if the shape helps you notice the issue.
- Fix the issue with the function so it produces above shape and restyle the code (the correctly styled fix program will be 6 lines).
- Finally, define this shape as the variable
debugging-exercise
Activity 7. Rotating
Read the documentation for the rotate
function and try making an image that looks like this:
Define it as barbie-bowtie
. You can use the color "pink"
or make official Barbie pink via the color
function with a RGB values of 218, 24, and 132 respectively.
Activity 8. Flag of Chicago
Now, make the flag of Chicago:
You might need some more functions than the ones we have discussed so far. You may find radial-star
and overlay/xy
to be helpful. Remember all the functions in the ISL are explained in the documentation (linked earlier) and your image doesn’t need to be exact! Define it as flag-of-chicago
. And again, make sure that you can sketch out the dataflow diagram for it.
How close does it need to be?
This is is one of those times where it benefits students to NOT ask for specifics. The more specific I get, the more expectations I have of exact precision. For this design, my standard will be: "If you showed this to a person, and said 'this is the flag of chicago,' they either a) be like 'oh sick,' b) 'duh,', or c) squint their eyes, turn their head, and go 'okay....'.
Activity 9. Your Own Design
Make a custom image of your own design. It must have at least 4 shapes and 2 different colors. You could make a smiley face, a Frankenstein, a bowling ball, a logo, a checkerboard, a house – whatever you’d like. Define it as my-custom-design
. We might feature some of the best ones in class next week! If you’re really proud of your design, post on our edSTEM brag post (will go live Monday after class).
Double Check your Work
Make sure you’ve uncommented all of those built-in check-expect
calls as they will double check you’ve defined all of your variables correctly. Also, after you submit, keep an eye out for the Canvas comment that the TypeChecker will post for you that double checks your built-in tests as well as the types of the various things we’ve asked you to define (starts on Tuesday).