8字型时间式显示字母,附加控制台颜色设置

source code

  1 #include <windows.h>
  2 #include<iostream>
  3 #include"time.h"
  4 #include"conio.h"
  5 using namespace std;
  6 const int len=5,wid=7;//每个字为len*wid(长和高),wid须为奇数
  7 
  8 
  9 HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);// 控制台输出句柄
 10 CONSOLE_CURSOR_INFO cursorInfo = { TRUE, FALSE };
 11 
 12 
 13 void gotoxy(int x,int y)
 14 {
 15 COORD loc={x,y};
 16 SetConsoleCursorPosition(hOutput,loc);
 17 }
 18 /*
 19 第一个数字代表背景色,第二个数字代表前景色。各颜色的代码如下:
 20 0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白灰色 8=灰色 
 21 9=亮蓝色 A=亮绿色 B=亮蓝绿色 C=亮红色 D=亮紫红色 E=亮黄色 F=亮白色
 22 */
 23 
 24 void ShowPoint(int);//长度占2个空格长
 25 void ShowSpace(int);
 26 
 27 void Show(char[],int,int);
 28 
 29 void RandColor(int);
 30 void Display(char,int,int);
 31 
 32  
 33 
 34 
 35 int main()
 36 {
 37 system("color F0");
 38 SetConsoleTitleA("chenjing");//窗口取名
 39 SetConsoleCursorInfo(hOutput, &cursorInfo); // 设置光标隐藏
 40 
 41 char ch[]="thank you and i love you but you do not love me";
 42 for(int i=0;i<strlen(ch);i++)
 43 {
 44 Display(ch[i],8*(i%10),6*(i/10));
 45 }
 46 system("pause");
 47 
 48 /*
 49 SYSTEMTIME sys; 
 50 
 51 int h,m,s;
 52 int h1,h2,m1,m2,s1,s2;
 53 
 54 GetLocalTime( &sys );
 55 h=sys.wHour;
 56 m=sys.wMinute;
 57 s=sys.wSecond;
 58 h1=h/10,h2=h%10,m1=m/10,m2=m%10,s1=s/10,s2=s%10;
 59 
 60 Show(h1,0,0);Show(h2,2*len+1,0);
 61 gotoxy(4*len+2,(wid-1)/2);
 62 ShowPoint(1);
 63 gotoxy(4*len+2,wid-1);
 64 ShowPoint(1);
 65 Show(m1,4*len+5,0);Show(m2,6*len+6,0);
 66 //Show(s1,35,0);Show(s2,52,0);
 67 */
 68 
 69  
 70 
 71 
 72 CloseHandle(hOutput);
 73 return 0;
 74 }
 75 
 76 
 77 void ShowPoint(int n)//长度占2个空格长
 78 {
 79 for(int i=0;i<n;i++) 
 80 {
 81 //RandColor(rand()%9);
 82 cout<<"";
 83 }
 84 }
 85 void ShowSpace(int n)
 86 {
 87 for(int i=0;i<n;i++) 
 88 cout<<" ";
 89 }
 90 
 91 void Show(char array[],int x,int y)
 92 {
 93 int i,j;
 94 for(i=0;i<5;i++) 
 95 {
 96 for(j=0;j<3;j++)
 97 {
 98 gotoxy(x+2*j,y);
 99 if(array[3*i+j]-'0') ShowPoint(1);
100 else ShowSpace(1);
101 }
102 y++;
103 }
104 }
105 
106 /*
107 第一个数字代表背景色,第二个数字代表前景色。各颜色的代码如下:
108 0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白灰色 8=灰色 
109 9=亮蓝色 A=亮绿色 B=亮蓝绿色 C=亮红色 D=亮紫红色 E=亮黄色 F=亮白色
110 */
111 void RandColor(int n)
112 {
113 switch(n)
114 {
115 default:break;
116 case 0:SetConsoleTextAttribute(hOutput, 0xF9);break;
117 case 1:SetConsoleTextAttribute(hOutput, 0xFA);break;
118 case 2:SetConsoleTextAttribute(hOutput, 0xFB);break;
119 case 3:SetConsoleTextAttribute(hOutput, 0xFC);break;
120 case 4:SetConsoleTextAttribute(hOutput, 0xFD);break;
121 case 5:SetConsoleTextAttribute(hOutput, 0xFE);break;
122 case 6:SetConsoleTextAttribute(hOutput, 0xF0);break;
123 case 7:SetConsoleTextAttribute(hOutput, 0xF3);break;
124 case 8:SetConsoleTextAttribute(hOutput, 0xF8);break;
125 }
126 }
127 
128 void Display(char ch,int x,int y)
129 {
130 switch(ch)
131 {
132 default:break;
133 case 'a':case 'A':Show("111001111101111",x,y);break;
134 case 'b':case 'B':Show("100100111101111",x,y);break;
135 case 'c':case 'C':Show("000000111100111",x,y);break;
136 case 'd':case 'D':Show("001001111101111",x,y);break;
137 case 'e':case 'E':Show("111101111100111",x,y);break;
138 case 'f':case 'F':Show("111100110100100",x,y);break;
139 case 'g':case 'G':Show("111101111001111",x,y);break;
140 case 'h':case 'H':Show("101101111101101",x,y);break;
141 case 'i':case 'I':Show("100000100100100",x,y);break;
142 case 'j':case 'J':Show("001000001001011",x,y);break;
143 case 'k':case 'K':Show("100100111100100",x,y);break;
144 case 'l':case 'L':Show("100100100100110",x,y);break;
145 case 'm':case 'M':Show("111001111001111",x,y);break;
146 case 'n':case 'N':Show("000000111101101",x,y);break;
147 case 'o':case 'O':Show("000000111101111",x,y);break;
148 case 'p':case 'P':Show("111101111100100",x,y);break;
149 case 'q':case 'Q':Show("111101111001001",x,y);break;
150 case 'r':case 'R':Show("101101111100100",x,y);break;
151 case 's':case 'S':Show("111100111001111",x,y);break;
152 case 't':case 'T':Show("100100111100111",x,y);break;
153 case 'u':case 'U':Show("000000101101111",x,y);break;
154 case 'v':case 'V':Show("000101101101111",x,y);break;
155 case 'w':case 'W':Show("001001111001001",x,y);break;
156 case 'x':case 'X':Show("111100111001001",x,y);break;
157 case 'y':case 'Y':Show("101101111001111",x,y);break;
158 case 'z':case 'Z':Show("111001111100111",x,y);break;
159 case ' ':Show("000000000000000",x,y);break;
160 }
161 }

 

posted @ 2015-03-13 22:00  踏上客人  阅读(702)  评论(0)    收藏  举报