/* * This code is courtesy of R. Forrest McCluer, 11/4/2005. * "I thought that you might like this DSGI code - it is a variation of your * descent program - incorporating your color fill-in technique" * * I cleaned up the macros and some of the calling sequences. Future plans * include adding an anim macro for GIFANIM output. * - Richard A. DeVenezia 01may2006 * * Note: This sample code is sized for customization of Motorola Razr v3 phones. * The utility "P2k Commander" (http://s5vi.vxxxstuff.com/) can be used to copy the output file * graphics.gif over the phones /a/custwakeup.gif, thus replacing the hohum * Cingular branded poweron animation. */ /* libname gdevice0 "%sysfunc(pathname(WORK))"; proc gdevice catalog=gdevice0.devices nofs; delete bigpng; copy png from=sashelp.devices newname=bigpng; modify bigpng xmax=11.6in xpixels=1102 ymax=11.6in ypixels=1102; run;quit; */ filename gout "%sysfunc(pathname(WORK))\graphics-2.png"; filename gout "%sysfunc(pathname(WORK))\graphics-2.gif"; filename gout "\\extreme\sas\samples\spinward-granim1.gif"; goptions reset=all cback=WHITE /* device=BIGPNG */ device=GIFANIM gsfname=gout gsfmode=replace /* gaccess=sasgafix gsflen=80 */ display gunit=pct /*hsize=10 in vsize=10 in */ xpixels=680 ypixels=880 xpixels=170 ypixels=220 hsize= vsize= ; %macro ComputeNestedTriangles ( data=Triangles /* name of table to contain coordinates */ , levels = 0 /* numbers of levels of nesting of triangles */ , radius = 50 , x0 = 50 , y0 = 50 , tilt = 0 /* clockwise degrees baseline tilted */ ); /* * X,Y coordinate units are LL(0,0) UR(100,100) and * correspond to percent of active viewport */ * Step 0 - construct an outer triangle; data &DATA. (keep=level--y3); length level radius theta x0 y0 x1 y1 x2 y2 x3 y3 8; d2r = atan( 1 ) / 45; /* degrees to radians */ radius = &RADIUS.; x0 = &X0.; label x0 = 'x0: Center of Triangle'; y0 = &Y0.; label y0 = 'y0: Center of Triangle'; theta = -30 - &TILT.; x1=x0+(radius)*cos(d2r*(theta+0*120)); y1=y0+(radius)*sin(d2r*(theta+0*120)); x2=x0+(radius)*cos(d2r*(theta+1*120)); y2=y0+(radius)*sin(d2r*(theta+1*120)); x3=x0+(radius)*cos(d2r*(theta+2*120)); y3=y0+(radius)*sin(d2r*(theta+2*120)); level=0; run; * poor mans recursion, one data step per level descended; %local level; %do level=1 %to &levels; data &DATA. (keep=level--y3); set &DATA.; output; if level = &level-1 then do; * recurse; * nest four triangles within current triangle; level = level + 1; radius = radius / 2; x00 = x0; y00 = y0; x10 = x1; y10 = y1; x20 = x2; y20 = y2; x30 = x3; y30 = y3; x1= x10; y1= y10; x2=(x10+x20)/2; y2=(y10+y20)/2; x3=(x10+x30)/2; y3=(y10+y30)/2; x0=(x1+x2+x3)/3; y0=(y1+y2+y3)/3; output; x1=(x20+x10)/2; y1=(y20+y10)/2; x2= x20; y2= y20; x3=(x20+x30)/2; y3=(y20+y30)/2; x0=(x1+x2+x3)/3; y0=(y1+y2+y3)/3; output; x1=(x30+x10)/2; y1=(y30+y10)/2; x2=(x30+x20)/2; y2=(y30+y20)/2; x3= x30; y3= y30; x0=(x1+x2+x3)/3; y0=(y1+y2+y3)/3; output; * the central nested triangle is * flipped with respect to parent triangle; x1=(x10+x20)/2; y1=(y10+y20)/2; x2=(x20+x30)/2; y2=(y20+y30)/2; x3=(x30+x10)/2; y3=(y30+y10)/2; x0=(x1+x2+x3)/3; y0=(y1+y2+y3)/3; theta = mod (theta + 180, 360); output; end; keep x0-x3 y0-y3 level radius theta; run; %end; %mend; %macro PlotSpinwardTriangles ( data = Triangles , level = 0 , minimumRadius = 0 , step = 30 /* degrees */ , steps = 35 , gradientColors = ff0000 ffffff ff0000 , gradientPoints = 0 0.5 1 , hsize=5in , vsize=5in , glib = work , gmem = triangles ); %local i x nc; %let i=1; %let x = %scan(&gradientColors,&i,%str( )); %do %while (%length(&x)); %local r&i g&i b&i f&i; %let r&i = 0%substr(&x,1,2)x; %let g&i = 0%substr(&x,3,2)x; %let b&i = 0%substr(&x,5,2)x; %let f&i = %scan(&gradientPoints,&i,%str( )); %let i=%eval(&i+1); %let x = %scan(&gradientColors,&i,%str( )); %end; %let nc = %eval(&i-1); %let _2pi = %sysevalf(2*%sysfunc(constant(PI))); %let _pi = %sysfunc(constant(PI)); options mprint; data _null_; rc=gset('catalog',"&GLIB.","&GMEM."); rc=ginit(); rc=graph('clear','grinward'); array _r[&nc] _temporary_ (%do i = 1 %to &nc; &&r&i %end;); array _g[&nc] _temporary_ (%do i = 1 %to &nc; &&g&i %end;); array _b[&nc] _temporary_ (%do i = 1 %to &nc; &&b&i %end;); array _f[&nc] _temporary_ (%do i = 1 %to &nc; &&f&i %end;); if (_f[1] ne 0) or (_f[&nc] ne 1) then put "WARNING: There is a problem with gradientPoints"; d2r = atan( 1 ) / 45; step = &STEP.; angle_c = 180 - 30 - step; spin = 180; steps = spin / step; /* * Compute the gradient colors: * allow for 253 color points in the 0..1 gradient space; * compute the gradient color at each point according to * the color space traversal points passed in gradientColors * and gradientPoints */ rc = gset('COLREP', 1, 'BLACK'); do i = 1 to steps; alpha = (i-1) / (steps-1); index = floor(alpha * 253) + 2; do k=&nc to 1 by -1 until (alpha>_f[k]); end; if k=0 then k=1; color = 'CX' || put(_r[k]+(_r[k+1]-_r[k])*(alpha-_f[k])/(_f[k+1]-_f[k]), hex2.) || put(_g[k]+(_g[k+1]-_g[k])*(alpha-_f[k])/(_f[k+1]-_f[k]), hex2.) || put(_b[k]+(_b[k+1]-_b[k])*(alpha-_f[k])/(_f[k+1]-_f[k]), hex2.) ; rc = gset('COLREP', index, color); * put i=z3. alpha=9.7 k= index=z3. color=; end; do until (last); set &DATA. end=last; if level ne &LEVEL. then continue; x10=x1; y10=y1; x20=x2; y20=y2; x30=x3; y30=y3; theta0 = theta; nradius = radius; istep=0; do itheta = theta to theta + step * steps by step; istep+1; alpha = (istep-1) / (steps-1); index = min(255,floor(alpha * 253)+2); rc = gset('FILCOLOR',index); rc = gset('FILTYPE','SOLID'); rc = gdraw('FILL', 3, x10,x20,x30, y10,y20,y30); x10=x0+(nradius)*cos(d2r*(itheta+0*120)); x20=x0+(nradius)*cos(d2r*(itheta+1*120)); x30=x0+(nradius)*cos(d2r*(itheta+2*120)); y10=y0+(nradius)*sin(d2r*(itheta+0*120)); y20=y0+(nradius)*sin(d2r*(itheta+1*120)); y30=y0+(nradius)*sin(d2r*(itheta+2*120)); nradius= nradius / sin(angle_c*d2r) * sin(30*d2r); end; end; rc=graph('update'); rc=gterm(); run; %mend; %macro NestedSpinwardTriangles ( levels = 0 , x0 = 50 , y0 = 50 , radius = 50 , tilt = 0 , step = 5 , steps = 36 , minimumRadius=0.075 , gradientColors=0020ff 201F73 090766 , gradientPoints= 0 .5 1 ); %ComputeNestedTriangles ( data=Triangles , levels=&levels , x0=&x0 , y0=&y0 , radius=&radius , tilt=&tilt ); %PlotSpinwardTriangles ( data=Triangles , level =&levels , step=&step , steps=&steps , minimumRadius=&minimumRadius , gradientColors=&gradientColors , gradientPoints=&gradientPoints ); %mend; %NestedSpinwardTriangles ( levels=2 , radius=200 , step=1 , steps=185 , minimumRadius=0.075 , gradientColors=ff0000 ffff00 aaaa44 000000 , gradientPoints= 0 .15 .25 1 ); options xmin noxwait noxsync; x start "Preview" "%sysfunc(pathname(GOUT))";