From d23f114bc31706d47f1a0470e38724cee65e8a17 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 10 Nov 2003 14:13:56 +0000 Subject: [PATCH] * test/demo.c: Nicer complete demo. --- test/demo.c | 203 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 148 insertions(+), 55 deletions(-) diff --git a/test/demo.c b/test/demo.c index 768a393..af33811 100644 --- a/test/demo.c +++ b/test/demo.c @@ -29,6 +29,8 @@ static void display_menu(void); +static void demo_all(void); + static void demo_dots(void); static void demo_lines(void); static void demo_thin_lines(void); @@ -37,7 +39,7 @@ static void demo_triangles(void); static void demo_outlined_triangles(void); static void demo_sprites(void); -int clipping = 0; +int force_clipping = 0; struct ee_sprite *sprite = NULL; int main(int argc, char **argv) @@ -73,6 +75,10 @@ int main(int argc, char **argv) demo = NULL; quit = 1; break; + case '0': + ee_clear(); + demo = demo_all; + break; case '1': ee_clear(); demo = demo_dots; @@ -133,18 +139,20 @@ static void display_menu(void) ee_putstr("============"); ee_goto(4, 6); - ee_putstr("1: dots demo"); + ee_putstr("0: complete demo"); ee_goto(4, 7); - ee_putstr("2: lines demo"); + ee_putstr("1: dots demo"); ee_goto(4, 8); - ee_putstr("3: thin lines demo"); + ee_putstr("2: lines demo"); ee_goto(4, 9); - ee_putstr("4: circles demo"); + ee_putstr("3: thin lines demo"); ee_goto(4, 10); - ee_putstr("5: triangles demo"); + ee_putstr("4: circles demo"); ee_goto(4, 11); - ee_putstr("6: outlined triangles demo"); + ee_putstr("5: triangles demo"); ee_goto(4, 12); + ee_putstr("6: outlined triangles demo"); + ee_goto(4, 13); ee_putstr("7: sprites demo"); ee_goto(4, yo - 2); @@ -153,6 +161,118 @@ static void display_menu(void) ee_refresh(); } +static void demo_all(void) +{ + static int i = 0; + + int j, xo, yo, x1, y1, x2, y2, x3, y3; + + i++; + + ee_clear(); + + /* Draw the sun */ + ee_color(EE_YELLOW); + xo = ee_get_width() / 4; + yo = ee_get_height() / 4 + 5 * sin(0.03*i); + + for(j = 0; j < 16; j++) + { + x1 = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8); + y1 = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8); + ee_draw_thin_line(xo, yo, x1, y1); + } + + ee_color(EE_WHITE); + for(j = 15 + sin(0.03*i) * 8; j--;) + { + ee_draw_circle(xo, yo, j, '#'); + } + + ee_color(EE_YELLOW); + ee_draw_circle(xo, yo, 15 + sin(0.03*i) * 8, '#'); + + /* Draw the pyramid */ + xo = ee_get_width() * 5 / 8; + yo = 2; + + x1 = ee_get_width() / 8 + sin(0.03*i) * 5; + y1 = ee_get_height() / 2 + cos(0.03*i) * 5; + + x2 = ee_get_width() - 10 - cos(0.02*i) * 10; + y2 = ee_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5; + + x3 = ee_get_width() / 4 - sin(0.02*i) * 5; + y3 = ee_get_height() * 3 / 4 + cos(0.02*i) * 5; + + ee_color(EE_GREEN); + ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%'); + ee_color(EE_YELLOW); + ee_draw_thin_line(xo, yo, x2, y2); + ee_draw_thin_line(x2, y2, x1, y1); + ee_draw_thin_line(x1, y1, xo, yo); + + ee_color(EE_RED); + ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#'); + ee_color(EE_YELLOW); + ee_draw_thin_line(x1, y1, x2, y2); + ee_draw_thin_line(x2, y2, x3, y3); + ee_draw_thin_line(x3, y3, x1, y1); + + ee_color(EE_BLUE); + ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%'); + ee_color(EE_YELLOW); + ee_draw_thin_line(xo, yo, x2, y2); + ee_draw_thin_line(x2, y2, x3, y3); + ee_draw_thin_line(x3, y3, xo, yo); + + /* Draw a background triangle */ + x1 = 2; + y1 = 2; + + x2 = ee_get_width() - 3; + y2 = ee_get_height() / 2; + + x3 = ee_get_width() / 3; + y3 = ee_get_height() - 3; + + ee_color(EE_BLUE); +// ee_fill_triangle(x1, y1, x2, y2, x3, y3, '.'); + ee_color(EE_CYAN); + ee_draw_thin_line(x1, y1, x3, y3); + ee_draw_thin_line(x2, y2, x1, y1); + ee_draw_thin_line(x3, y3, x2, y2); + + xo = ee_get_width() / 2 + cos(0.027*i) * ee_get_width() / 3; + yo = ee_get_height() / 2 - sin(0.027*i) * ee_get_height() / 2; + + ee_draw_thin_line(x1, y1, xo, yo); + ee_draw_thin_line(x2, y2, xo, yo); + ee_draw_thin_line(x3, y3, xo, yo); + + /* Draw a sprite behind the pyramid */ + ee_draw_sprite(xo, yo, sprite); + + /* Draw a trail behind the foreground sprite */ + for(j = i - 60; j < i; j++) + { + int delta = ee_rand(-5, 5); + ee_color(ee_rand(1, 10)); + ee_goto(ee_get_width() / 2 + + cos(0.02*j) * (delta + ee_get_width() / 4), + ee_get_height() / 2 + + sin(0.02*j) * (delta + ee_get_height() / 3)); + ee_putchar('#'); + } + + /* Draw foreground sprite */ + ee_draw_sprite(ee_get_width() / 2 + cos(0.02*i) * ee_get_width() / 4, + ee_get_height() / 2 + sin(0.02*i) * ee_get_height() / 3, + sprite); + + ee_refresh(); +} + static void demo_dots(void) { int xmax = ee_get_width() - 1; @@ -176,7 +296,7 @@ static void demo_lines(void) /* Draw lines */ ee_color(ee_rand(1, 10)); - if(clipping) + if(force_clipping) { ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#'); @@ -196,7 +316,7 @@ static void demo_thin_lines(void) /* Draw lines */ ee_color(ee_rand(1, 10)); - if(clipping) + if(force_clipping) { ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), ee_rand(- w, 2 * w), ee_rand(- h, 2 * h)); @@ -215,7 +335,7 @@ static void demo_circles(void) int h = ee_get_height(); /* Draw circles */ - if(clipping) + if(force_clipping) { ee_color(ee_rand(1, 10)); ee_draw_circle(ee_rand(- w, 2 * w), @@ -249,7 +369,7 @@ static void demo_triangles(void) /* Draw lines */ ee_color(ee_rand(1, 10)); - if(clipping) + if(force_clipping) { ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), @@ -268,18 +388,21 @@ static void demo_outlined_triangles(void) { int w = ee_get_width(); int h = ee_get_height(); + int x1, y1, x2, y2, x3, y3; /* Draw lines */ ee_color(ee_rand(1, 10)); - if(clipping) + if(force_clipping) { - ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), - ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), - ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#'); + x1 = ee_rand(- w, 2 * w); + y1 = ee_rand(- h, 2 * h); + x2 = ee_rand(- w, 2 * w); + y2 = ee_rand(- h, 2 * h); + x3 = ee_rand(- w, 2 * w); + y3 = ee_rand(- h, 2 * h); } else { - int x1, y1, x2, y2, x3, y3; x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1); @@ -287,52 +410,22 @@ static void demo_outlined_triangles(void) y2 = ee_rand(0, h - 1); x3 = ee_rand(0, w - 1); y3 = ee_rand(0, h - 1); + } + + ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#'); - ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#'); + ee_color(ee_rand(1, 10)); + ee_draw_thin_line(x1, y1, x2, y2); + ee_draw_thin_line(x2, y2, x3, y3); + ee_draw_thin_line(x3, y3, x1, y1); - ee_color(ee_rand(1, 10)); - ee_draw_thin_line(x1, y1, x2, y2); - ee_draw_thin_line(x2, y2, x3, y3); - ee_draw_thin_line(x3, y3, x1, y1); - } ee_refresh(); } static void demo_sprites(void) { - static int i = 0; - - int x1, y1, x2, y2, x3, y3; - - i++; - - x1 = 2; - y1 = 2; - - x2 = ee_get_width() - 3; - y2 = ee_get_height() / 2; - - x3 = ee_get_width() / 3; - y3 = ee_get_height() - 3; - - ee_clear(); - - /* Draw a sprite behind the triangle */ - ee_draw_sprite(ee_get_width() / 2 + cos(0.027*i) * 30, - ee_get_height() / 2 - sin(0.027*i) * 20, sprite); - - /* Draw a background triangle */ - ee_color(EE_BLUE); - ee_fill_triangle(x1, y1, x2, y2, x3, y3, '.'); - ee_color(EE_CYAN); - ee_draw_thin_line(x1, y1, x3, y3); - ee_draw_thin_line(x2, y2, x1, y1); - ee_draw_thin_line(x3, y3, x2, y2); - - /* Draw foreground sprite */ - ee_draw_sprite(ee_get_width() / 2 + cos(0.02*i) * 20, - ee_get_height() / 2 + sin(0.02*i) * 10, sprite); - + ee_draw_sprite(ee_rand(0, ee_get_width() - 1), + ee_rand(0, ee_get_height() - 1), sprite); ee_refresh(); }