C语言圣诞树 动态颜色
#include <windows.h>
#include <winnt.h>
#include <stdio.h>
#include<stdlib.h>
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define LAKEBLUE 3
#define RED 4
#define PURPLE 5
#define YELLOW 6
#define WHITE 7
#define GREY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTRED 11
#define LIGHTPURPLE 12
#define LIGHTYELLOW 13
#define BRIGHTWHITE 14
void setcolor(int color)
{
HANDLE hConsoleWnd;
hConsoleWnd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleWnd,color);
}
int main(){
int i=1;
int n=5;
int x,y,s,j,k;
int max=0;
while(1){
for (int j = 1; j <= n; j++) {
int s = 1 << j, k = (1 << n) - s, x;
for (int y = s - j; y >= 0; y--, putchar('\n')) {
setcolor(i);
i++;
if(i>=14){
i=1;
}
for (x = 0; x < y + k; x++){
printf(" ");
}
for (x = 0; x + y < s; x++){
printf("%c ", '!' ^ y & x);
}
for (x = 1; x + y < s; x++){
printf("%c ", '!' ^ y & (s - y - x - 1));
max=s;
}
}
}
for(int j=0;j<5;j++){
i++;
for(int k=0;k<max-8;k++){
printf(" ");
}
printf("|||||||||||||||||||||||||||||||\n");
setcolor(i);
if(i>=14){
i=1;
}
}
Sleep(1000);
system("cls");
}
}