#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
const int _DELAY = 300;
void set_cursor_position(int row, int col)
{
COORD coord;
coord.X = col;
coord.Y = row;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void set_left_top(int *start_row, int *start_col, const int finish_row, const int finish_col)
{
while (true)
{
Sleep(_DELAY);
set_cursor_position(*start_row, *start_col);
printf("1");
*start_row = *start_row - 1;
*start_col = *start_col - 1;
if (*start_row < finish_row)
{
*start_row = *start_row + 1;
*start_col = *start_col + 2;
break;
}
if (*start_col < finish_col)
{
*start_col = *start_col + 1;
break;
}
}
}
void set_right_bottom(int *start_row, int *start_col, const int finish_row, const int finish_col)
{
while (true)
{
Sleep(_DELAY);
set_cursor_position(*start_row, *start_col);
printf("0");
*start_row = *start_row + 1;
*start_col = *start_col + 1;
if (*start_col > finish_col)
{
*start_row = *start_row - 2;
*start_col = *start_col - 1;
break;
}
if (*start_row > finish_row)
{
*start_row = *start_row - 1;
break;
}
}
}
int main()
{
printf("*** MATRIX RESOLUTION ***\n\n");
int rows;
printf("ROWS: ");
scanf("%d", &rows);
int padding_top = rows + 4;
int padding_left = 2;
int cols;
printf("COLS: ");
scanf("%d", &cols);
cols = cols + padding_left;
bool direction = true;
int start_row = padding_top;
int start_col = padding_left;
while (start_row != (padding_top - rows) + 1 || start_col != cols)
{
if (direction)
{
set_left_top(&start_row, &start_col, (padding_top - rows) + 1, padding_left);
}
else
{
set_right_bottom(&start_row, &start_col, padding_top, cols - 1);
}
direction = !direction;
}
padding_top = padding_top + 1;
set_cursor_position(padding_top, 0);
return 0;
}