主题:[讨论]求助,求高手
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
double Earthx,Earthy,Circlex,Circley; /*Earthx,Earthy)表示地球的当前圆心,(Circlex,Circley)表示运行物得当前圆心*/
void drawnrun(int x,int y,double i,int r,int runr,int color) /*画星球*/
{
setcolor(color);
setfillstyle(SOLID_FILL,color);
i=(i*1.74444)/100; /*3.14/180=1.74444e-2*/
Circlex=runr*cos(i)+x;
Circley=runr*sin(i)+y;
fillellipse(Circlex,Circley,r,r);
}
void eraserun(int x,int y,double i,int r,int runr) /*擦除星球*/
{
setfillstyle(SOLID_FILL,BLACK);
i=(i*1.74444)/100;
Circlex=runr*cos(i)+x;
Circley=runr*sin(i)+y;
setcolor(BLACK);
fillellipse(Circlex,Circley,r,r);
}
void putstar(void) /*在天空画星星*/
{
int i,dotx,doty,h,w,color;
w=640;
h=480;
for(i=0;i <150;i++)
{
dotx=random(w-1);
doty=random(h-1);
color=random(16);
putpixel(dotx,doty,color); /*小星星*/
circle(dotx+1,doty+1,1); /*大星星*/
}
}
main()
{
int gd=DETECT,gm;
int Circlex1,Circley1,r;
int i,j,k,ks;
initgraph(&gd,&gm, " ");
Circlex1=getmaxx()/2;
Circley1=getmaxy()/2;
cleardevice();
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(1,1, "Sun,Earth,Moon ");
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(Circlex1,Circley1,35,35); /*画太阳*/
setcolor(RED);
outtextxy(Circlex1-16,Circley1-10, "SUN "); putstar();
for(j=1;j <3;j++) /*地球一共转3圈*/
{
ks=0;
for(i=0;i <=360;i++)
{
delay(200);
drawnrun(Circlex1,Circley1,i,20,180,LIGHTBLUE); /*画地球*/
Earthx=Circlex;
Earthy=Circley;
for(k=1;k <12;k++)
{
ks+=1;
drawnrun(Earthx,Earthy,ks,5,50,WHITE); /*画月亮*/
if(kbhit()) break;
else delay(800);
eraserun(Earthx,Earthy,ks,5,50); /*擦月亮*/
}
eraserun(Circlex1,Circley1,i,15,180); /*擦地球*/
if(kbhit()) break;
}
}
getch();
closegraph();
}
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
double Earthx,Earthy,Circlex,Circley; /*Earthx,Earthy)表示地球的当前圆心,(Circlex,Circley)表示运行物得当前圆心*/
void drawnrun(int x,int y,double i,int r,int runr,int color) /*画星球*/
{
setcolor(color);
setfillstyle(SOLID_FILL,color);
i=(i*1.74444)/100; /*3.14/180=1.74444e-2*/
Circlex=runr*cos(i)+x;
Circley=runr*sin(i)+y;
fillellipse(Circlex,Circley,r,r);
}
void eraserun(int x,int y,double i,int r,int runr) /*擦除星球*/
{
setfillstyle(SOLID_FILL,BLACK);
i=(i*1.74444)/100;
Circlex=runr*cos(i)+x;
Circley=runr*sin(i)+y;
setcolor(BLACK);
fillellipse(Circlex,Circley,r,r);
}
void putstar(void) /*在天空画星星*/
{
int i,dotx,doty,h,w,color;
w=640;
h=480;
for(i=0;i <150;i++)
{
dotx=random(w-1);
doty=random(h-1);
color=random(16);
putpixel(dotx,doty,color); /*小星星*/
circle(dotx+1,doty+1,1); /*大星星*/
}
}
main()
{
int gd=DETECT,gm;
int Circlex1,Circley1,r;
int i,j,k,ks;
initgraph(&gd,&gm, " ");
Circlex1=getmaxx()/2;
Circley1=getmaxy()/2;
cleardevice();
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(1,1, "Sun,Earth,Moon ");
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(Circlex1,Circley1,35,35); /*画太阳*/
setcolor(RED);
outtextxy(Circlex1-16,Circley1-10, "SUN "); putstar();
for(j=1;j <3;j++) /*地球一共转3圈*/
{
ks=0;
for(i=0;i <=360;i++)
{
delay(200);
drawnrun(Circlex1,Circley1,i,20,180,LIGHTBLUE); /*画地球*/
Earthx=Circlex;
Earthy=Circley;
for(k=1;k <12;k++)
{
ks+=1;
drawnrun(Earthx,Earthy,ks,5,50,WHITE); /*画月亮*/
if(kbhit()) break;
else delay(800);
eraserun(Earthx,Earthy,ks,5,50); /*擦月亮*/
}
eraserun(Circlex1,Circley1,i,15,180); /*擦地球*/
if(kbhit()) break;
}
}
getch();
closegraph();
}