diff options
author | rodri <rgl@antares-labs.eu> | 2020-06-24 08:14:16 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2020-06-24 08:14:16 +0000 |
commit | 1c93e86c01eaad0143ee193cf11dec5dee82b6c9 (patch) | |
tree | ef04c9f79808e80ec2a2fdea53a7e60e12f89f5d | |
parent | 77043bdafc8d7cec0dac4b9375885be2f323f4f9 (diff) | |
download | etoys-1c93e86c01eaad0143ee193cf11dec5dee82b6c9.tar.gz etoys-1c93e86c01eaad0143ee193cf11dec5dee82b6c9.tar.bz2 etoys-1c93e86c01eaad0143ee193cf11dec5dee82b6c9.zip |
ptinpoly: fix colors and polygon countour.
-rw-r--r-- | ptinpoly.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -41,8 +41,9 @@ polygonpush(Polygon *poly, Point2 p) { poly->pts = realloc(poly->pts, ++poly->npts*sizeof(Point2)); poly->pts[poly->npts-1] = p; - poly->scrpts = realloc(poly->scrpts, poly->npts*sizeof(Point)); + poly->scrpts = realloc(poly->scrpts, (poly->npts+1)*sizeof(Point)); poly->scrpts[poly->npts-1] = toscreen(p); + poly->scrpts[poly->npts] = poly->scrpts[0]; /* close the polygon */ } Polygon* @@ -58,9 +59,10 @@ newpolygon(Point2 *pts, int npts) poly->npts = 0; }else{ poly->pts = pts; - poly->scrpts = malloc(npts*sizeof(Point)); + poly->scrpts = malloc((npts+1)*sizeof(Point)); for(i = 0; i < npts; i++) poly->scrpts[i] = toscreen(poly->pts[i]); + poly->scrpts[npts] = poly->scrpts[0]; /* close the polygon */ poly->npts = npts; } poly->push = polygonpush; @@ -97,7 +99,7 @@ initpalette(void) { pal[PCBg] = allocimage(display, UR, screen->chan, 1, DWhite); pal[PCFg] = allocimage(display, UR, screen->chan, 1, DBlack); - pal[PCPoly] = allocimage(display, UR, screen->chan, 1, DPaleblue); + pal[PCPoly] = allocimage(display, UR, screen->chan, 1, DPalebluegreen); pal[PCPolydark] = allocimage(display, UR, screen->chan, 1, DDarkblue); pal[PCAux] = allocimage(display, UR, screen->chan, 1, DRed); } @@ -122,8 +124,8 @@ redraw(void) lockdisplay(display); draw(screen, screen->r, pal[PCBg], nil, ZP); fillpoly(screen, thepoly->scrpts, thepoly->npts, 1, pal[PCPoly], ZP); - poly(screen, thepoly->scrpts, thepoly->npts, Enddisc, Enddisc, 1, pal[PCPolydark], ZP); - for(i = 0; i < thepoly->npts; i++) + poly(screen, thepoly->scrpts, thepoly->npts > 0? thepoly->npts+1: 0, Enddisc, Enddisc, 1, pal[PCPolydark], ZP); + for(i = 0; thepoly->npts > 0 && i < thepoly->npts+1; i++) fillellipse(screen, thepoly->scrpts[i], 2, 2, pal[PCPolydark], ZP); fillellipse(screen, toscreen(thepoint), 2, 2, pal[PCAux], ZP); drawbanner(); |