## Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

Frequent Contributor
Posts: 84

# Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

Truth be told, the underlying concept here isn't all that different than Rick Wicklin's 2011 throwback ASCII Xmas tree, but with shaded boxes ("presents") taking the place of ASCII characters in an effort to mimic some of the nice polygon Christmas tree art work floating about the web. Happy Holidays, all!

CODE

``````* Fun w/SAS ODS Graphics: Xmas tree made up of Xmas presents;

*==> Generate polygon vertices for a "Xmas present" (each face will be shaded differently);

data XmasPresent;
id=1;                                         * Right face;
x=0; y=1; output;
x=0; y=0; output;
x=cos(angle); y=sin(angle); output;
y+1; output;
id=2;                                         * Left face;
x=0; y=1; output;
x=0; y=0; output;
x=-cos(angle); y=sin(angle); output;
y+1; output;
id=3;                                         * Top face;
x=0; y=1; output;
x=-cos(angle); y=sin(angle)+1; output;
x=0; y=sin(angle)+1+sin(angle); output;
x=cos(angle); y=sin(angle)+1; output;
run;

data XmasPresent;                             * Add sequence # for plotting;
set XmasPresent;
seq+1;

*==> Generate points for presents that will make up the "Xmas tree";

data xmastree;
do row=12 to 3 by -1;                         * Tree is 10 rows (first row is 1 present, last is 10 presents);
yoffset=row*2*.875;                         * Adjust row height (87.5%) to tighten things up;
do col=0 to 9;
xoffset=^mod(row,2)+col*2+1;              * Offset each row's columns by 1;
idoffset+3;
rndcolor=put(ceil(7*ranuni(14)),1.);      * Assign one of 7 random colors to present;
if (row-3)<=xoffset<=(10.5+(12-row)) then
output;                                 * Output only desired # points for row (1, 2, ..., 10);
end;
end;
row=2;                                        * Generate "trunk" (2 rows of 3/2 presents);
yoffset=row*2*.875;
do col=3 to 5;
xoffset=2+col*2;
idoffset+3;
rndcolor=put(ceil(7*rand("Uniform")),1.);
output;
end;
row=1;
yoffset=row*2*.875;
do col=4 to 5;
xoffset=mod(row,2)+col*2;
idoffset+3;
rndcolor=put(ceil(7*rand("Uniform")),1.);
output;
end;
row=0;                                        * Generate "stand" (1 row of 5 presents);
yoffset=row*2*.875;
do col=2 to 6;
xoffset=2+col*2;
idoffset+3;
rndcolor=put(ceil(7*rand("Uniform")),1.);
output;
end;

*==> Merge Xmas tree points with Xmas present polygon points;

proc sql;
create table xmastreepresents as
select x+xoffset as x, y+yoffset as y,                       /* Keep present faces separate for shading */
case when id=1 then idoffset+id else . end as newid,  /* Right face */
case when id=2 then idoffset+id else . end as newid2, /* Left face */
case when id=3 then idoffset+id else . end as newid3, /* Top face */
RndColor
from xmastree x, xmaspresent p order by idoffset+id, seq;

*==> Hard work's done, let's plot a Xmas tree! (transparency used to shade present faces);

ods listing image_dpi=300 gpath='/folders/myfolders';
ods graphics on / reset antialias width=5in height=5in imagename="XMASTREE";

proc template;
define statgraph xmastemplate;
begingraph;
entryfootnote  "HAPPY HOLIDAYS!" / textattrs=(size=14pt weight=bold);
discreteAttrMap name='PresentColor';     * Translate random color #'s to colors;
value '1' / fillattrs=(color=blue);
value '2' / fillattrs=(color=red);
value '3' / fillattrs=(color=green);
value '4' / fillattrs=(color=purple);
value '5' / fillattrs=(color=orange);
value '6' / fillattrs=(color=hotpink);
value '7' / fillattrs=(color=black);
endDiscreteAttrMap;
discreteAttrVar attrVar=PresentC var=RndColor attrMap="PresentColor";
layout overlayequated / border=false xaxisopts=(display=(line ticks tickvalues))
yaxisopts=(display=(line ticks tickvalues));
polygonplot id=newid x=x y=y / display=(fill) group=presentc fillATTRS=(transparency=.75) INCLUDEMISSINGGROUP=FALSE;
polygonplot id=newid2 x=x y=y / display=(fill) group=presentc fillATTRS=(transparency=.45) INCLUDEMISSINGGROUP=FALSE;
polygonplot id=newid3 x=x y=y / display=(fill) group=presentc fillATTRS=(transparency=0) INCLUDEMISSINGGROUP=FALSE;
endlayout;
endgraph;
end;

proc sgrender data=xmastreepresents template=xmastemplate;
run;``````

SAS Super FREQ
Posts: 1,227

## Re: Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

Another good one, Ted.   I suggest removing the axes and wall border.

Frequent Contributor
Posts: 84

## Re: Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

Good suggestion - revised LAYOUT statement and image below!

``layout overlayequated / xaxisopts=(display=none) yaxisopts=(display=none) walldisplay=none;``
Community Manager
Posts: 3,194

## Re: Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

A Q*bert Christmas!

New User
Posts: 1

## Re: Fun w/ODS Graphics: Chock Full O'Presents Xmas Tree

wow

Discussion stats
• 4 replies
• 1873 views
• 12 likes
• 4 in conversation