In the first few days of class, you have received a crash-course introduction to programming in Racket, in particular with images. Furthermore, you also learned about algorithmic decomposition and its importance in computer programming. In this brief demonstration exercise, we’ll practice these techniques further by playing around with images.
In this course, we’re concerned about writing good code. What does that look like? Good programs have two qualities we’re looking after:
External correctness is observable in the sense that we can run a program and determine that its behavior is correct. In contrast, internal correctness concerns the design of our program: Is it readable? Does it follow the design guidelines outlined in the exercise write-up and otherwise adhere to good coding conventions?
External correctness is often a given—we always want to write programs that do the right thing. However, we’ll find in this course that internal correctness is just as important! Computer programs are not just “consumed” by computers. Other people will read and even modify our programs. In particular, you will find that in three months (or perhaps sooner), you will feel like “another person”, forgetting what you were thinking when you were designing the program. So it is important that we build habits that are conducive to writing readable code.
As we discussed previously, programming is not a spectator sport (really, few things are in this world). You need to write programs to learn how to program. You often need to write programs to learn to think computationally. The labs and projects will be you primary vehicle for this sort of practice. This alone may be enough for some of you to master Racket programming. But for many people, you will need additional practice to truly master these concepts.
One way to do this is through “playing around.” What we mean by this is programming for the purposes of exploring a programming language or its libraries, rather than a specific end-product. This is how many of us approach learning a new language. We may have a few starting points in our back pockets, but as we write, we are less concerned about finishing the task at hand as we are about understanding the new environment. This exploration usually involves investigating and answering questions such as “How do I do X in this language?” or “How does feature X that I don’t understand compare to feature Y that I do understand?” or even “How does this language lead me to think differently about algorithm design?”
Because you are beginning programmers, your questions will likely be markedly simpler: “How can I even make a thing happen?” and “how do I type a thing?”. But nevertheless, “playing around” lets you tackle some of those ideas. You might start with one our lab exercises that you developed with a peer as a starting point and then change the code in ways that are novel to you. Or you might start from scratch and try to reproduce something you have seen or written before. There is no right way to go about “play”. Its the attitude that’s important: one of exploration and asking and answering questions rather than focusing on the final product.
For this assignment, you will create three files: spaceship.rkt, freestyle.rkt, and my-image-utils.rkt. The particular contents of each are detailed below.
For additional details on turning on this assignment and interpreting your feedback from it, please consult the Gradescope page.
Each file should have a format similar to this.
# lang racket
(require 2htdp/image)
(require csc151)
; spaceship.rkt
; Author: Stu Dent
; Mini-Project 1, Part 1
; Date: April 8, 2021
; Citations:
; XXX
; YYY
; Code here
For this first part of the assignment, your goal is to define an image called rainbow-spaceship that looks like this:

Here are the details of the rainbow-spaceship image:
The “horizontal pyramid” effect is due to how the image library places sub-images with beside when they are different heights.
Smaller images are automatically centered vertically relative to the taller images.
For example the left-most red stripe is vertically centered relative to the red-orange two-stack of stripes next to it.
Make sure that the definition of rainbow-spaceship mimics its structure.
Also pay special attention to remove redundancy from your code using define and, as appropriate, functions.
We do not yet have the machinery to elegantly capture the growing, symmetric nature of the columns of the spaceship.
However, note the relationship between the stripes of each successive column.
How can you capture this relationship in code?
Now that you’ve had a taste for manipulating images and using define and functions to reduce redundancy, you will now get the opportunity to play around making images of some complexity.
As discussed, this is open-ended: I have no particular image for you to draw and only some requirements about how you design your program.
Feel free to try the following starting points:
To encourage you to practice algorithmic decomposition, your program must follow these design requirements:
define command.define should be evocative of what the image is.
It should be pithy, a few words at most, but at the same time descriptive.
Racket programming conventions say that these names should be in all lowercase with dashes between words, e.g., names-like-this.define that is the overall image, which you should call my-image.; An amazing image of <...> I've created.Other than this, there are no minimum requirements regarding limits, code size, or complexity. Have fun with it!
As you have likely noted, as your images and programs grow in complexity, it is helpful to write procedures (functions, subroutines) that encapsulate and parameterize a piece of code. For example, you may find that you regularly want to build “blocks” by overlaying an outline on a solid figure.
;;; (block size color) -> image?
;;; size : non-negative-integer?
;;; color : color?
;;; Create a square block of the specified size and color
(define block
(lambda (size color)
(overlay (square size 'outline 'black)
(square size 'solid color))))
Write five (5) procedures that you think will be useful in building more complex images. Create a list of five images, one for each procedure, and call that list examples.
(define examples (list (block 20 'red) ...))
Once again, there are no minimum requirements regarding limits, code size, or complexity, have fun!
You are under no obligation to use additional functions or language features beyond what we have introduced in this first week.
However, You may feel limited by the functions we have discussed so far.
If so, you are free to reference the documentation for the 2htdp/image library for the full set of functions available:
Note that this documentation may not be entirely comprehensible to you yet! That is fine. If you choose to explore this library in more detail, I recommend experimenting with these functions in the interactions pane and figure out how they work before throwing them into your code. Remember, if you adapt any code from this library’s documentation, you should cite that you did so in a comment in your code!
In grading these assignments, we will look for the following for each level. We may also identify other characteristics that move your work between levels.
Submissions that lack any of these characteristics will get an I.
[ ] Includes the three specificed files.
[ ] Includes an appropraite header on each file that indicates the author, date, etc.
[ ] Code runs in DrRacket.
Submissions that lack any of these characterstics will get an R.
[ ] In Part 1, creates the correct spaceship.
[ ] In Part 2, includes at least five sub-images.
[ ] In Part 2, includes at least one procedure.
[ ] In Part 2, the image is correctly named `my-image`.
[ ] In Part 3, includes five helper procedures.
[ ] In Part 3, each helper procedure has at least one parameter.
[ ] In Part 3, includes the required `examples` list, which has the required form.
Submissions that lack any of these characterstics will get an M.
[ ] In Part 1, code is concise and avoids repetition.
[ ] In Part 2, image is particularly interesting or creative.
[ ] In Part 3, one or more of the helper procedures is especially innovative.