%let name=mandelbrot_gplot; filename odsout '.'; /* SAS/Graph version of http://rosettacode.org/wiki/Mandelbrot_set#Fortran */ /* %let x_min=-2.5; %let x_max=1.5; %let y_min=-1.5; %let y_max=1.5; */ %let x_min=-1.7; %let x_max=.7; %let y_min=-1.0; %let y_max=1.0; %let i_points=800; %let j_points=600; /* ------------------------------------------------------------ */ data mandelbrot (keep = j i colorvar); width=&x_max-&x_min; height=&y_max-&y_min; x_centre=&x_min+(width/2); y_centre=&y_min+(height/2); /* n_max is basically the 'complexity'. If you were using multiple colors, you'd want to define as many colors as you have n_max, and then use the following when you assign colorvar: colorvar=(n_max-n)+1; */ n_max=41; /* Although the plot looks like smooth/continuous color, it is really composed of lots of individual 'points' - if you use enough points, and pack them together dense enough, then they will look like solid colors. (i = x direction, and j = y direction) */ i_points=&i_points; j_points=&j_points; dx_di=width/i_points; dy_dj=height/j_points; x_offset=x_centre - 0.5*(i_points+1)*dx_di; y_offset=y_centre - 0.5*(j_points+1)*dy_dj; do j = 1 to j_points; y_0 = y_offset + dy_dj * j; do i = 1 to i_points; x_0 = x_offset + dx_di * i; x=0.0; y=0.0; n=0; do while (1=1); x_sqr=x**2; y_sqr=y**2; /* outside */ if (x_sqr+y_sqr > 4.0) then do; colorvar=2; /* black/inside */ output; leave; end; /* inside */ if (n eq n_max) then do; colorvar=1; /* white/outside */ output; leave; end; y=y_0 + 2.0*x*y; x=x_0 + x_sqr - y_sqr; n+1; end; end; end; run; goptions device=png xpixels=800 ypixels=600; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Mandelbrot set") style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=18pt htext=12pt; goptions ctext=gray33; symbol1 value=point interpol=none color=black; symbol2 value=point interpol=none color=white; axis1 label=none value=none major=none minor=none offset=(0,0); axis2 label=none value=none major=none minor=none offset=(0,0); title1 ls=1.5 "SAS/Graph Mandelbrot"; footnote1 "Created using Data Step and Proc Gplot"; proc gplot data=mandelbrot; plot j*i=colorvar / vaxis=axis1 haxis=axis2 nolegend des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;