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:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started