<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Fun With SAS ODS Graphics: YAAEB (Yet another animated Easter Bunny) in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350415#M12159</link>
    <description>&lt;P&gt;Love it&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2017 01:06:08 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-04-17T01:06:08Z</dc:date>
    <item>
      <title>Fun With SAS ODS Graphics: YAAEB (Yet another animated Easter Bunny)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350390#M12158</link>
      <description>&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8338i32CCE26976B3BDA6/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="EB.gif" title="EB.gif" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CODE&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Fun w/SAS ODS Graphics: Animated Easter Bunny from points in math-aids.com graphing worksheet;

data EasterBunny(keep=shapeID x y polyX polyY);
length shapeID $ 20. x 8 y 8;
retain shapeID;                                
infile "/folders/myfolders/EB.txt" lrecl=1000;  * File contains points to plot from math-aids.com;
input;
if _infile_=:'Shape' then
  shapeID=_infile_;
else
  do;
    i=1;
    do while(scan(_infile_, i, ' ')^='');
      x=scan(_infile_, i, '(), ');
      y=scan(_infile_, i+1, '(), ');
      i+2;                                      * List of shapes to color on final slide;
      if shapeID in ('Shape 16' 'Shape 17' 'Shape 21' 'Shape 22'   
                     'Shape 3'  'Shape 4'  'Shape 5'  'Shape 6' 
                     'Shape 9'  'Shape 10' 'Shape 11' 'Shape 12') then
        do; polyX=x; polyY=y; end;
      output;
    end;
  end;
                                                 * Lines to draw;
data line(keep=function drawspace x1 y1 x2 y2 polyX polyY);
set EasterBunny;
by shapeID notsorted;
function='line';
drawspace='datavalue';
x1=lag(x);
y1=lag(y);
x2=x;
y2=y;
if ^first.shapeID;

%macro gentemplate(final=Y);                    * Draw the bunny!;
proc template;
define statgraph ebtemplate;
  begingraph;
    dynamic linenum;
    layout overlayequated / walldisplay=none
      xaxisopts=(display=none offsetmin=0.001 offsetmax=0.001)
      yaxisopts=(display=none offsetmin=0.001 offsetmax=0.001);
      scatterplot x=x y=y / markerattrs=(size=0);
      %if &amp;amp;final=Y %then %do;
      polygonplot x=PolyX y=PolyY id=ShapeID / display=(fill) label=none fillattrs=(color=pink);
      ellipseparm semimajor=.5 semiminor=.5 xorigin=-2 yorigin=2.5 slope=0 / display=all outlineattrs=(thickness=2pt) fillattrs=(color=pink);
      ellipseparm semimajor=.5 semiminor=.5 xorigin=-.5 yorigin=2.5 slope=0 / display=all outlineattrs=(thickness=2pt) fillattrs=(color=pink);
      %end;
      entry halign=right linenum / valign=bottom textattrs=(size=32 weight=bold color=lightgray);
      annotate;
    endlayout;
  endgraph;
end;
run;
%mend;

* Create animated GIF with one incremental plot for each line;

ods _all_ close;
options papersize=('4 in', '4 in') printerpath=gif animation=start 
        nodate nonumber animduration=1.8 animloop=YES NOANIMOVERLAY;
ods printer file='/folders/myfolders/EB.gif';
ods graphics / width=4in height=4in imagefmt=GIF;

%macro drawlines;
proc sql noprint;
select count(*) into :numlines from line;
quit;                   

%gentemplate(final=Y);                          * Display final image before drawing lines;
options animduration=1.8;
proc sgrender data=easterbunny template=ebtemplate sganno=line;
dynamic linenum=" "; 

options animduration=.04;                       * Line-by-line drawing;
%gentemplate(final=N); 
%do l=1 %to &amp;amp;numlines;                          * Draw incremental image with lines thus far;  
  proc sgrender data=easterbunny template=ebtemplate sganno=line(obs=&amp;amp;l);
  dynamic linenum="&amp;amp;l";
%end; 
run; 
%mend;

