22a. Hangman Images
How to load a sequence of images into DrRacket.
Goal for the day: produce a sequence of images to use for “hangman” and load it into Racket.
Image sequence
Draw a sequence of images hang-0.png
, hang-1.png
, etc., with the appropriate number of parts of the person filled in. Use “File -> Export as…” to save each file with a different name.
Tools:
- Microsoft Paint on Windows
- Paintbrush (download) on Macintosh. You will need to hold down Control when you click on the application to allow it to open for the first time.
- Gimp on Linux.
Make a Racket function
- Load images into Racket.
- Write a function that takes in the number of mistakes and returns the correct image of the gallows.
The best way to load an image from a file is to use bitmap/file
.
Examples:
(bitmap/file "hang-0.png")
(bitmap/file "pics/hang-1.png")
note
For the simplest loading, save the Racket file in the same folder as your images. “Untitled” programs will not find your images - save!Why?
The only cases of file corruption I have seen involve large images being pasted into DrRacket files. Keeping the images in separate files prevents that problem.