On this page:
Strings and Text
Text and Images
6.10

Lab 2: Text and Images

Implement this lab with the Beginning Student Language. Require the HtDP2e image library at the top of your definitions:

(require 2htdp/image)

Hint: You can search for documentation by right-clicking any identifier foo in the definitions or interactions windows and choosing ’Search in Help Desk for "foo"’ menu option. You can also press <F1> to search for documentation about any identifier under the cursor.

Choose the initial Head and Hands, and get started!

Strings and Text

Your TAs hope to break into the lucrative & high-stakes world of banner making and advertising. Unrelated, the theme of today’s lab is working with strings, text, and images.

Ex 1: Define a function greet-tracked-person that, given the string name of some person and a string slogan, returns a string with a personalized slogan such as:

You may find the function string-append useful. Test your function with check-expect.

Ex 2: Strings and images are different types of values and we want both in our advertisements. Write a function big-and-red that, given some string str, returns an image of str colored red and in a 64pt font of your choice.

Hint: When you need to do something but don’t know how, look at the signatures of functions in the documentation. If you need to convert a string into an image, don’t just search for string->image and give up if you see no results, look for a function that takes in a string a returns an image. Test it out, and if it’s not what you need, keep looking!

Bonus: Some slogans are just too long, so define a new function no-more-than-32 that, given a string, returns that string with no more than the first 32 characters. One of the BSL string operations provides a simple way to do this for strings at least 32 characters long, but may not work for shorter strings. A clever use of min and string-length will let you solve this without resorting to cond, which we’ll use in the future.

Text and Images

Swap Head and Hands.

Ex 3: Logos and slogans go hand-in-hand, so define a function logo-and-slogan that, given an image logo and a string slogan, returns an image with the logo to the left of the text of the slogan (try to make it large and in an obnoxious font). Copy your favorite logos from the internet into your definitions window to test your implementation.

Ex 4: Some companies find that people accidentally overlook even their best advertisements. Define a function four-must-be-better that, given an image, stacks four copies of that image vertically so it can’t be missed.

Ex 5: We find the close button in our prototype is too easy to click, so we want to change the size of our advertisements dynamically so the close button is harder to click. Define a function on-background-of-width that, given an image and some positive integer width, places the image on a background rectangle of any color that is 200 pixels high and width pixels wide.

Bonus: Using the functions you’ve defined, define a function animation that, given a non-negative integer width, returns an image of your favorite logo and slogan on a background 200 pixels high and width pixels wide. Require the 2htdp/universe library, and use the function animate to demo the growing advertisement.