最终效果:
//绘制一个圆,然后沿圆周移动一个标记(每按一次“Next”按钮,标记移动一段距离)。
#include"../实践/GUI/Simple_window.h"
#include"GUI/Graph.h"
int main()
try
{
using namespace Graph_lib;
//建立窗口。
Point tl(100, 100);
Simple_window win(tl, 600, 400, "My Window");
//-------------------------------------------------------------------------------
//建立圆。
Point oo(300, 200);
Circle cc(oo, 150);
cc.set_color(0);
win.attach(cc);
//-------------------------------------------------------------------------------
//建立并移动标志点。
int j = 0;
while (1)
{
Circle pp(Point(oo.x+cc.radius()*cos(j * 3.1415926 / 180.0), oo.y-cc.radius()*sin(j * 3.1415926 / 180.0)),5);//C++中三角函数的参数为弧度。
pp.set_fill_color(Color::red);
win.attach(pp);
win.wait_for_button();//将控制权交给显示引擎,使GUI系统在屏幕上显示一个对象,并等待用户按下窗口中的“Next”,
//以便执行下面的程序。
j += 10;
}
//-------------------------------------------------------------------------------
}
catch (exception& e) {
cerr << "error: " << e.what() << '\n';
return 1;
}
catch (...) {
cerr << "Oops: unknown exception!\n";
return 2;
};
//-----------------------------------------------------------------------------------