Notice
Recent Posts
Recent Comments
Creative Code
콘솔-(3) 본문
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;
// 16가지 ANSI 컬러를 열거형으로 정의
enum color16 {
Black = 0,
Blue,
Green,
Cyan,
Red,
Magenta,
Brown,
Lightgray,
Darkgray,
Lightblue,
Lightgreen,
Lightcyan,
Lightred,
Lightmagenta,
Yellow,
White
};
// 콘솔 창 내의 커서 위치를 x, y 좌표로 이동하는 함수 정의
void gotoxy(int x, int y) {
COORD pos = { x, y }; // COORD 구조체를 사용하여 커서 위치를 설정합니다.
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); // 커서 위치를 변경합니다.
}
// 텍스트 색상과 배경 색상을 설정하는 함수 정의
void setcolor(int txtcolor, int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), txtcolor + color * 16); // 텍스트 색상과 배경 색상을 설정합니다.
}
int main() {
srand(time(NULL)); // 난수 생성기 초기화
setcolor(Lightblue, White); // 초기 텍스트 색상과 배경 색상 설정
for (int i = 0; i < 16; i++) { // 16번 반복
setcolor(rand() % 16, rand() % 16); // 랜덤한 텍스트 색상과 배경 색상 설정
cout << "******" << endl; // '*' 문자를 출력합니다.
}
}