X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Ftest_stroke.c;h=06ae2b69937e092830a223ce47ccde61aa2a2568;hp=9068c5784bab5db506e0f50b65a4e6a1c3605a8f;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hpb=7be8967177293d3a0b4b8a286f16b740933ac583 diff --git a/lib/gfxpoly/test_stroke.c b/lib/gfxpoly/test_stroke.c index 9068c57..06ae2b6 100644 --- a/lib/gfxpoly/test_stroke.c +++ b/lib/gfxpoly/test_stroke.c @@ -1,8 +1,10 @@ #include #include "../gfxtools.h" +#include "convert.h" #include "stroke.h" +#include "convert.h" -int main() +int test_stroke1() { gfxline_t l[512], f[256*5]; @@ -10,6 +12,7 @@ int main() gfxdevice_t dev; gfxdevice_swf_init(&dev); dev.setparameter(&dev, "framerate", "25.0"); + dev.setparameter(&dev, "disable_polygon_conversion", "1"); int t; for(t=0;t<300;t++) { dev.startpage(&dev, 700,700); @@ -74,25 +77,25 @@ int main() //gfxpoly_t*p = gfxpoly_fromstroke(l, width, gfx_capRound, gfx_joinRound, 500); gfxpoly_t*p1 = gfxpoly_from_stroke(l, width, gfx_capRound, gfx_joinRound, 500, 0.05); - assert(gfxpoly_check(p1)); + assert(gfxpoly_check(p1, 1)); //gfxpoly_t*p2 = gfxpoly_from_fill(f, 0.05); gfxline_t*l2 = gfxline_clone(l); - double c = cos(t*M_PI/75); - double s = sin(t*M_PI/75); + double c = cos(t*M_PI/50.0); + double s = sin(t*M_PI/50.0); static int x1 = 0, xdir = 1; static int y1 = 0, ydir = 5; - x1+=xdir; if(x1>=150) {x1=300-x1;xdir=-xdir;} if(x1<-150) {x1=-300-x1;xdir=-xdir;} - y1+=ydir; if(y1>=150) {y1=300-y1;ydir=-ydir;} if(y1<-150) {y1=-300-y1;ydir=-ydir;} - gfxmatrix_t m = { c, s, -(350+x1)*c-350*s+350, - -s, c, 350*s-(350+x1)*c+350}; + x1 = sin(t*M_PI/60.0)*50; + y1 = -sin(t*M_PI/50.0)*50; + gfxmatrix_t m = { c, s, -(350+x1)*c-(350+y1)*s+350, + s, -c, -(350+x1)*s+(350+y1)*c+350}; gfxline_transform(l2, &m); gfxpoly_t*p2 = gfxpoly_from_stroke(l2, width, gfx_capRound, gfx_joinRound, 500, 0.05); - assert(gfxpoly_check(p2)); + assert(gfxpoly_check(p2, 1)); gfxpoly_t*p3 = gfxpoly_intersect(p1, p2); - assert(gfxpoly_check(p3)); + assert(gfxpoly_check(p3, 1)); //gfxpoly_t*p4 = gfxpoly_from_fill(f, 0.05); //gfxpoly_t*p5 = gfxpoly_intersect(p1, p4); @@ -128,3 +131,71 @@ int main() result->save(result, "test.swf"); result->destroy(result); } + +int test_stroke2() +{ + gfxline_t l[4]; + l[0].type = gfx_moveTo; + l[0].x = 100;l[0].sx=2; + l[0].y = 100;l[0].sy=2; + l[0].next = &l[1]; + l[1].type = gfx_lineTo; + l[1].x = 100;l[1].sx=2; + l[1].y = 200;l[1].sy=-2; + l[1].next = &l[2]; + l[2].type = gfx_lineTo; + l[2].x = 250;l[2].sx=4; + l[2].y = 200;l[2].sy=0; + l[2].next = &l[3]; + l[3].type = gfx_lineTo; + l[3].x = 200;l[3].sx=0; + l[3].y = 150;l[3].sy=4; + l[3].next = 0; + + + gfxdevice_t dev; + gfxdevice_swf_init(&dev); + dev.setparameter(&dev, "framerate", "25.0"); + int t; + for(t=0;t<300;t++) { + dev.startpage(&dev, 700,700); + gfxline_t*g = l; + while(g) { + g->x += g->sx; + g->y += g->sy; + if(g->x<200) {g->x=400-g->x;g->sx=-g->sx;} + if(g->y<200) {g->y=400-g->y;g->sy=-g->sy;} + if(g->x>500) {g->x=1000-g->x;g->sx=-g->sx;} + if(g->y>500) {g->y=1000-g->y;g->sy=-g->sy;} + g = g->next; + } + //l[3].x = l[0].x; + //l[3].y = l[0].y; + + gfxdrawer_t d; + gfxdrawer_target_gfxline(&d); + double width = t/3.0; + if(width>50) width=100-width; + width = 40; + + draw_stroke(l, &d, width, gfx_capSquare, gfx_joinMiter, 500); + gfxline_t*line = (gfxline_t*)d.result(&d); + //gfxline_dump(line, stdout, ""); + + gfxcolor_t black = {255,0,0,0}; + gfxcolor_t cyan = {255,0,128,128}; + dev.stroke(&dev, l, 2, &black, gfx_capRound, gfx_joinRound, 0); + dev.stroke(&dev, line, 2, &cyan, gfx_capRound, gfx_joinRound, 0); + gfxline_free(line); + dev.endpage(&dev); + } + + gfxresult_t* result = dev.finish(&dev); + result->save(result, "test.swf"); + result->destroy(result); +} + +int main() +{ + test_stroke2(); +}