ASCII drawing in C

Job ID: 33064571

Budget: $30 – $250 USD

Develop a program called Draw that creates images using only 10 ASCII characters. The program will create an image by reading a sequence of instructions and progressively building up an image. The program supports four drawing operations:

Draw a point - Adds a single point.
Draw a rectangle - Adds a filled rectangle.
Draw a line - Adds a line between two points.
Flood fill an area - Floods an area with a color.
Here is an example of the final output of the program for one particular data file:

% ./Draw < plus.txt
+---------+
|::: @----|
|:+: @--+-|
| @----|
|%%%%%%%%%|
|====@####|
|=+==@####|
|====@####|
+---------+
Color range [0.00, 1.00], average 0.5048

The draw.zip contains a stub program Draw.c containing a mostly completed main function. The main function handles reading in the data file and calling various functions that create the image, display it, and calculate the final line of statistics. You need to complete the missing function calls that handle reading input using scanf (see the TODO comments). There are also 7 functions declared in Draw.c. Your job is to add the correct parameters to each function and to implement the body of each of the functions. Rules:
Do NOT use global variables (i.e. a variable declared outside the body of any function).
Do NOT change the name of the 7 functions.
Do NOT change the return type of the 7 functions.
You may add additional helper functions of your own if you want (but you are not required to).
Program input. Your program is controlled by a file redirected to the program as standard input. While the provided main function handles reading this for you, it will be helpful to understand the format. Here is the data file for the above image:

% cat plus.txt
9 7

l 4 -1 4 7 1.0
l -1 3 9 3 0.8

r 0 0 3 2 0.2

p 1 1 0.5
p 7 1 0.5
p 1 5 0.5
p 7 5 0.5

f 0 0 0.1
f 8 0 0.3
f 0 6 0.4
f 8 6 0.7

- The first line specifies that the image will be 9 characters wide by 7 characters tall. The main program assumes images are at least 1 character wide and 1 character tall. As is typical in computer graphics (and unlike graphs in math), we will treat (0, 0) as the top-left coordinate. The x-coordinate increases as you go right. The y-coordinate increases as you go down.
- The l (lowercase "L") lines draw a line. After the l comes the (x1, y1) and (x2, y2) coordinates of the line's end points. This is followed by a floating-point value specifying the greyscale color of the line. Note that while both lines have coordinates outside the image's area of (0, 0) - (8, 6), the program still works and doesn't crash.
- The r lines draw a rectangle. After the r comes the left (x) and top (y) coordinate of the rectangle. This is followed by the rectangle's width, height, and color.
- The p lines draw a single point at the specified x- and y-coordinate with the given color.
- The f lines cause a flood fill that starts at the specified coordinate. A flow fill spreads out from this coordinate, changing pixels to the specified color. The flood fill stops when it hits a pixel that is at least as dark as the color of the flood fill. For example in the above example, the 4 flood fills each only fill one of the 4 regions made by the two lines since the lines are darker than the fill color.

Data format. The image is stored as a two-dimensional array of double values. Whenever the main program calls one of your functions, it passes the width, height, and the 2D array as the first three parameters to your function. Depending on the function, other additional parameters may be passed in (see the provided main program).

* More Info Given along with the zip files.
Related categories: C Programming Algorithm C# Programming