/** * DESC: Tests circle drawing using Bresenham algorithm. * * IMP: HIGH */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include int main( int argc, char *argv[] ) { debug_level = 0; /* 1 = warn, 2 = info, 3 = verbose, 4 = debug mode */ printf( "Bresenham drawing test.\n" ); printf( "Press any key to go next test step.\n" ); visual_init( 800, 600 ); circle_draw_aliased = circle_draw_bresenham; coord_t p = { 0, 0 }; surface_t *s = surface_new( 800, 600 ); assert_not_null( s ); circle_t *o = circle_new(); assert_not_null( o ); color_t c; COLOR_FROM_ARGB( c, COLOR_RED ); object_init2( o, c ); printf( "100px red circle at ( 100, 100 )\n" ); COLOR_FROM_ARGB( OBJECT_COLOR( o ), COLOR_RED ); SET_COORD( o->center, 100, 100 ); o->radius = 100; object_draw( o, s ); visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); printf( "200px magenta filled circle at ( 300, 300 )\n" ); COLOR_FROM_ARGB( OBJECT_COLOR( o ), COLOR_MAGENTA ); SET_COORD( o->center, 300, 300 ); o->radius = 200; object_draw( o, s ); visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); printf( "300px white filled circle at ( 400, 300 )\n" ); COLOR_FROM_ARGB( OBJECT_COLOR( o ), COLOR_WHITE ); OBJECT_SET_DRAW_OPT( o, DRAW_FILL ); SET_COORD( o->center, 400, 300 ); o->radius = 300; object_draw( o, s ); visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); printf( "Series of yellow circles at ( 400, 300 ), radius change 10px\n" ); COLOR_FROM_ARGB( OBJECT_COLOR( o ), COLOR_YELLOW ); OBJECT_UNSET_DRAW_OPT( o, DRAW_FILL ); SET_COORD( o->center, 400, 300 ); unsigned r; for ( r=0; r <= 300; r += 10 ) { o->radius = r; object_draw( o, s ); } visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); printf( "Circle outside the screen\n" ); SET_COORD( o->center, 10, 10 ); o->radius = 100; object_draw( o, s ); visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); printf( "Filled circle outside the screen\n" ); OBJECT_SET_DRAW_OPT( o, DRAW_FILL ); SET_COORD( o->center, 10, 10 ); o->radius = 100; object_draw( o, s ); visual_display( s, p ); visual_update(); visual_waitkey(); surface_clear( s ); surface_free( s ); object_free( o ); visual_quit(); return ask_user_yn( "Everything rendered as expect?" ) != 1; }