Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:  image text in transcribed 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

LO 2-3 How to choose channels to reach your audience.

Answered: 1 week ago

Question

Does your companys code of conduct address this issue?

Answered: 1 week ago