Я использую 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
Является ли контур Луны действительно закрытым? –