This homework is a simplified version of this nifty assignment. First read through Ben Stephenson's description for the nifty background. But if you think my assignments are cryptic, try deciphering his details. I originally meant to faithfully recreate his instructions, but somewhere on the way, I lost the will to live.
So, here is a somewhat simplified version of his algorithm. We'll do it in Racket, of course.
w
by h
blue rectangle with a black outline, use this:
(cc-superimpose (colorize (filled-rectangle w h) "blue") (rectangle w h))
randoms
that takes a seed value and a length, producing a list of random numbers between 0 and 1 (i.e., divide xn by m). The first element of the list should be the seed divided by m.w
and height h
inside a big rectangle with dimensions width
by height
, and a random number r
between 0 and 1, we say that the small rectangle is
w > 50
and w / width > 0.5 * r
h > 50
and h / height > 0.5 * r
(mondrian width height rands)
that receives the dimensions and a (sufficiently long) list of random numbers and returns a list of length 2. The first element is the Mondrian painting (nested hc-append
, vc-append
, cc-superimpose
). The second element is the un-consumed tail of the random numbers. You can use (list ... ...)
to make this list and first
/second
to take it apart.(mondrian 40 40 '(0.5 0.07 0.42))
, and you should get back a red square and a list containing the unused 0.42.define let let* letrec lambda first second rest list map cond else and modulo + - * / = >Ask on Piazza if you feel the need to use anything else.
letrec
:
(define (mondrian width height rands) (letrec ( (wide-enough (lambda (w r) (and (> w 50) (> (/ w width) (* 0.5 r))))) ... (mondrian-helper (lambda (...) ...))) (mondrian-helper ...)))
mondrian.rkt
containing the definitions of randoms
, mondrian
, and any helper functionsmondrian.png
that contains an image that you found pleasant—vary the width, height, and random number seed a bit, and pick your favorite. Here is mine:mondrian.rkt
. Do not turn in any of the interactions/definitions file that Dr. Racket saves.tests.rkt
containing tests that produce a list of 100 random numbers, a single blue square, a white rectangle atop a red rectangle, a yellow rectangle next to a white rectangle, a rectangle that is split in four with one blue and three white rectangles (consuming 11 random numbers), and finally the input that produced your image. IMPORTANT Your tests.rkt
file should save these five pictures into files test1.png
, test2.png
, test3.png
, test4.png
, and mondrian.png
. To save a file, include the definition of the following function in your tests.rkt
file:
(define (save-pict picture filename) (send (pict->bitmap picture) save-file filename 'png))The grader will run these commands:
cat mondrian.rkt tests.rkt | racket -l slideshow -i cat mondrian.rkt horstmanntests.rkt | racket -l slideshow -i
project.txt
providing your favorite project topic and team mates.