Skip to content

Instantly share code, notes, and snippets.

@FriedEgg
Last active August 29, 2015 14:15
Show Gist options
  • Save FriedEgg/ca5268c84e255a49b9c7 to your computer and use it in GitHub Desktop.
Save FriedEgg/ca5268c84e255a49b9c7 to your computer and use it in GitHub Desktop.
A Geeky Valentines
/* inspired by Rick Wicklin -- http://blogs.sas.com/content/iml/2015/02/11/binary-heart/ */
proc fcmp outlib=work.funcs.graph;
function heartx(t);
return(16*sin(t)**3);
endsub;
function hearty(t);
return(13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t));
endsub;
run;
options cmplib=work.funcs;
proc template;
define statgraph heart;
dynamic T;
begingraph;
entrytitle " ";
entryfootnote "{16*sin(t)^3, 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)}, {t, 0, 2*pi}";
layout overlay / yaxisopts=(
label=" "
display=none
)
xaxisopts=(
label=" "
display=none
)
;
entry "Happy Valentines Day";
if (exists(T))
seriesplot x=eval(heartx(T)) y=eval(hearty(T));
endif;
endlayout;
endgraph;
end;
run;
data foo;
drop pi;
pi = constant('pi');
do t=0 to 2*pi by 0.01*pi/4;
output;
end;
run;
proc sgrender data=foo template=heart;
dynamic t="T";
run;
proc fcmp outlib = work.funcs.graphs;
function heart3d(x,y);
t = 1 - x**2 - (y - abs(x))**2;
if sign(t)=-1 then return(0);
return(5-sqrt(t)*cos(30*t));
endsub;
run;
options cmplib=work.funcs;
proc template;
define statgraph heart3d;
dynamic X Y;
begingraph;
layout lattice / rows=1 columns=2;
layout overlay3d / cube=false rotate=5 tilt=85;
surfaceplotparm x=X y=Y z=eval(heart3d(X,Y)) /
surfacetype = fillgrid;
endlayout;
layout overlay;
contourplotparm x=X y=Y z=eval(heart3d(X,Y)) /
contourtype = fill;
endlayout;
endlayout;
endgraph;
end;
run;
data ranges / view=ranges;
do x=-1 to 1 by .01;
do y=-1 to 1.5 by .01;
output;
end;
end;
run;
proc sgrender data=ranges template=heart3d;
dynamic x="x" y="y";
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment