void Init_Data()
{
int i
for( i=0i<POINTi++)
{
Snow[i].x=0
Snow[i].y=0
Snow[i].size=0
}
for( i=0i<MaxXi++)
Map[i]=MaxY
}
显示:
void MakeSnow()
{
int i
if( CurSnow>=POINT ) return
for( i=0Snow[i].sizei++ )
CurSnow++
Snow[i].x=random(MaxX)
Snow[i].y=random(DOWNSPEED)
Snow[i].size=random(MaxSize)+1
}
设定显示坐标
void ShowSnow( int x, int y, int size, int flag )
{
int color=0
if ( flag ) color=15
switch( size )
{
case 1:
putpixel( x, y, color )
break
case 2:
setcolor( color )
line( x-1, y-1, x+1, y+1 )
line( x-1, y+1, x+1, y-1 )
break
case 3:
setcolor( color )
line( x-1, y-1, x+1, y+1 )
line( x-1, y+1, x+1, y-1 )
/*
line( x-2, y-2, x+2, y+2 )
line( x-2, y+2, x+2, y-2 )*/
line( x-2, y, x+2, y )
line( x, y-2, x, y+2 )
break
}
}
雪花移动效果:
void Move( int n, int tox, int toy )
{
int x, y, size, i, j
float person
x=Snow[n].x
y=Snow[n].y
size=Snow[n].size
/* check end */
j=y
if( x<tox )
{
person=(DOWNSPEED *1.0) / ( tox-x )*1.0
for( i=xi<=toxi++ )
{
if( j>=Map[i] )
{
tox=i-size
break
}
j+=(int)( (i-x+1)*person )
}
}
else if( x>tox )
{
person=(DOWNSPEED *1.0) / ( x-tox )*1.0
for( i=xi>=toxi-- )
{
if( j>=Map[i] )
{
tox=i+size
break
}
j+=(int)( (x-i+1)*person )
}
}
if( y+DOWNSPEED>=Map[tox] )
{
switch( size )
{
case 1:
Map[x]--
break
case 2:
Map[x]-=2
if( x>0 &&Map[x-1]>Map[x] ) Map[x-1]=Map[x]
if( x<MaxX-1 &&Map[x+1]>Map[x] ) Map[x+1]=Map[x]
break
case 3:
Map[x]-=3
if( x>1 &&Map[x-2]>Map[x] ) Map[x-1]=Map[x]
if( x>0 &&Map[x-1]>Map[x] ) Map[x-1]=Map[x]
if( x<MaxX-2 &&Map[x+2]>Map[x] ) Map[x+1]=Map[x]
if( x<MaxX-1 &&Map[x+1]>Map[x] ) Map[x+1]=Map[x]
break
}
CurSnow--
y=Map[x]+size
Snow[n].x=x
Snow[n].y=y
Snow[n].size=0
}
else /* not end */
{
Snow[n].x=tox
Snow[n].y=toy
}
}
#include<stdio.h>
#include<time.h>
#include<windows.h>
typedef struct
{
int x,y
char ch
}STU
STU st[100]
//出现位置
void gotoxy(int x, int y)
{
HANDLE hout
COORD pos
pos.X = x
pos.Y = y
hout = GetStdHandle(STD_OUTPUT_HANDLE)
SetConsoleCursorPosition(hout, pos)
}
/*隐藏光标*/
void show_cursor(int hide)
{
CONSOLE_CURSOR_INFO cciCursor
HANDLE hout
hout = GetStdHandle(STD_OUTPUT_HANDLE)
if(GetConsoleCursorInfo(hout, &cciCursor))
{
cciCursor.bVisible = hide
SetConsoleCursorInfo(hout, &cciCursor)
}
}
/*设置颜色*/
void set_color(int color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color)
}
main()
{
int i,j
show_cursor(0)
srand(time(NULL))
//初始化结构体
for (i=0i<100i++)
{
st[i].x = rand()%80
st[i].y = rand()%20
st[i].ch = rand()%(49-47)+48
}
while (1)
{
for (i=0i<100i++)
{
gotoxy(st[i].x,st[i].y)
set_color(0x2)//最先出现的颜色;
putchar(st[i].ch)
gotoxy(st[i].x,st[i].y-5)
putchar(' ')
st[i].y++
st[i].ch = rand()%(49-47)+48
if (st[i].y-5>=18)
{
gotoxy(st[i].x,st[i].y-1)
putchar(' ')
gotoxy(st[i].x,st[i].y-2)
putchar(' ')
gotoxy(st[i].x,st[i].y-3)
putchar(' ')
gotoxy(st[i].x,st[i].y-4)
putchar(' ')
gotoxy(st[i].x,st[i].y-4)
putchar(' ')
}
if (st[i].y >23)
{
st[i].x = rand()%80
st[i].y = rand()%20
}
gotoxy(st[i].x,st[i].y)
set_color(0xA)//由前一个颜色渐变成的颜色
putchar(st[i].ch)
}
Sleep(120)
}
}
color(0) printf("黑色\n") color(1) printf("蓝色\n") color(2) printf("绿色\n") color(3) printf("湖蓝色\n") color(4) printf("红色\n") color(5) printf("紫色\n") color(6) printf("黄色\n") color(7) printf("白色\n") color(8) printf("灰色\n") color(9) printf("淡蓝色\n") color(10) printf("淡绿色\n") color(11) printf("淡浅绿色\n") color(12) printf("淡红色\n") color(13) printf("淡紫色\n") color(14) printf("淡黄色\n") color(15) printf("亮白色\n")几个基本的颜色;
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int main()
{
int temperature //温度
int weather //天气
char str_weather[5]
int wind //风
srand((unsigned)time(0))//初始化随机种子
temperature=rand()%63-20 //获取-20到42的随机数
while(1)
{
weather=rand()%3//获取天气情况:0为雨,1为雪,2为晴
if(temperature<0 && weather==0) //如果温度小于0度并且天气为雨,则重新获取
{
continue
}
switch(weather)
{
case 0:
strcpy(str_weather,"雨")
break
case 1:
strcpy(str_weather,"雪")
break
case 2:
strcpy(str_weather,"晴")
break
}
break //如果符合规则,则退出循环
}
wind=rand()%13//获取风级:0-12
printf("今天温度:%d 天气:%s 风级:%d级\n",temperature,str_weather,wind)
return 0
}