// @topic T01030 FLTK Graphics // @brief Animation with Fl::repeat_timeout() #include "txtbook/Simple_window.h" #include "txtbook/Graph.h" using namespace Graph_lib; const double TICK_TIMEOUT = 0.1; // 50 ms void callback( void* pthing ) { Graph_lib::Polygon* ppoly = static_cast< Graph_lib::Polygon* >( pthing ); std::cout << "TICK "; ppoly->move( 1, 1 ); // +1 pixel along x and y axis Fl::redraw(); Fl::repeat_timeout( TICK_TIMEOUT, callback, pthing ); } int main() { Point tl( 100, 100 ); Simple_window win( tl, 600, 600, "Canvas" ); Graph_lib::Polygon poly; poly.add( Point( 300, 200 ) ); poly.add( Point( 350, 100 ) ); poly.add( Point( 400, 200 ) ); poly.set_color( Color::blue ); poly.set_fill_color( Color::yellow ); win.attach( poly ); Fl::add_timeout( TICK_TIMEOUT, callback, &poly ); win.wait_for_button(); }