/ rush01.c
rush01.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* rush01.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: lfiorell <lfiorell@student.42nice.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2024/07/20 09:03:00 by lfiorell #+# #+# */ 9 /* Updated: 2024/07/20 09:20:49 by lfiorell ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #define LEFT_CORNER '/' 14 #define RIGHT_CORNER '\\' 15 #define UP_WALL '*' 16 #define SIDE_WALL '*' 17 #define EMPTY ' ' 18 19 /* 20 * This function prints the character c to stdout. 21 */ 22 void ft_putchar(char c); 23 24 /* 25 * Prints to the standard output a line of the rush's output, 26 taking as arguments 27 * 28 * size : The width of the line to display 29 * y : The current line being printed, starting at 0 30 * j : The total number of line to display minus 1 31 */ 32 void display_line(int size, int y, int j); 33 34 /* 35 * Prints a line, taking as arguments 36 * 37 * c : The character used to fill the middle 38 * left : The character to print first, so it is placed to the left 39 * right : The character to print last, so it is placed to the right 40 * n : The width of the line to print 41 */ 42 void print_line(char c, char left, char right, int n); 43 44 /* 45 * Runs the rush's function, taking as arguments 46 * 47 * x : The width of the rectangle to print 48 * y : the height of the rectangle to print 49 */ 50 void rush(int x, int y) 51 { 52 int j; 53 54 j = 0; 55 while (j < y) 56 { 57 display_line(x, j, y - 1); 58 j++; 59 } 60 } 61 62 /* 63 * Prints to the standard output a line of the rush's output, 64 taking as arguments 65 * 66 * size : The width of the line to display 67 * y : The current line being printed, starting at 0 68 * j : The total number of line to display minus 1 69 * 70 * If this is the first line 71 * print the corners (`*_CORNER`) and the top (`UP_WALL`). 72 * 73 * If this is the last line 74 * print the corners (`*_CORNER`) reversed and the bottom (`UP_WALL`). 75 * 76 * If it isn't the first or last 77 * print the sides (`SIDE_WALL`), and fill the middle with `EMPTY` 78 */ 79 void display_line(int size, int y, int j) 80 { 81 if (0 == y) 82 { 83 print_line(UP_WALL, LEFT_CORNER, RIGHT_CORNER, size - 2); 84 } 85 else if (j == y) 86 { 87 print_line(UP_WALL, RIGHT_CORNER, LEFT_CORNER, size - 2); 88 } 89 else 90 { 91 print_line(EMPTY, SIDE_WALL, SIDE_WALL, size - 2); 92 } 93 } 94 95 /* 96 * Prints a line, taking as arguments 97 * 98 * c : The character used to fill the middle 99 * left : The character to print first, so it is placed to the left 100 * right : The character to print last, so it is placed to the right 101 * n : The width of the line to print 102 */ 103 void print_line(char c, char left, char right, int n) 104 { 105 int i; 106 107 i = 0; 108 ft_putchar(left); 109 while (i < n) 110 { 111 ft_putchar(c); 112 i++; 113 } 114 ft_putchar(right); 115 ft_putchar('\n'); 116 }