我使用graphics.h爲一個小程序,爲教育目的而寫。它有一個環繞地球的月球。問題是,經過幾次迭代,整個屏幕變爲空白(白色)。我嘗試了很多方法,但無法找到問題所在。請查看下面的代碼並查看是否可以找出問題所在?C++圖形使用graphics.h
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
int main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
int Earth_x,Earth_y;
Earth_x=10+390/2;
Earth_y=60+340/2;
int Moon_x,Moon_y;
Moon_x=Earth_x+100; //Moon initial coordinates
Moon_y=Earth_y;
float t = 0;
int new_page, old_page; // declare integer variables representing two graphics pages
while(1)
{
old_page = getvisualpage(); // set old_page to the number of the visual page
new_page = abs(old_page-0); // set new_page to the visual page number-1
setactivepage(new_page); // set the active page to the value of the new page
cleardevice(); // erase the active page
//rectangle(x1,y1,x2,y2);
rectangle(10,60,400,400);
//code for drawing and filing Earth.
setcolor(GREEN);
setfillstyle(1,GREEN);
circle(Earth_x,Earth_y,30);
floodfill(Earth_x,Earth_y,GREEN);
setcolor(WHITE);
outtextxy(Earth_x, Earth_y, "Earth");
//code for drawing and filling Moon.
setfillstyle(1,WHITE);
circle(Moon_x,Moon_y,10);
floodfill(Moon_x,Moon_y,WHITE);
//****We can add delay to slow down the moon***
//delay(1);
setvisualpage(new_page); // move the activepage to the visual page
//Code for modification of Moon coordinates
Moon_x=Earth_x+100*cos(t*3.1415/180.0);
Moon_y=Earth_y+100*sin(t*3.1415/180.0);
t=t+1;
}
getch();
closegraph();
}
謝謝你的幫忙!
這是Turbo-C++嗎? – Borgleader
不是。使用的編譯器是GCC mingw。 – KhuramAli
月球輪廓是否真的閉合? –