function-name : first-input-type second-input-type ... -> output-typeFor example, the function to find the area of a rectangle has the contract
rectangle-area : num num -> num
since it takes two numbers (the width and height) as input, and returns a number corresponding to the area.
A quick note about coding style: Indentation and line-breaks make your code easy to read and are good programming practices, so please pay attention to them. For example, here's a definition for the area of a trapezoid:
;; trapezoid-area : num num num -> numThat's a lot of code on one line! Here's an indented version:
;; computes the area of a trapezoid using the standard formula
(define (trapezoid-area base top height) (* height (/ (+ base top) 2)))
;; trapezoid-area : num num num -> numThe convention for line-breaks is to put a break after the function header, and then a break after the first operand in each expression. We usually don't break very short expressions like (+ base top). DrRacket should indent your code automatically if you insert a line break (by pressing Enter or Return). If it does not, press Tab with your cursor anywhere at the line you're indenting.
;; computes the area of a trapezoid using the standard formula
(define (trapezoid-area base top height)
(* height
(/ (+ base top)
2)))
Type svn co https://phoenixforge.cs.uchicago.edu/svn/yourusername-cs105-aut-12 into the Terminal, replace yoursername with your CNet username. If you get a prompt asking you if you would like to accept the certificate, press p (meaning to accept permanently). Enter your CNet password when prompted for it.
mkdir lab2Now click on this lab2.rkt link to download the lab2.rkt file and save it in your yourusername-cs105-aut-12/lab2 directory you just created. Now remember we only made local copies of your lab2 directory and lab2.rkt so you need to svn add these files to your repository. Type in the following commands:
svn add lab2Next, you will commit the lab2 directory to the repository. Remember we only told svn that on the next commit it should add the lab2 directory. Type in the following commands
cd lab2
svn add lab2.rkt
cd ..Note: cd .. takes you up one level in your directory structure (i.e. yourusername-cs105-aut-12/lab2 )
svn commit -m "Commiting the lab2 directory"
You may use any DrRacket operator for this lab except the scale function.
Define a function with the contract
blankface: num -> image
that draws a circle with the specified radius, of the color yellow if the radius is at least 75, and orange if the radius is less than 75. For example, (blankface 50) should draw an orange circle of radius 50, and (blankface 150) a yellow circle of radius 150. Use the cond statement you learned about in class.
eye : num -> image
which draws a cartoon-like eye of width = the input number, and height = twice the input number. For example, (eye 10) should produce something like
Use the ellipse function.
mouth : num -> image
which draws a grim mouth of width = the input number. Use the rectangle function. For example, (mouth 100) should produce something like
and (mouth 50) something like
(Notice how the height of the mouth is proportional to the width.)
face : num -> image
which generates a face. (face 50) should look approximately like this:
and (face 120) like this:
Don't sweat the small details of eye and mouth placement -- just make sure it looks more or less like a face. Make sure the entire face scales with the radius -- that is the sizes and positions of the eyes and mouth should be appropriate for the given radius. To test that it scales, uncomment the last expression before Part E in lab2.rkt (starting with beside), giving an output like this:
You are encouraged to write more auxiliary functions if it will make your task easier. The face function will be reasonably complex, so make sure you are indenting correctly.
smiley-face : num -> image
that produces a face of the given radius with a smile. The color should be orange or yellow depending on the radius just as before. If you uncomment the second-last expression in lab2.rkt, you should get something like this:
Hint: write a separate auxiliary function to create a smile. One way of getting the smile is to overlay two circles of the appropriate colors, and then crop the result midway. Use the crop function.
sick-face : num -> image
that produces a face of the given radius with a frown and Xs as eyes. The color should be orange or yellow depending on the radius just as before. If you uncomment the last expression in lab2.rkt, you should get something like:
Writing a function to produce a frown should involve a minor adaptation of the smile function.
Hint: To get the Xs write an additional function that uses the rectangles, rotate,and overlay functions.
svn commit -m "BLAH"where BLAH stands for a meaningful message. Have a nice day!