#include #include #include #define BRICKS_POINTS 18 static double bricks [] = { -100.0, 100.0, 100.0, 100.0, 100.0, 25.0, 0.0, 25.0, 0.0, 12.0, 0.0, -12.0, 0.0, -25.0, 100.0, -25.0, 100.0, -100.0, -100.0, -100.0, -100.0, -25.0, 0.0, -25.0, 0.0, -12.0, 0.0, 12.0, 0.0, 25.0, -100.0, 25.0, -100.0, 100.0, 0.0, 0.0, }; #define STAR_POINTS 47 static double star [] = { 0.0, 0.0, 0.0, 256.0, 53.0, 250.0, 0.0, 0.0, 104.0, 233.5, 150.0, 207.0, 0.0, 0.0, 190.0, 171.0, 221.5, 128.0, 0.0, 0.0, 243.0, 79.0, 254.5, 26.5, 0.0, 0.0, 254.5, -27.0, 243.0, -79.0, 0.0, 0.0, 221.5, -127.5, 190.0, -171.0, 0.0, 0.0, 150.0, -207.0, 104.0, -233.5, 0.0, 0.0, 53.0, -250.0, 0.0, -256.0, 0.0, 0.0, -53.5, -250.0, -104.0, -233.5, 0.0, 0.0, -150.0, -207.0, -190.0, -171.0, 0.0, 0.0, -221.5, -128.0, -243.0, -79.0, 0.0, 0.0, -254.5, -27.0, -254.5, 26.5, 0.0, 0.0, -243.0, 79.0, -221.5, 128.0, 0.0, 0.0, -190.0, 171.0, -150.0, 207.0, 0.0, 0.0, -104.0, 233.5, -53.5, 250.0, 0.0, 0.0, 0.0, 0.0, }; #define WIDTH 550 #define HEIGHT 550 int main (int argc, char *argv[]) { ArtVpath *vpath, *pert_vpath; ArtSVP *svp, *svp2; int num_points, use_perturb, render_bitmap; double *polygon; int i; unsigned char *pixmap; polygon = star; num_points = STAR_POINTS; use_perturb = 1; render_bitmap = 0; for (i=1 ; i < argc; i++) { if (!strcmp (argv[i], "--no-perturb") || !strcmp (argv[i], "+p")) use_perturb = 0; else if (!strcmp (argv[i], "--perturb") || !strcmp (argv[i], "-p")) use_perturb = 1; else if (!strcmp (argv[i], "--render") || !strcmp (argv[i], "-r")) render_bitmap = 1; else if (!strcmp (argv[i], "star")) { polygon = star; num_points = STAR_POINTS; } else if (!strcmp (argv[i], "bricks")) { polygon = bricks; num_points = BRICKS_POINTS; } else { fprintf (stderr, "Unknown option: %s\n", argv[i]); } } vpath = art_new (ArtVpath, num_points); for (i=0; i < num_points; i++) { vpath[i].code = (i == 0 ? ART_MOVETO : ART_LINETO); vpath[i].x = polygon[2*i]; vpath[i].y = polygon[2*i+1]; } vpath[num_points - 1].code = ART_END; if (use_perturb) { fprintf (stderr, "-------------------------\nvpath_perturb...\n"); pert_vpath = art_vpath_perturb (vpath); art_free (vpath); vpath = pert_vpath; #if 0 for (i=0; pert_vpath[i].code != ART_END; i++) fprintf (stderr, " %11.5f, %11.5f\n", pert_vpath[i].x, pert_vpath[i].y); #endif } fprintf (stderr, "-------------------------\nsvp_from_vpath...\n"); svp = art_svp_from_vpath (vpath); art_free (vpath); fprintf (stderr, "-------------------------\nsvp_uncross...\n"); svp2 = art_svp_uncross (svp); art_svp_free (svp); fprintf (stderr, "-------------------------\nsvp_rewind_uncrossed...\n"); svp = art_svp_rewind_uncrossed (svp2, ART_WIND_RULE_ODDEVEN); art_svp_free (svp2); if (render_bitmap) { pixmap = malloc (WIDTH*HEIGHT); fprintf (stderr, "-------------------------\ngray_svp_aa...\n"); art_gray_svp_aa (svp, - WIDTH/2 + 1, - HEIGHT / 2 + 1, WIDTH/2, HEIGHT/2, pixmap, WIDTH); printf ("P5 %d %d 255 ", WIDTH, HEIGHT); for (i=0; i < WIDTH*HEIGHT; i++) printf ("%c", pixmap[i]); } else { printf ("you may start this program with \"--render\" " "to write a PGM-image to stdout\n"); } art_svp_free (svp); return 0; }