Strings 2
Write each of these functions. Add at least one new check-expect of your own for each problem.
-
Given a word with at least 3 letters, the
tletterfunction gives the third letter.(check-expect (tletter "zebra") "b") (check-expect (tletter "stripe") "r") -
The
wordshowfunction makes an image of a given string in 48 point black font.(wordshow "Chicken") =>
-
The
winning-score : number -> imagefunction takes in a numberscoreand puts out an image the the following in 48 point black font.(winning-score 47)=>
-
Circular typing adds a new letter to the end of a string and at the same time removes a letter from the beginning, so the length stays the same.
(check-expect (circular-type "dinosaur" "s") "inosaurs") (check-expect (circular-type "page" "d") "aged") -
The
rletterfunction gives a random letter from the given word. Each appearance of a letter in the word is equally likely, so in “dad”, the “d” will be chosen twice as often as the “a”.(rletter "candy") => "c" (rletter "candy") => "y" (rletter "candy") => "a" -
Make an animation using a string model and some of the functions you wrote above. Use
wordshowfor the draw handler andcircular-typefor the key handler. Test it to make sure it works. -
Write a new mouse handler for your animation. The mouse handler selects a random letter from the string model, puts it on the end of the model, and removes the first letter so the length of the model stays the same.
Example: Suppose that the original model is
"candy"and the"a"is randomly selected. The new model would be"andya".