BookmarkSubscribeRSS Feed
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Happy '04JUL2020'd!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...A Star......Is Born...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); 
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; 

 

3 REPLIES 3
ChrisHemedinger
Community Manager

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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Captain America's Shield, ODS Graphics EditionCaptain 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; 

 

Jay54
Meteorite | Level 14

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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