DAY 3 OF BOOTSTRAP STRINGS AND IMAGES S I T I N YO U R PA I R S . G R A B YO U R C H R O M E B O O K S A N D L O G I N TO W E S C H E M E . O R G STRINGS AND IMAGES One of these things is not like the other… • 12 -53 “hello” 4.9 A string is anything between quotation marks. What happens if you put quotes around multiple words? Around numbers? Try entering different strings into the Interactions window. 2 How would you convert this to code? star (star 5050 “solid” “red”) “solid” “red” A new function called star. (star has been defined previously in the computer program) The addition function + takes in two Numbers and produces a Number The function called star takes in a number and two strings and produces a new type of data, called an Image. (star 50 “solid” “red”) Try this in your interactions window. What is the datatype of each of the values listed below Number String or Image? Domain of a function is its input or the data the function expects. Examples: • The function + has a domain of two numbers • The function – has a domain of two numbers • The function star has a domain of a number and two strings We need to keep track of the required inputs for each function By keeping a list of all the functions in a language, and their Domains, programmers can easily look up how each function is used. It’s also important to keep track of what each function produces. • For example, a program wouldn’t use star if they were trying to produce a Number, because star only produces Images. The Range of a function is the data that the function produces. CONTRACTS A contract has three parts: – The Name • Example: Star – Domain • Example: A number and Two Strings – Range • Example: Image The Contract is: ; star: Number String String Image Write the contract for star in the back page of workbook Here is the contract for a new function rectangle ; rectangle: Number Number String String Image • • • • What is the Name of this function? How many things are the Domain of this function? What is the type of each thing in the Domain? What is the Range of this function? Write the contract for rectangle in your contracts page MORE IMAGE FUNCTIONS ; circle : Number String String Image ; ellipse: Number Number String String Image ; triangle: Number String String Image ; rectangle: Number Number String String Image ; text: String Number String Image ; rotate : ; scale: Number Image Number Image …and dozens more! Image Image 12 (3+4)=7 What would the contract be of this expression? ; + : NUMBER NUMBER NUMBER Write the contract for +, -, *, / on your contracts page? CONTRACT OR CODE? ; triangle : Number String String Image (triangle 100 “outline” “blue”) ; square : Number String String Image (square (+ 200 5) “solid” “red”) Figure out the domain and range of the following: rhombus right-triangle radial-star star-polygon Write the contract for each in your contracts page. IMAGES CAN BE INPUTS You can use the function: flip-horizontal to flip your image from left to right CONTRACT CODE ; flip-horizontal : Image Image (flip-horizontal (right-triangle 50 20 “outline” “red)) Convert the racket code to a contract and add to your contract page (flip-vertical (triangle 50 “outline” “orange”)) (scale 2 (text “resize” 10 “purple”)) (rotate 45 (text “spin” 30 “green”)) Experiment with the code in the interactions window
© Copyright 2026 Paperzz