关闭

地球 c语言实现

标签: 语言cimagerandomincludedelay
406人阅读 评论(0) 收藏 举报

 #include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <process.h>

#define TRUE 1
#define FALSE 0
#define IMAGE_SIZE 10

void draw_picture();
void move_picture();
void draw_image(int x, int y);
void putpixel_stars();

char title[]="WELLCOME TO THE";
char *move="COMPUTER WOELD!";
void *pt_addr;
int x,y,maxx,maxy,midx,midy;

int main()
{
   int driver = VGA;
   int mode=VGAHI;
   int errorcode;
   initgraph(&driver, &mode, "C://soft//TC");
   errorcode=graphresult();
   if(errorcode!=0){
     printf("Graphics error:%s/n",grapherrormsg(errorcode));
     printf("Press any key to halt:");
     getch();
     exit(1);
   }
   cleardevice();
   maxx=getmaxx();
   maxy=getmaxy()-20;
   midx=maxx/2;
   midy=maxy/2;
   x=0;
   y=midy-25;
   setbkcolor(GREEN);
   draw_picture();
   move_picture();
   free(pt_addr);
   settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
   settextjustify(LEFT_TEXT,TOP_TEXT);
   restorecrtmode();
}

void draw_picture(void)
{
  unsigned int i,size;
  setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  setcolor(LIGHTBLUE);
  for(i=0;i<=14;i++)
  {
    ellipse(midx,midy,0,360,108,108-8*i);
    ellipse(midx,midy,0,360,108-8*i,108);
  }
  setcolor(BLUE);
  setlinestyle(SOLID_LINE,0,THICK_WIDTH);
  ellipse(midx,midy,130,50,170,30);
  draw_image(x,y);
  size=imagesize(x,y-IMAGE_SIZE,x+(4*IMAGE_SIZE),y+IMAGE_SIZE);
  pt_addr=malloc(size);
  getimage(x,y-IMAGE_SIZE,x+(4*IMAGE_SIZE),y+IMAGE_SIZE,pt_addr);
  putpixel_stars();
  setcolor(DARKGRAY);
  setlinestyle(SOLID_LINE,0,THICK_WIDTH);
  rectangle(0,0,maxx,maxy);
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  bar(0,getmaxy()-18,getmaxx(),getmaxy());
  outtextxy(150,getmaxy()-12,"Program for Demo in CG Lesson ,HUST");
  setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  setcolor(BLUE);
  settextstyle(TRIPLEX_FONT,HORIZ_DIR,6);
  settextjustify(CENTER_TEXT,CENTER_TEXT);
  outtextxy(midx-70,70,title);
}

void move_picture(viod)
{
  char printmove[2];
  int movex;
  do{
    x=0;
    movex=midx-200;
    setcolor(6);
    while(x<=maxx)
    {
      if(kbhit())break;
      putimage(x,y-IMAGE_SIZE,pt_addr,XOR_PUT);
      x=x+5;
      if(*move!='/0'&& x>movex)
      {
        *(printmove)=*(move++);
        *(printmove+1)='/0';
        outtextxy(movex,y+IMAGE_SIZE+100,printmove);
    movex+=30;
      }
      putimage(x,y-IMAGE_SIZE,pt_addr,XOR_PUT);
      delay(150000);
    }
     putimage(0,y-IMAGE_SIZE,pt_addr,XOR_PUT);
  }while(!kbhit());
}

void draw_image(int x,int y)
{
  setcolor(GREEN);
  setfillstyle(1,4);
  moveto(x+10,y);
  linerel(-3*10,2*10);
  moveto(x+10,y);
  linerel(-3*10,-2*10);
  moveto(x+25,y);
  linerel(-5*10,0);
  fillellipse(x+13,y,8,8);
}

void putpixel_stars(void)
{
  int i,seed=1958;
  int dotx,doty,h,w,color,maxcolor;
  maxcolor=getmaxcolor();
  w=getmaxx();
  h=getmaxy()-20;
  srand(seed);
  for(i=0;i<5000;++i)
  {
    dotx=1+random(w-1);
    doty=1+random(h-1);
    color=random(maxcolor);
    putpixel(dotx,doty,color);
  }
  srand(seed);
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10901次
    • 积分:173
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:0篇
    • 译文:0篇
    • 评论:7条
    文章分类
    最新评论