Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Assignment 1 19T2 COMP1511: CS Paint
- // paint.c
- // This program was written by Josh Amoils (z5256967).
- /* Overview: This program simulates the 'Paint' tool used on many computers
- today. The canvas is comprised of a 2D array of numbers that correspond to
- different shades. As outlined in the spec, this program executes functions to
- simulate the use of various tools used in 'Paint' such as the Line Drawing,
- Rectangle Drawing, Shading and Additive Brush tools.
- Limitations: This program achieves all the requirements outlined in the spec.
- However, the functionality of this program is limited if it were to be
- practically used as a replacement to 'Paint'; this program only draws
- 45 degree diagonal lines, has only 5 shading options and can only use an
- additive brush of size 3 x 3 pixels.
- Understanding the code: The program is structured as follows:
- 1. The Main Function: Scans in the first number of an input command line
- and directs the program to the relevant general tool function.
- 2. The General Tool Functions: Each tool has a general function that
- assesses the validity of the input commands and runs smaller functions
- depending on the relevant positions of the inputted start and
- endpoints.
- 3. The Smaller Functions: Each of these void functions directly change
- the state of the canvas in one specific way. Most of these smaller
- functions are named as follows,
- "General Function: Smaller Function". */
- // Libraries used in this program.
- #include <stdio.h>
- #include <stdlib.h>
- // The dimensions of the canvas (20 rows x 36 columns).
- #define N_ROWS 20
- #define N_COLS 36
- // Shades (assuming your terminal has a black background).
- #define BLACK 0
- #define DARK 1
- #define GREY 2
- #define LIGHT 3
- #define WHITE 4
- // Instruction commands for each tool
- #define LINE_DRAWING 1
- #define RECTANGLE_DRAWING 2
- #define SHADE_CHANGE 3
- #define COPY_AND_PASTE 4
- #define ADDITIVE_BRUSH 5
- // Defines the size of the command array (# of commands) by action_command.
- #define LINE_INPUT_SIZE 4
- #define RECTANGLE_INPUT_SIZE 4
- #define COPY_PASTE_INPUT_SIZE 6
- #define ADDITIVE_BRUSH_INPUT_SIZE 9
- // Types of Brushes.
- #define NORMAL 0
- #define ADDITIVE 1
- // 2D Dimension of Additive Brush.
- #define ADDITIVE_BRUSH_DIMENSION 3
- // Prototypes
- // Prints out the canvas.
- void printCanvas(int canvas[N_ROWS][N_COLS]);
- // Sets the entire canvas to be blank.
- void setBlankCanvas(int canvas[N_ROWS][N_COLS]);
- // Gets inputs for the commands array.
- void get_commands(int commands[], int input_size);
- // Checks if a given row/column coordinate lies on the canvas.
- int valid_row(int row);
- int valid_col(int col);
- int valid_bounds(int start_row, int start_col, int end_row, int end_col);
- // General Line Drawing function (includes additive brush functions).
- void line(int canvas[N_ROWS][N_COLS], int start_row, int start_col, int end_row,
- int end_col, int shade, int brush,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]);
- // Line Drawing: Horizontal line.
- void horizontal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- // Line Drawing: Vertical line.
- void vertical_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- // Line Drawing: Diagonal line with positive or negative gradient.
- void pos_diagonal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- void neg_diagonal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- // General Rectangle Drawing function.
- void rectangle(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- // Rectangle Drawing: Makes Rectangle change on canvas.
- void draw_rectangle(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade);
- /* Copy/Paste Function: Comprised of a copy section (4 cases) and a
- paste section. */
- void copy_and_paste(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int target_row, int target_col);
- // Copy/Paste Function: Copy Function.
- void copy(int row_size, int col_size, int copy_array[row_size][col_size],
- int canvas[N_ROWS][N_COLS], int start_row, int start_col, int end_row,
- int end_col);
- // Copy/Paste Function: Paste function.
- void paste(int row_size, int col_size,
- int copy_array[row_size][col_size], int canvas[N_ROWS][N_COLS],
- int target_row, int target_col);
- /* General Additive Brush function (Stamps one pixel at a time with the current
- additive brush settings. */
- void additive_stamp(int canvas[N_ROWS][N_COLS],
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION],
- int row_counter, int col_counter);
- // Additive Brush: Inputs additive brush settings.
- void additive_input(
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION],
- int commands[ADDITIVE_BRUSH_INPUT_SIZE]);
- // Additive Brush: Draws Horizontal line with additive brush settings.
- void additive_brush_horiz(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]);
- // Additive Brush: Draws Vertical line with additive brush settings.
- void additive_brush_vert(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]);
- /* Additive Brush: Draws Diagonal line with positive gradient with
- additive brush settings. */
- void additive_brush_pos_diagonal(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]);
- /* Additive Brush: Draws Diagonal line with negative gradient with
- additive brush settings. */
- void additive_brush_neg_diagonal(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]);
- /* Checks if the a pixel's shade is still valid after the additive brush has
- been applied. If it is not, this function will set the pixel to either
- White or BLACK. */
- int valid_shade(int shade);
- //Main Function
- int main(void) {
- /* Declares the canvas, action_command and the 2D array that stores the
- additive brush settings. */
- int canvas[N_ROWS][N_COLS];
- int action_command;
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION];
- /* Sets the default shade to BLACK and the default brush to
- NORMAL (non-additive). */
- int shade = BLACK;
- int brush = NORMAL;
- // Makes canvas blank.
- setBlankCanvas(canvas);
- /* Checks if command input exists and assigns it to the action_command
- (the first number inputted on every line by the user).
- The action_command is then used to direct the main function to the
- relevant cs_paint functions. */
- while (scanf("%d", &action_command) == 1) {
- // Resets the shade to the second command if it's a valid shade.
- if (action_command == SHADE_CHANGE) {
- int possible_shade;
- scanf("%d", &possible_shade);
- if (possible_shade >= 0 && possible_shade <= 4) {
- shade = possible_shade;
- brush = NORMAL;
- }
- }
- /* Collects subsequent commands and directs the program to the Draw Line
- functions, taking into account the current shade and brush. */
- if (action_command == LINE_DRAWING) {
- int commands[LINE_INPUT_SIZE];
- get_commands(commands, LINE_INPUT_SIZE);
- line(canvas, commands[0], commands[1], commands[2], commands[3],
- shade, brush, add_shade);
- }
- /* Collects subsequent commands and directs the program to the Rectangle
- function, taking into account the current shade. */
- else if (action_command == RECTANGLE_DRAWING) {
- int commands[RECTANGLE_INPUT_SIZE];
- get_commands(commands, RECTANGLE_INPUT_SIZE);
- rectangle(canvas, commands[0], commands[1], commands[2],
- commands[3], shade);
- }
- /* Collects subsequent commands and directs the program to the
- Copy/Paste function. */
- else if (action_command == COPY_AND_PASTE) {
- int commands[COPY_PASTE_INPUT_SIZE];
- get_commands(commands, COPY_PASTE_INPUT_SIZE);
- copy_and_paste(canvas, commands[0], commands[1], commands[2],
- commands[3], commands[4], commands[5]);
- }
- /*Collects subsequent commands and directs the program to the additive
- brush customisation function. Inputs the whole command array into
- the additive_input function rather than individual values as shown in
- the other commands.This increases the maintainability of the additive
- brush feature, allowing the brush size to be easily adjusted for
- different stamp sizes.*/
- else if (action_command == ADDITIVE_BRUSH) {
- int commands[ADDITIVE_BRUSH_INPUT_SIZE];
- get_commands(commands, ADDITIVE_BRUSH_INPUT_SIZE);
- additive_input(add_shade, commands);
- brush = ADDITIVE;
- }
- }
- // Prints the canvas after all the adjustments.
- printCanvas(canvas);
- return 0;
- }
- // Functions
- // Collects Commands and stores them in an array called "commands".
- void get_commands(int commands[], int input_size) {
- int counter = 0;
- while (counter < input_size) {
- scanf("%d", &commands[counter]);
- counter++;
- }
- }
- // Checks if a row value is valid.
- int valid_row(int row) {
- int valid = 0;
- if (row >= 0 && row < N_ROWS) {
- valid = 1;
- }
- return valid;
- }
- // Checks if a column value is valid.
- int valid_col(int col) {
- int valid = 0;
- if (col >= 0 && col < N_COLS) {
- valid = 1;
- }
- return valid;
- }
- // Checks if input bounds are valid.
- int valid_bounds(int start_row, int start_col, int end_row, int end_col) {
- int valid = 0;
- if (valid_row(start_row) && valid_row(end_row) && valid_col(start_col) &&
- valid_col(end_col)) {
- valid = 1;
- }
- return valid;
- }
- // Lines Drawing
- void line(int canvas[N_ROWS][N_COLS], int start_row, int start_col, int end_row,
- int end_col, int shade, int brush,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]) {
- // Checks if the commands are valid.
- if (valid_bounds(start_row, start_col, end_row, end_col)) {
- // If brush is normal, program uses Stage 1/2 functions.
- if (brush == NORMAL) {
- /* Draws a Horizontal line, taking into account the forwards and
- backwards cases. */
- if (start_row == end_row) {
- if (start_col < end_col) {
- horizontal_line(canvas, start_row, start_col, end_row,
- end_col, shade);
- }
- else {
- horizontal_line(canvas, start_row, end_col, end_row,
- start_col, shade);
- }
- }
- /* Draws a Vertical line, taking into account the forwards and
- backwards cases. */
- else if (start_col == end_col) {
- if (start_row < end_row) {
- vertical_line(canvas, start_row, start_col, end_row,
- end_col, shade);
- }
- else {
- vertical_line(canvas, end_row, start_col, start_row,
- end_col, shade);
- }
- }
- /* Draws a Diagonal line. If the distance between the rows is equal
- to the difference between the columns, the line is angled at
- 45 degrees. */
- else if (abs(end_row - start_row) == abs(end_col - start_col)) {
- // Line with negative gradient.
- if (start_row < end_row && start_col < end_col) {
- neg_diagonal_line(canvas, start_row, start_col, end_row,
- end_col, shade);
- }
- else if (start_row > end_row && start_col > end_col) {
- neg_diagonal_line(canvas, end_row, end_col, start_row,
- start_col, shade);
- }
- // Line with positive gradient.
- else if (start_row > end_row && start_col < end_col) {
- pos_diagonal_line(canvas, start_row, start_col, end_row,
- end_col, shade);
- }
- else if (start_row < end_row && start_col > end_col) {
- pos_diagonal_line(canvas, end_row, end_col, start_row,
- start_col, shade);
- }
- }
- }
- /* Directs program to Draw Line functions that take into account current
- additive brush settings. */
- else if (brush == ADDITIVE) {
- // Horizontal line.
- if (start_row == end_row) {
- if (start_col < end_col) {
- additive_brush_horiz(canvas, start_row, start_col, end_row,
- end_col, add_shade);
- }
- else {
- additive_brush_horiz(canvas, start_row, end_col, end_row,
- start_col, add_shade);
- }
- }
- // Vertical line.
- else if (start_col == end_col) {
- if (start_row < end_row) {
- additive_brush_vert(canvas, start_row, start_col, end_row,
- end_col, add_shade);
- }
- else {
- additive_brush_vert(canvas, end_row, start_col, start_row,
- end_col, add_shade);
- }
- }
- // Diagonal Lines.
- else if (abs(end_row - start_row) == abs(end_col - start_col)) {
- if (start_row < end_row && start_col < end_col) {
- additive_brush_pos_diagonal(canvas, start_row, start_col,
- end_row, end_col, add_shade);
- }
- else if (start_row > end_row && start_col > end_col) {
- additive_brush_pos_diagonal(canvas, end_row, end_col,
- start_row, start_col, add_shade);
- }
- else if (start_row > end_row && start_col < end_col) {
- additive_brush_neg_diagonal(canvas, start_row, start_col,
- end_row, end_col, add_shade);
- }
- else if (start_row < end_row && start_col > end_col) {
- additive_brush_neg_diagonal(canvas, end_row, end_col,
- start_row, start_col, add_shade);
- }
- }
- }
- }
- }
- // Normal Brush: Draws Horizontal line.
- void horizontal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- while (start_col <= end_col) {
- canvas[start_row][start_col] = shade;
- start_col++;
- }
- }
- // Normal Brush: Draws Vertical line.
- void vertical_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- while (start_row <= end_row) {
- canvas[start_row][start_col] = shade;
- start_row++;
- }
- }
- // Normal Brush: Draws Diagonal line with a negative gradient.
- void neg_diagonal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- int col_counter = start_col;
- int row_counter = start_row;
- while (col_counter <= end_col) {
- canvas[row_counter][col_counter] = shade;
- col_counter++;
- row_counter++;
- }
- }
- // Normal Brush: Draws Diagonal line with a positive gradient.
- void pos_diagonal_line(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- int col_counter = start_col;
- int row_counter = start_row;
- while (col_counter <= end_col) {
- canvas[row_counter][col_counter] = shade;
- col_counter++;
- row_counter--;
- }
- }
- // General Rectangle Function.
- void rectangle(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- if (valid_bounds(start_row, start_col, end_row, end_col)) {
- // Rectangle: Case 1.
- if (start_row <= end_row && start_col <= end_col) {
- draw_rectangle(canvas, start_row, start_col, end_row, end_col,
- shade);
- }
- // Rectangle: Case 2.
- else if (end_row <= start_row && start_col <= end_col) {
- draw_rectangle(canvas, end_row, start_col, start_row, end_col,
- shade);
- }
- // Rectangle: Case 3.
- else if (start_row <= end_row && end_col <= start_col) {
- draw_rectangle(canvas, start_row, end_col, end_row, start_col,
- shade);
- }
- // Rectangle: Case 4.
- else {
- draw_rectangle(canvas, end_row, end_col, start_row, start_col,
- shade);
- }
- }
- }
- // Rectangle Function: Draws the rectangle by looping through the rows/coloumns.
- void draw_rectangle(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int shade) {
- int row_counter = start_row;
- int col_counter = start_col;
- while (row_counter <= end_row) {
- col_counter = start_col;
- while (col_counter <= end_col) {
- canvas[row_counter][col_counter] = shade;
- col_counter++;
- }
- row_counter++;
- }
- }
- /* Copy and paste function. The desired area is copied (taking into account the
- relative positions of start and end) and then pasted. */
- void copy_and_paste(int canvas[N_ROWS][N_COLS], int start_row, int start_col,
- int end_row, int end_col, int target_row, int target_col) {
- int diff_row = abs(end_row - start_row);
- int diff_col = abs(end_col - start_col);
- // Checks that all points are valid and that target area lies on the canvas.
- if (valid_bounds(start_row, start_col, end_row, end_col)
- && (valid_bounds(target_row, target_col, (target_row + diff_row),
- (target_col + diff_col)))) {
- int copy_array[diff_row + 1][diff_col + 1];
- // Copy: Case 1.
- if ((start_row < end_row) && (start_col < end_col)) {
- copy(diff_row + 1, diff_col + 1, copy_array, canvas, start_row,
- start_col, end_row, end_col);
- }
- // Copy: Case 2.
- else if ((start_row > end_row) && (start_col < end_col)) {
- copy(diff_row + 1, diff_col + 1, copy_array, canvas, end_row,
- start_col, start_row, end_col);
- }
- // Copy: Case 3.
- else if ((start_row < end_row) && (start_col > end_col)) {
- copy(diff_row + 1, diff_col + 1, copy_array, canvas, start_row,
- end_col, end_row, start_col);
- }
- // Copy: Case 4.
- else {
- copy(diff_row + 1, diff_col + 1, copy_array, canvas, end_row,
- end_col, start_row, start_col);
- }
- // Pastes the stored copy_array into the target area on the canvas.
- paste(diff_row + 1, diff_col + 1, copy_array, canvas, target_row, target_col);
- }
- }
- /* Copy and Paste: Copy function. Stores the desired area in a 2D array called
- copy_array. */
- void copy(int row_size, int col_size, int copy_array[row_size][col_size],
- int canvas[N_ROWS][N_COLS], int start_row, int start_col, int end_row,
- int end_col) {
- int row_counter_array = 0;
- int col_counter_array = 0;
- int col_counter = start_col;
- int row_counter = start_row;
- while (row_counter <= end_row) {
- col_counter = start_col;
- col_counter_array = 0;
- while (col_counter <= end_col) {
- copy_array[row_counter_array][col_counter_array]
- = canvas[row_counter][col_counter];
- col_counter++;
- col_counter_array++;
- }
- row_counter++;
- row_counter_array++;
- }
- }
- /* Copy and Paste: Paste function. Pastes copy_array onto the target area of the
- canvas. */
- void paste(int row_size, int col_size,
- int copy_array[row_size][col_size], int canvas[N_ROWS][N_COLS],
- int target_row, int target_col) {
- int target_end_row = target_row + row_size - 1;
- int target_end_col = target_col + col_size - 1;
- int row_counter_array = 0;
- int col_counter_array = 0;
- int col_counter = target_col;
- while (target_row <= target_end_row) {
- col_counter_array = 0;
- col_counter = target_col;
- while (col_counter <= target_end_col) {
- canvas[target_row][col_counter]
- = copy_array[row_counter_array][col_counter_array];
- col_counter_array++;
- col_counter++;
- }
- row_counter_array++;
- target_row++;
- }
- }
- // Additive Brush: Inputs Additive Brush settings into a 3 x 3 array.
- void additive_input(
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION],
- int commands[ADDITIVE_BRUSH_INPUT_SIZE]) {
- int col_counter = 0;
- int row_counter = 0;
- while (row_counter <= 2) {
- col_counter = 0;
- while (col_counter <=2) {
- add_shade[row_counter][col_counter]
- = commands[(row_counter * 3) + col_counter];
- col_counter++;
- }
- row_counter++;
- }
- }
- /* Additive Brush: Stamp Function. The stamp function will be called to
- re-colour the 3 x 3 pixels around each referenced pixel in the Additive Draw
- Line functions based on the current settings in the add_shade array. */
- void additive_stamp(int canvas[N_ROWS][N_COLS],
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION],
- int row_counter, int col_counter) {
- // Loops through the columns around the referenced pixel from left to right.
- int horiz = -1;
- // Loops through the rows around the referenced pixel from top to bottom.
- int vert = -1;
- while (horiz <= 1) {
- vert = -1;
- while (vert <= 1) {
- canvas[row_counter + vert][col_counter + horiz]
- += add_shade[vert + 1][horiz + 1];
- canvas[row_counter + vert][col_counter + horiz] =
- valid_shade(canvas[row_counter + vert][col_counter + horiz]);
- vert++;
- }
- horiz++;
- }
- }
- // Additive Brush: Draws Horizontal Line.
- void additive_brush_horiz(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]) {
- if (valid_bounds(start_row -1, start_col - 1, end_row + 1 , end_col + 1)) {
- int col_counter = start_col;
- while (col_counter <= end_col) {
- additive_stamp(canvas, add_shade, start_row, col_counter);
- col_counter++;
- }
- }
- }
- // Additive Brush: Draws Vertical Line.
- void additive_brush_vert(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]) {
- if (valid_bounds(start_row - 1, start_col - 1, end_row + 1 , end_col + 1)) {
- int row_counter = start_row;
- while (row_counter <= end_row) {
- additive_stamp(canvas, add_shade, row_counter, start_col);
- row_counter++;
- }
- }
- }
- // Additive Brush: Draws Diagonal Line with a positive gradient.
- void additive_brush_pos_diagonal(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]) {
- if (valid_bounds(start_row - 1, start_col - 1, end_row + 1 , end_col + 1)) {
- int col_counter = start_col;
- int row_counter = start_row;
- while (col_counter <= end_col) {
- additive_stamp(canvas, add_shade, row_counter, col_counter);
- col_counter++;
- row_counter++;
- }
- }
- }
- // Additive Brush: Draws Diagonal Line with a negative gradient.
- void additive_brush_neg_diagonal(int canvas[N_ROWS][N_COLS], int start_row,
- int start_col, int end_row, int end_col,
- int add_shade[ADDITIVE_BRUSH_DIMENSION][ADDITIVE_BRUSH_DIMENSION]) {
- if (valid_bounds(start_row - 1, start_col + 1, end_row + 1 , end_col - 1)) {
- int col_counter = start_col;
- int row_counter = start_row;
- while (col_counter <= end_col) {
- additive_stamp(canvas, add_shade, row_counter, col_counter);
- col_counter++;
- row_counter--;
- }
- }
- }
- /* Checks if the a pixel's shade is still valid after the additive brush has
- been applied. If it is not, this function will set the pixel to either
- White or BLACK. */
- int valid_shade(int shade) {
- if (shade > WHITE) {
- shade = WHITE;
- }
- else if (shade < BLACK) {
- shade = BLACK;
- }
- return shade;
- }
- /* Prints the canvas, by printing the integer value stored in
- each element of the 2-dimensional canvas array. */
- void printCanvas(int canvas[N_ROWS][N_COLS]) {
- int row = 0;
- while (row < N_ROWS) {
- int col = 0;
- while (col < N_COLS) {
- printf("%d ", canvas[row][col]);
- col++;
- }
- row++;
- printf("\n");
- }
- }
- /* Sets the entire canvas to be blank, by setting each element in the
- 2-dimensional canvas array to be WHITE (which is #defined at the top
- of the file). */
- void setBlankCanvas(int canvas[N_ROWS][N_COLS]) {
- int row = 0;
- while (row < N_ROWS) {
- int col = 0;
- while (col < N_COLS) {
- canvas[row][col] = WHITE;
- col++;
- }
- row++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement