From 22f98d58ee8c4a583b6ea0d4ce39d1cee68da570 Mon Sep 17 00:00:00 2001 From: Dmitriy Gorshenin Date: Mon, 16 May 2022 00:54:15 +0300 Subject: [PATCH] Changing color --- Lab2/Lab2.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Lab2/Lab2.cpp diff --git a/Lab2/Lab2.cpp b/Lab2/Lab2.cpp new file mode 100644 index 0000000..180c3d4 --- /dev/null +++ b/Lab2/Lab2.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include + +const int REPEATS = 3; +const int PERIOD = 1300; + +const int LENGTH = 24; +char str[LENGTH]; + +const char CHAR_COLORS_AMOUNT = 16; +const char BACK_COLORS_AMOUNT = 8; + +const int x1 = 10; +const int y1 = 10; +const int x2 = 70; +const int y2 = 20; + +void outputGreetings() +{ + printf("Program will output your string with different colors.\n"); + printf("Enter string with length less than 24 characters.\n"); + printf("Excess characters will not be read.\n"); +} + +void readString() +{ + printf("Enter your string: "); + scanf("%24s", str); +} + +void goToNextLine() +{ + cprintf("\r\n"); +} + +void outputBackgroundColor(int code) +{ + switch(code) + { + case BLACK: + cprintf("black"); + break; + case BLUE: + cprintf("blue"); + break; + case GREEN: + cprintf("green"); + break; + case CYAN: + cprintf("cyan"); + break; + case RED: + cprintf("red"); + break; + case MAGENTA: + cprintf("magenta"); + break; + case BROWN: + cprintf("brown"); + break; + case LIGHTGRAY: + cprintf("lightgray"); + break; + } +} + +void outputCurrentColors(int backColor, int charColor) +{ + cprintf("Back color:"); + outputBackgroundColor(backColor); + cprintf(",char color:%d ", charColor); +} + +void scroll() +{ + union REGS r; + r.h.ah = 6; + r.h.al = REPEATS; + r.h.ch = y1-1; + r.h.cl = x1-1; + r.h.dh = y2-1; + r.h.dl = x2-1; + r.h.bh = 0x07; + int86(0x10, &r, &r); +} + +void main() +{ + clrscr(); + outputGreetings(); + readString(); + clrscr(); + window(x1,y1,x2,y2); + for(int i = 0; i < BACK_COLORS_AMOUNT; i++) + { + for(int j = 0; j < CHAR_COLORS_AMOUNT; j++) + { + textbackground(i); + textcolor(j); + outputCurrentColors(i,j); + cprintf(str); + clreol(); + delay(PERIOD); + scroll(); + goToNextLine(); + } + } + textbackground(BLACK); + textcolor(WHITE); + clreol(); + system("PAUSE"); +}