From ec0a1adadf3c64957c8f7d529c6bdbf3fa037dd8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 22 Jan 2010 00:39:54 +0000 Subject: quick workround for polygon plotter issues improve polygon star plotter to have animation! svn path=/trunk/libnsfb/; revision=9862 --- test/polystar.c | 64 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/polystar.c b/test/polystar.c index 9897458..25b1f42 100644 --- a/test/polystar.c +++ b/test/polystar.c @@ -1,5 +1,7 @@ /* libnsfb ploygon plotter test program */ +#define _POSIX_C_SOURCE 199506L + #include #include #include @@ -9,8 +11,16 @@ #include "libnsfb_plot.h" #include "libnsfb_event.h" -#define UNUSED(x) ((x) = (x)) +#include +// Sleep milliseconds +static void sleepMilli(long ms) +{ + const struct timespec ts = {ms / 1000, ms % 1000 * 1000000}; + nanosleep(&ts, NULL); +} + +#define UNUSED(x) ((x) = (x)) int main(int argc, char **argv) { @@ -26,6 +36,8 @@ int main(int argc, char **argv) int loop; nsfb_plot_pen_t pen; + double rotate; + UNUSED(argc); UNUSED(argv); @@ -46,41 +58,45 @@ int main(int argc, char **argv) nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); - /* claim the whole screen for update */ - nsfb_claim(nsfb, &box); pen.stroke_colour = 0xff000000; pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID; - nsfb_plot_clg(nsfb, 0xffffffff); + for (rotate =0; rotate < (2 * M_PI); rotate += (M_PI / 8)) { + /* claim the whole screen for update */ + nsfb_claim(nsfb, &box); - radius = (box.y1 / 2); + nsfb_plot_clg(nsfb, 0xffffffff); - for (sides = 14; sides >=6; sides-=2) { - points = malloc(sizeof(nsfb_point_t) * sides); + radius = (box.y1 / 2); - for (loop = 0; loop < sides;loop+=2) { - points[loop].x = (box.x1 / 2) + - (radius * cos(loop * 2 * M_PI / sides)); - points[loop].y = (box.y1 / 2) + - (radius * sin(loop * 2 * M_PI / sides)); + for (sides = 10; sides >=9; sides-=2) { + points = malloc(sizeof(nsfb_point_t) * sides); - points[loop+1].x = (box.x1 / 2) + - ((radius / 3) * cos((loop+1) * 2 * M_PI / sides)); - points[loop+1].y = (box.y1 / 2) + - ((radius / 3) * sin((loop+1) * 2 * M_PI / sides)); - } + for (loop = 0; loop < sides;loop+=2) { + points[loop].x = (box.x1 / 2) + + (radius * cos((loop * 2 * M_PI / sides) + rotate)); + points[loop].y = (box.y1 / 2) + + (radius * sin((loop * 2 * M_PI / sides) + rotate)); - nsfb_plot_polygon(nsfb, (const int *)points, sides, - 0xff000000 | (0xffffff / (sides * 2))); + points[loop+1].x = (box.x1 / 2) + + ((radius / 3) * cos(((loop+1) * 2 * M_PI / sides) + rotate)); + points[loop+1].y = (box.y1 / 2) + + ((radius / 3) * sin(((loop+1) * 2 * M_PI / sides) + rotate)); + } - nsfb_plot_polylines(nsfb, sides, points, &pen); + nsfb_plot_polygon(nsfb, (const int *)points, sides, + 0xff000000 | (0xffffff / (sides * 2))); - free(points); - radius -= 40; - } + nsfb_plot_polylines(nsfb, sides, points, &pen); - nsfb_update(nsfb, &box); + free(points); + radius -= 40; + } + + nsfb_update(nsfb, &box); + sleepMilli(100); + } while (event.type != NSFB_EVENT_CONTROL) nsfb_event(nsfb, &event, -1); -- cgit v1.2.3