Question: Write a program that draws 2 white circles somewhere in a dark gray rectangular (not square) PGM. You may hard-code the row and column locations,

Write a program that draws 2 white circles somewhere in a dark gray rectangular (not square) PGM. You may hard-code the row and column locations, radius and brightness levels for the two circles, or make it a little more challenging and prompt the user for the circle information.

For this, it may be helpful to use the sqrt( ) function, which returns the square root of a number. For example:

y = sqrt(2.0);

sets y to ~1.414. If the distance of a pixel from the center of the circle is less than the radius, you're inside the circle. Otherwise you're outside.

Outside the circle, assign the each pixel a random number between 0 & 64. (See the rand(...) function in chapter 3. The modulus operator will come in handy to truncate your random numbers to a value between 0 and 255.

For more excitement (this IS exciting, isn't it?) you could shade the the circles as you get closer to the center, or shade the random numbers outside the circle. Here's a circle example, with shading towards the center of the circle. (This is from a previous semester, where the challenge was to draw a single black circle on a random background, centered in the image):

 pgm name? circle.pgm ncol, nrow? 640 480 radius? 192 done writing PGM to circle.pgm sample solution looks like this:   Write a program that draws 2 white circles somewhere in a 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!