下面是用C语言写的关于变幻线屏保的程序,大家有时间可以试试...
#include<bios.h>
#include<conio.h>
#include<graphics.h>
#define TOP 0
#define LEFT 0
#define RIGHT 639
#define BUTTOM 479
#define MAXLINE 12
#define HEADCOLOR 10
#define BODYCOLOR 2
#define BGCOLOR 0
#define PATH "D:\\turboc2"
int movepoint(int *x, int *y, int *dx, int*dy);
main()
{
int driver=VGA, mode=VGAHI;
int i,j,k;
long tim,delaytim;
int point[2][4][4]={LEFT,TOP,2,6,
RIGHT,BUTTOM,5,-3,
LEFT,BUTTOM,-3,-7,
RIGHT,TOP,-3,4
};
/*int point[][][]={x,y,dx,dy}*/
initgraph(&driver,&mode,PATH);
/*copy point0 to point1*/
for(j=0;j<4;j++){
for(i=0;i<4;i++){
point[1][j][i]=point[0][j][i];
}
}
/*draw the polyline*/
setcolor(BODYCOLOR);
for(j=0;j<MAXLINE;j++){
for(i=0;i<4;i++){
movepoint(&point[0][i][0],&point[0][i][1],&point[0][i][2],&point[0][i][3]);
}
for(i=0;i<4;i++){
line(point[0][i][0],point[0][i][1],point[0][(i+1)%4][0],point[0][(i+1)%4][1]);
}
}
while(!kbhit()){
/*clear the last polyline*/
setcolor(BGCOLOR);
for(i=0;i<4;i++){
line(point[1][i][0],point[1][i][1],point[1][(i+1)%4][0],point[1][(i+1)%4][1]);
}
setcolor(BODYCOLOR);
for(i=0;i<4;i++){
line(point[0][i][0],point[0][i][1],point[0][(i+1)%4][0],point[0][(i+1)%4][1]);
}
/*move point*/
for(j=0;j<2;j++){
for(i=0;i<4;i++){
movepoint(&point[j][i][0],&point[j][i][1],&point[j][i][2],&point[j][i][3]);
}
}
/*draw the first polyline*/
setcolor(HEADCOLOR);
for(i=0;i<4;i++){
line(point[0][i][0],point[0][i][1],point[0][(i+1)%4][0],point[0][(i+1)%4][1]);
}
tim=biostime(0, 0); /*return the clock ticks since midnight (18.2/sec)*/
delaytim=tim+1;
while(tim<delaytim){
tim=biostime(0, 0);
}
}
getch();
}
int movepoint(int *x, int *y, int *dx, int *dy)
{
*x+=*dx;
*y+=*dy;
if(*x<LEFT || *x>RIGHT){
*dx=-*dx;
*x+=*dx;
}
if(*y<TOP || *y>BUTTOM){
*dy=-*dy;
*y+=*dy;
}
return 0;
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |