2022年6月29日水曜日

SASで花火を描く




暑中お見舞い申し上げます。




SASで花火描いてみました。三角関数をつかってるだけの単純なプログラムです。

/* 花火描画用データ */
data fireworks;
 rad = constant('pi')/180;
 call streaminit(777);
 do i = 1 to 5;
  xpos = rand("uniform",-30,30);
  ypos = rand("uniform",-30,30);
  do rmax = 0, 36;
  do r = 0 to rmax by 4;
  do a = 0 to 360 by 15;
    x=cos(a*rad)*r+xpos;
    y=sin(a*rad)*r+ypos;
    output;
  end;
  end;
  end;
 end;
run;

/* 花火描画 */
title;
ods graphics / height=20cm width=20cm;

options animation=start animduration=1.2 printerpath=gif;
ods noresults;
ods printer file="出力するGIFファイルのフルパスをここに指定。ファイル名は「fireworks.gif」とか適当に" ;

%macro m_fireworks(i=,color=);
 proc sgplot data=fireworks aspect=1 noautolegend;
  styleattrs wallcolor=midnightblue;
  scatter x=x y=y / markerattrs=(symbol=circlefilled color=&color size=0.1cm );
  xaxis min=-50 max=50 display=none;
  yaxis min=-50 max=50 display=none;
  inset "Summer Greetings to All."/ position=bottom textattrs=(color=lightblue size=25cm family="Arial");
  by rmax;
  where i=&i;
 run;
%mend;
%m_fireworks(i=1,color=yellow);
%m_fireworks(i=2,color=skyblue);
%m_fireworks(i=3,color=lightgreen);
%m_fireworks(i=4,color=yellow);
%m_fireworks(i=5,color=lightpink);

ods printer close;
ods results;
options animation=stop;

ods graphics / reset=all;