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".
* 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);
aR=aD*constant("pi")/180; * Convert from degrees to radian;
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;
Nice job @tc! Add a few concentric circles and you'd have a Captain America shield.
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;
Nice. And, if you use a GLOSS or SHEEN skin, you may also get the lighting effect on the shield. 🙂
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.