hello everyone,<br> i have created a programme which works fine and not in the way intended by problem statement. here is the problem statement copied as it is from HtDP.<br><b><span style="font-weight: bold;">
<br>-- </span>Exercise 11.3.5.</b>
Develop a program that visualizes a student riot. In preparation of a
student riot, a small group of students meets to make paint-filled
balloons. The typical riot uses <code class="scheme"><span class="keyword">'</span><span class="variable">red</span></code> only. Then, on the evening of
the riot, the students enter a university's progressive theater with the
balloons and throw them all over the seats.
<p>
</p>
<p>
The program's only input should be a natural number, which represents the
number of balloons thrown. The visualization should use a canvas that
contains a black grid and the positions of the balls.Assume a random distribution of the balls over the theater's
seats. Each box in the grid represents a seat. Configure the program so
the change of one variable definition changes the number of columns in the
grid and a change to another changes the number of rows.</p>
<p>
<strong>Hint:</strong> Develop auxiliary functions that draw some given number of lines in the
vertical and the horizontal direction. ----<br></p>my solution works not with function call : (riot n)<br>but with (draw-baloons (riot n))
<br><br>also < riot > consumes only one agument but i had to use radius of disk (red baloons) as an extra in its body as shown down here.<br><br>may you help me on modifying <riot > according to the problem statement?
<br><br>"arnuld"<br><br>---------------------- start of programme -------------------------------------------<br>(define ROWS 5)<br>(define COLS 5)<br>;; i created variable definitions of COLS & ROWS because problem wants so
<br>;; hence you can change the values of COLS & ROWS here in variable definitions and effect will be <br>;; transfered into the variables & functions which use these 2 variables<br>;; same is for canvas<br><br>(define canvas-x 300)
<br>(define canvas-y 300)<br>(define dist-ROWS (quotient canvas-y ROWS))<br>(define dist-COLS (quotient canvas-y COLS))<br>(define radius 5)<br><br>(define (riot n)<br> (cond<br> [(zero? n) empty]<br> [else (cons radius (riot (sub1 n)))]))
<br><br>(define (draw-balloons a-lon)<br> (cond<br> [(empty? a-lon) true]<br> [else (draw-all a-lon)]))<br><br>(define (draw-all a-lon)<br> (and (draw-solid-disk (make-posn (random canvas-x)<br> (random canvas-y))
<br> (first a-lon)<br> 'red)<br> (sleep-for-a-while 1)<br> (draw-balloons (rest a-lon))))<br><br>;; ------------ draw columns and rows here -------------------------------
<br><br>(define (draw-COLS COLS)<br> (cond<br> [(zero? COLS) true]<br> [else (and (draw-solid-line (make-posn (* COLS dist-COLS) 0)<br> (make-posn (* COLS dist-COLS) canvas-y) 'black)
<br> (draw-COLS (sub1 COLS)))])) <br><br>;; change the values of COLS & ROWS in variable definitions and effect will be here into these <br>;; functions<br><br>(define (draw-ROWS ROWS)<br> (cond<br> [(zero? ROWS) true]
<br> [else (and (draw-solid-line (make-posn 0 (* ROWS dist-ROWS))<br> (make-posn canvas-x (* ROWS dist-ROWS)) 'black)<br> (draw-ROWS (sub1 ROWS)))]))<br><br>;; tests<br>(start canvas-x canvas-y)
<br>(draw-COLS COLS)<br>(draw-ROWS ROWS)<br><br>(draw-balloons (riot 20))<br><br>(sleep-for-a-while 1)<br>(stop)<br><br>------------------------ end of programme ------------------------------------------<br clear="all"><br>
-- <br>"the great intellectuals"