Lapis Lazuli | Level 10

## Fun with SAS ODS Graphics: 3 Cheers for the Red, White, and Blue (Polygons)

Happy '04JUL2020'd!

Sure, you could settle for unicode stars (U+2605) or SAS 'starfilled' markers for your 4th of July plots. But what's the fun in that when you can roll your own polygon stars with SAS ODS Graphics and a little math help (1 2 3)? Happy Independence Day!

Note: Updated to use RGB color codes for "Old Glory Red and Blue".

A Star......Is Born

``````* Fun with SAS ODS Graphics: 04Jul2020 - Three Cheers for the Red, White, and Blue (Polygons)
Inspired by discussions of stars/pentagrams at:
1. blackeyepeas.phys.lsu.edu/courses/ict/19c/3/Points.html
2. mathworld.wolfram.com/Pentagram.html
3. stackoverflow.com/questions/13695317/rotate-a-point-around-another-point;

proc fcmp outlib=work.funcs.points;                   * User-defined functions;
subroutine rotate_pt(aD,oX,oY,nX,nY);                 * Function rotates a point (oX, oY) by given # of degrees (aD);
outargs nX, nY;                                       * Returns coordinates of new point (nX, nY);
nX=cos(aR)*oX-sin(aR)*oY;                             * Compute new X position;
nY=sin(aR)*ox+cos(aR)*oY;                             * Compute new Y position;
endsub;
run;

options cmplib=(work.funcs);
data stars(keep=id nx ny);                            * Generate points for stars (vertices of outer and inner pentagons);
do id=4.5 to 1.5 by -1.5;                             * Nested polygons (red, white, and blue);
nx=0;                                               * Initialize x/y coordinates;
ny=id;
output;                                             * Point on larger outer pentagon;
ox=nx; oy=ny;
call rotate_pt(360/5/2,.382*ox,.382*oy,nX,nY);      * Rotate (36 degrees) and scale outer pentagon points to inner pentagon points;
output;                                             * Point on smaller inner pentagon;
do i=1 to 4;
call rotate_pt(360/5,ox,oy,nX,nY);                * Rotate outer pentagon points (72 degrees);
output;                                           * Point on larger outer pentagon;
ox=nx; oy=ny;
call rotate_pt(360/5/2,.382*ox,.382*oy,nX,nY);    * Rotate (36 degrees) and scale outer pentagon points to inner pentagon points;
output;                                           * Point on smaller inner pentagon;
end;
end;

proc sgplot data=stars noautolegend noborder aspect=1;* Draw nested red=white-blue stars (polygon plot);
styleattrs datacolors=(CXB22234 white CX3C3B6E);      * "Old Glory Red", White, "Old Glory Blue";
polygon x=nx y=ny id=id / group=id fill;              * Stars;
xaxis display=none; yaxis display=none;               * Hide axes;``` ```

3 REPLIES 3
Community Manager

## Re: Fun with SAS ODS Graphics: 3 Cheers for the Red, White, and Blue (Polygons)

Nice job @tc!  Add a few concentric circles and you'd have a Captain America shield.

Lapis Lazuli | Level 10

## Re: Fun with SAS ODS Graphics: 3 Cheers for the Red, White, and Blue (Polygons)

Captain America's Shield, ODS Graphics Edition

Right you are, @ChrisHemedinger! Very thoughtful of you to remember the Captain with his July 4th birthday approaching!

``````*==> Remix for SAS ODS Graphics Take on Captain America's Shield
Modeled after en.wikipedia.org/wiki/Captain_America%27s_shield;

proc sgplot data=stars(where=(id=1.5)) noautolegend noborder aspect=1;        * Select any star, scale circles appropriately;
ellipseparm semimajor=3.75 semiminor=3.75 /  fill fillattrs=(color=CXB22234); * "Old Glory Red" circle;
ellipseparm semimajor=3 semiminor=3 /  fill fillattrs=(color=white);          * White circle;
ellipseparm semimajor=2.25 semiminor=2.25 /  fill fillattrs=(color=CXB22234); * "Old Glory Red" circle;
ellipseparm semimajor=1.5 semiminor=1.5 /  fill fillattrs=(color=CX3C3B6E);   * "Old Glory Blue" circle;
polygon x=nx y=ny id=id / group=id fill fillattrs=(color=white);              * White star;
xaxis display=none; yaxis display=none;                                       * Hide axes;``` ```

Meteorite | Level 14

## Re: Fun with SAS ODS Graphics: 3 Cheers for the Red, White, and Blue (Polygons)

Nice.  And, if you use a GLOSS or SHEEN skin, you may also get the lighting effect on the shield.  🙂

Discussion stats
• 3 replies
• 885 views
• 8 likes
• 3 in conversation