Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#Cprogramming #drawingcircle Task: draw_circle() You must write a function that

ID: 3775949 • Letter: #

Question

#Cprogramming #drawingcircle

Task: draw_circle()

You must write a function that draws a filled circle into an image array of the same type as in Lab 3.

Requirements

Create and add a single C source file called "t1.c".

"t1.c" should contain the function draw_circle() and agree exactly with this function declaration:

The image array img, and its sizes (cols,rows) should be interpreted in the same way as for Lab 3.

The function draws a filled circle in the image array in the specified color.

The center of the circle is at the center of the pixel at the coordinate {x,y} and it has the specified radius in pixels.

Note that x and y may fall outside the image.

On return, every pixel that contains a point inside the defined circle i.e. (distance to {x,y} < radius (NOT <= radius) ) must be set to color. Do not set the color of any other pixel.

For a radius of zero, do not set any pixels.

When rounding floating point calculations, round to the nearest integer, with 0.5 rounded up to 1.

Example

You might find these examples helpful for interpreting the specs. In every case the image array imghas been zeroed in advance.

Note: this is 9 white pixels in the center of the image. Why does a radius of 1 cause 9 pixels to be filled? We are considering all the points in the pixel and not just the point at the centre of the pixel. This diagram shows all the pixels that contain points less than R=1 from the center of the pixel at (x,y):

Explanation / Answer

//main.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "imgops.h"
#include "t1.h"


int main() {

for( int i=10; i>0; i-- )
draw_circle( img, 64, 32, 32, 16, 2*i, 200/i+55);
  
  
return 0;
}

==================================================================

draw.c

imgops.h

========================================================================