#include <stdio.h>
/* screen size - adapt to console size */
#define NUM_COLUMNS 80
#define NUM_ROWS 25
/* screen buffer */
char screen[NUM_COLUMNS][NUM_ROWS];
/* initialize buffer by setting all pixels to spaces */
void initialize_buffer() {
for (int i = 0; i < NUM_ROWS; i++)
for (int j = 0; j < NUM_COLUMNS; j++)
screen[j][i] = ' ';
}
/* update screen by copying buffer to console window */
void update_screen() {
for (int i = 0; i < NUM_ROWS; i++) {
for (int j = 0; j < NUM_COLUMNS; j++)
}
}
/* checks whether a given point (x,y) is within the screen */
unsigned in_screen(int x, int y) {
// TODO
return 0;
}
/* draw a single point at given position (x,y) and with given character */
void draw_pixel(int x, int y, char c) {
// TODO
}
/* clear a single pixel at position (x,y) */
void clear_pixel(int x, int y) {
// TODO
}
/* draw a horizontal line (x1,y)-(x2,y) with dashes (-) */
void draw_horizontal_line(int x1, int x2, int y) {
// TODO
}
/* draw a vertical line (x,y1)-(x,y2) with vertical bars (|) */
void draw_vertical_line(int x, int y1, int y2) {
// TODO
}
/* draw a horizontal arrow (x1,y)-(x2,y) */
void draw_horizontal_arrow(int x1, int x2, int y) {
draw_horizontal_line(x1, x2, y);
if (x1 < x2)
draw_pixel(x2, y, '>');
else
draw_pixel(x2, y, '<');
}
/* draw a vertical arrow (x,y1)-(x,y2) */
void draw_vertical_arrow(int x, int y1, int y2) {
draw_vertical_line(x, y1, y2);
if (y1 < y2)
draw_pixel(x, y2, 'v');
else
draw_pixel(x, y2, '^');
}
/* draw a rectangle (x1,y1)-(x2,y1)-(x2,y2)-(x1,y2) with plus, dashes and vertical bars */
void draw_rectangle(int x1, int y1, int x2, int y2) {
// TODO
}
void draw_filled_rectangle(int x1, int y1, int x2, int y2, char c) {
// TODO
}
/* draw a general line (x1,y1)-(x2,y2) with character c */
void draw_line(int x1, int y1, int x2, int y2, char c) {
// TODO
}
/* flood fill an area starting at given position with character c */
void flood_fill(int x, int y, char c) {
// TODO
}
/* main program: entry point */
int main(int argc, const char *argv[]) {
initialize_buffer();
draw_rectangle(25, 2, 68, 8);
draw_line(0, NUM_ROWS - 1, NUM_COLUMNS - 1, 0, '*');
flood_fill(2, 2, '.');
draw_pixel(30, 10, '1');
draw_pixel(20, 15, '2');
draw_pixel(75, 20, '3');
draw_line(8, 8, 45, 15, '+');
draw_horizontal_arrow(0, NUM_COLUMNS - 1, 0);
draw_horizontal_arrow(NUM_COLUMNS - 1, NUM_COLUMNS / 2, NUM_ROWS - 2);
draw_vertical_arrow(0, 1, NUM_ROWS - 1);
draw_filled_rectangle(3, 3, 8, 5, '#');
update_screen();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovKiBzY3JlZW4gc2l6ZSAtIGFkYXB0IHRvIGNvbnNvbGUgc2l6ZSAqLwojZGVmaW5lIE5VTV9DT0xVTU5TIDgwCiNkZWZpbmUgTlVNX1JPV1MgMjUKCi8qIHNjcmVlbiBidWZmZXIgKi8KY2hhciBzY3JlZW5bTlVNX0NPTFVNTlNdW05VTV9ST1dTXTsKCi8qIGluaXRpYWxpemUgYnVmZmVyIGJ5IHNldHRpbmcgYWxsIHBpeGVscyB0byBzcGFjZXMgKi8Kdm9pZCBpbml0aWFsaXplX2J1ZmZlcigpIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTlVNX1JPV1M7IGkrKykKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IE5VTV9DT0xVTU5TOyBqKyspCiAgICAgICAgICAgIHNjcmVlbltqXVtpXSA9ICcgJzsKfQoKCi8qIHVwZGF0ZSBzY3JlZW4gYnkgY29weWluZyBidWZmZXIgdG8gY29uc29sZSB3aW5kb3cgKi8Kdm9pZCB1cGRhdGVfc2NyZWVuKCkgewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOVU1fUk9XUzsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBOVU1fQ09MVU1OUzsgaisrKQogICAgICAgICAgICBwdXRjaGFyKHNjcmVlbltqXVtpXSk7CiAgICAgICAgcH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