|
||||||||||||||||||||||
Problem Set 2: Repetition Assigned: Tuesday January 26, 2016 Due: Thursday February 4, 2016, midnight This is a pair problem set. You must work with a partner. If you don't know anyone yet (perfectly understandable!), you can use the Piazza partner finding tool or you can ask a staffer to help you find a partner.
This problem set consists of SetupStart by downloading the harness code. Put the compressed archive in a handy place and unpack it. Next, rename the folder from 02.ps.harness to your surname followed by the digit 2. (Mine would be named Muller2.)The problems in the part1 and part2 folders both have Makefiles and can be compiled using the Unix make command as in:
All of the problems in both parts are couched in terms of writing a specific function. Each function has a stub including failwith "Not yet implemented". In order to solve the problem, replace the stub with your code.
Part 1 (3 Points Total): Working with Booleans, Strings and Numbers
Part 2 (10 Points up to 12 Total): Working with DrawingsThe problems in Part 2, labeled A through F, all involve writing functions that use some of the Universe functions to draw images in the graphics window. As we've discussed in class, the graphics window is Cartesian or xy-plane, but with y=0 at the top rather than the bottom.Parts C, D and E involve drawing rings in the graphics window; all are worth 2 points. Part F requires a drawing of squares running on a diagonal. Parts A, B, C and D are relatively simple and can be done right away. Parts E and F require repetition. Note that Part F is optional extra credit. The problems in Part 2 refer to the following images.
Part A (2 Points) twoColorsWrite a function twoColors : unit -> Color.t such that a call (twoColors()) has equal chances of returning either Color.black or a randomly generated color.Part B (2 Points) randomStripeWrite a function randomStripe : unit -> Image.t such that a call (randomStripe()) returns a square the size of the graphics window with a horizontal stripe that is half the height of the graphics window. The stripe should be centered and should have a 50% chance of being Color.black and 50% chance of being a random color.Part C (2 Points) ringWrite a function ring : float -> float -> Color.t -> Image.t such that a call (ring radius width color) returns a ring with a radius, width and color as given.Part D (2 Points) Random RingsWrite a function randomRing : Image.t -> Image.t such that a call (randomRing image) returns a new image that is just like the input image but it contains a newly placed random ring. By "random ring", we mean a ring with a random radius, random width, random color and which is placed at random (x, y) coordinates in image.Part E (2 Points) rowOfRingsWrite a function rowOfRings : int -> Image.t such that a call (rowOfRings n) returns a rectangle containing n rings with equal diameters and with random widths and random color. The height of the rectangle should be the diameter of the rings and the width should be the displayWidth.Part F (2 Points) Diamonds (optional extra credit)Write a function diamonds : int -> Image.t such that a call (diamonds n) returns an image containing n randomly colored squares of equal size running from upper left to lower right.PART 3 MOVED, Now Part 2 of Problem Set 3 |