The exercise is asking to make wider stripes similar to the previous exercise. I've included the exercise and code from it along with code that I've been messing with to get the desired result.
I know it can be done easily with loops, but the point of the exercise is to use what has been already introduced in the book. http://www.facom.ufu.br/~marcelo/PF/pictures_racket.pdf
I need a way to implement a series expression (5n+4) in order to get the result I desire.
I'm starting to think there isn't a way without looping or using if statements ect... (trying to use conditionals only is the goal here) I think what I have will suffice, but I know it's not right and the book will show a better way later on I assume.
I would like some feedback on the first exercise if there was a way to improve it and some critiquing on the wide-stripe logic as well.
The exercise or code isn't complete, but you can see where I'm going with it if you run the code. I'm missing a cleaner way to write it, but it hasn't struck me yet.
(require picturing-programs) ; builds an image black to red from left to right (see above lines 282-305) (define (always-zero x y) ; x a number ; y a number 0 ) (define WIDTH 150) (define HEIGHT 100) ; make-stripes : number number -> Image ; Takes in a width and height to create a shape ; with even and odd numbered stripes (define (red-stripe x y) (cond [(= (modulo (* y y) 2) 0) 255] [else 0])) (define (blue-stripe x y) (cond[(= (modulo (* y y) 3) 1) 255] [else 0])) (define (make-stripes width height) (build3-image width height red-stripe always-zero blue-stripe)) ; another-make-stripe-function (define (add5 y) (+ y 5)) (define (red-stripe2 x y) (cond [(even? (add5 y)) 255] [else 0])) (define (blue-stripe2 x y) (cond[(odd? (- 150 y)) 255] [else 0])) (define (make-wide-stripes width height) (build3-image width height red-stripe2 always-zero blue-stripe2)) (build3-image 150 100 red-stripe2 always-zero blue-stripe2) (define red (color 255 0 0 255)) (define blue (color 0 0 255 255)) (define total-rows (/ HEIGHT 5)) ;20 (define (row y) (+ y 5)) ; (define (0-4? n) (and (>= n 0) (<= n 4))) (define (5-9? n) (and (>= n 5) (<= n 9))) (define (10-14? n) (and (>= n 10) (<= n 14))) (define (15-19? n) (and (>= n 15) (<= n 19))) (define (20-24? n) (and (>= n 20) (<= n 24))) (define (25-29? n) (and (>= n 25) (<= n 29))) (define (blue-or-red x y) (cond [(0-4? y) blue] [(5-9? y) red] [(10-14? y) blue] [(15-19? y) red] [(20-24? y) blue] [(25-29? y) red] [else blue])) (define (random-br-picture width height) (build-image width height blue-or-red)) (build-image 150 100 blue-or-red)