CSci 150: Foundations of computer science I
Home Syllabus Assignments Tests

Assignment 3: Rainbow

Due: 2:00pm, Thursday, September 17. Value: 30 pts. Submit to Sauron.

Compose a program that draws a rainbow, analogous to the one at right. I drew the image as 150 nested circles (GOvals), the largest 600 pixels in diameter and each successive one 3 pixels smaller in diameter than the last. Finally, I drew a white circle to get the white interior and a white rectangle to block off the bottom half of all the circles.

In class we were using setFillColor to fill our circles, but here you should use setColor here: The setColor method affects the circle's boundary as well as is interior, whereas setFillColor leaves the boundary black. You'll still want to use setFilled; otherwise only the border of each circle will be drawn, and some white pixels will be left between adjoining nested circles.

To compute the color of each rectangle, you'll want to vary the colors according to the below graph. The graph's red line indicates that the first 50 circles should have a red value of 250, while the blue line indicates that these circles should have a blue value of 0. The green line indicates that each circle's green value should vary from 0 for circle 0 to 250 for circle 50. Thus, the first circle will have only red, while the 50th circle will have an equal mixture of red and green, which appears yellow. As graphed, the 50th through 75th would have decreasing red values, while the green value stays constant at 250 and the blue value stays at 0.

Of course, you should strive to have a solution that involves as little repetition of code as possible. A solution that doesn't involve any loops will get very little credit.