%drawlines;
options printerpath=gif animation=stop;
ods printer close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;Shape 1
-10 -7 -10 -8.5 -9.5 -9.5 -9 -10 -8 -10.5 -10 -7
Shape 2
-10 -7 -10.5 -6 -10 -4 -8.5 -3 -7 -2.5 -6.5 -2.5 -5.5 -3 -4.5 -4.5
-3.5 -7 -2.5 -10 -2 -12 -2.5 -14 -4 -14.5 -5.5 -14 -7 -12 -8 -10.5
Shape 3
-9.5 -5.5 -8.5 -5.5 -8 -6 -8 -7 -9 -7 -9.5 -6 -9.5 -5.5
Shape 4
-8.5 -3.5 -7.5 -4 -7 -5 -7.5 -6 -8 -5.5 -8.5 -4.5 -8.5 -3.5
Shape 5
-6.5 -3.5 -6 -3.5 -5.5 -4 -5.5 -5 -6 -5.5 -6.5 -5 -7 -4 -6.5 -3.5
Shape 6
-7 -6.5 -6 -6.5 -5.5 -7 -4.5 -8.5 -4 -10 -3.5 -12 -3.5 -13.5
-5 -13 -6 -11.5 -7.5 -9 -8 -8 -7.5 -7 -7 -6.5
Shape 7
-6.5 -2.5 -5 -2 -4.5 -2.5 -5.5 -3
Shape 8
-1 -3.5 -2.5 -5 -1.5 -5 -2 -6 -1 -6 -1.5 -7 -1 -6.5 -1 -8.5
Shape 9
6.5 -7.5 7.5 -6 8.5 -6 8.5 -6.5 8 -7.5 7.5 -7.5 6.5 -7.5
Shape 10
7.5 -8.5 8 -8 9 -7.5 10 -7.5 9.5 -8.5 8.5 -9 8 -9 7.5 -8.5
Shape 11
8 -10 8.5 -9.5 9.5 -9.5 10 -10 9.5 -10.5 8.5 -10.5 8 -10
Shape 12
0.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3 1 2 0.5 1 1 1.5 1.5
Shape 23
-1 0.5 -1 -1 0.5 -1 1 -0.5
Shape 24
-1 -1 -2 -1.5 -3 -1&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Apr 2017 20:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350390#M12158</guid>
      <dc:creator>tc</dc:creator>
      <dc:date>2017-04-16T20:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Fun With SAS ODS Graphics: YAAEB (Yet another animated Easter Bunny)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350415#M12159</link>
      <description>&lt;P&gt;Love it&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 01:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350415#M12159</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-04-17T01:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Fun With SAS ODS Graphics: YAAEB (Yet another animated Easter Bunny)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350493#M12164</link>
      <description>&lt;P&gt;Technically this is completely off topic as it doesn't use ODS or SAS/GRAPH, but I spent almost an hour doing it&amp;nbsp;so I can't not post it now. Here's the same in JavaScript, using a slightly modified version of the original SAS code to create the SVG, and&amp;nbsp;&lt;A href="https://github.com/maxwellito/vivus" target="_self"&gt;vivus.js&lt;/A&gt;&amp;nbsp;to animate it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8347i45507CF5F90A1218/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="bunny.gif" title="bunny.gif" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS code to generate the SVG looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length shapeID $ 20. x 8 y 8;
  gh = 40; * grid height ;
  gw = 30; * grid width ;
  file "/pub/ht/bunny/my.svg"; * target SVG location and write header ;
  if _n_ eq 1 then 
    put '&amp;lt;svg width="' gw +(-1) '0" height="' gh +(-1) '0" viewBox="0 0 ' gh gw '" id="bunny"&amp;gt;';
  infile "/pub/programs/EB.txt" lrecl=1000 end=EOF;  * File contains points to plot from math-aids.com;
  input;
  if _infile_=:'Shape' then do;
    shapeID=_infile_;
    if _n_ gt 1 then put '"/&amp;gt;'; * unless its the first element we will need to close last one ;
    if shapeID in ('Shape 16' 'Shape 17' 'Shape 21' 'Shape 22'   
               'Shape 3'  'Shape 4'  'Shape 5'  'Shape 6' 
               'Shape 9'  'Shape 10' 'Shape 11' 'Shape 12') then
    put '&amp;lt;polygon fill="none" stroke="#FF8A65" stroke-width="0.2" points="' @;
    * if this is a polygon then it is a polygon, else it is a polyline ;
    else put '&amp;lt;polyline fill="none" stroke="#FF8A65" stroke-width="0.2" points="' @;
  end;
  else do;
    i=1;
    do while(scan(_infile_, i, ' ')^='');
      x=scan(_infile_, i, '(), ') + ((gw / 2));
      put x +(-1) ',' @;
      y=((gh / 2) - scan(_infile_, i+1, '(), '));
      put y @;
      i+2;  
      output;
    end;
  end;
  if EOF then put '"/&amp;gt;&amp;lt;/svg&amp;gt;';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The Vivus JS constructor&amp;nbsp;to animate it looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;new Vivus('bunny', {
    type: 'oneByOne',
    duration: 800,
    pathTimingFunction: Vivus.EASE_OUT,
});&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If anyone wants to see the generated SVG or have a play around with the JavaScript code, the example is up on JsFiddle: &lt;A href="http://jsfiddle.net/m3xswhnz/" target="_self"&gt;http://jsfiddle.net/m3xswhnz/&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hurray for long weekends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nik&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 13:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-YAAEB-Yet-another-animated-Easter/m-p/350493#M12164</guid>
      <dc:creator>boemskats</dc:creator>
      <dc:date>2017-04-17T13:18:37Z</dc:date>
    </item>
  </channel>
</rss>

