Published on :
Graphic CREATION_INTERNE

IFS Christmas Tree Generator

This code is also available in: Deutsch Français
Awaiting validation
The script uses the IML procedure to implement a system of discrete stochastic iterated functions. It defines linear transformation matrices (L), translation vectors (B), and probabilities (prob) for each transformation. The iterative process calculates 100,000 points which, once plotted, form the image of a Christmas tree. The generated points are then stored in a SAS© dataset named 'IFS'. Finally, PROC SGPLOT is used to display these points as a scatter plot, without axes, to create a visual representation of the tree.
Data Analysis

Type : CREATION_INTERNE


The data (x, y points) are generated entirely within the PROC IML block by an iterative process, then stored in the temporary 'IFS' dataset. No external data or data from SASHELP is used for the main generation.

1 Code Block
PROC IML Data
Explanation :
This block initializes the linear transformation matrices (L), translation vectors (B), and probabilities for an iterated function system, specifically configured to generate a Christmas tree. It then performs 100,000 iterations using the `randgen` function to randomly select a transformation. Each iteration calculates a new point based on the previous one. The generated points (x, y) are then transcoded and stored in a temporary SAS dataset named 'IFS', which will be used for visualization.
Copied!
1PROC IML;
2/* For an explanation of how to construct an iterated function system in SAS, see
3 http://blogs.sas.com/content/iml/2012/12/12/iterated-function-systems-and-barnsleys-fern-in-sas/
4*/
5/* Each row is a 2x2 linear transformation */
6/* Christmas tree */
7L = {0.03 0 0 0.1,
8 0.85 0.00 0.00 0.85,
9 0.8 0.00 0.00 0.8,
10 0.2 -0.08 0.15 0.22,
11 -0.2 0.08 0.15 0.22,
12 0.25 -0.1 0.12 0.25,
13 -0.2 0.1 0.12 0.2};
14/* ... and each row is a translation vector */
15B = {0 0,
16 0 1.5,
17 0 1.5,
18 0 0.85,
19 0 0.85,
20 0 0.3,
21 0 0.4 };
22prob = { 0.02 0.6 0.1 0.07 0.07 0.07 0.07};
23L = L`; B = B`; /* For convenience, transpose the L and B matrices */
24
25/* Iterate the discrete stochastic map */
26N = 1e5; /* number of iterations */
27x = j(2,N); k = j(N,1);
28x[,1] = {0, 2}; /* initial point */
29call randgen(k, "Table", prob); /* values 1-7 */
30
31DO i = 2 to N;
32 x[,i] = shape(L[,k[i]], 2)*x[,i-1] + B[,k[i]]; /* iterate */
33END;
34
35/* Plot the iteration history */
36y = x`;
37create IFS from y[c={"x" "y"}]; append from y; close IFS;
38QUIT;
2 Code Block
PROC SGPLOT
Explanation :
This block configures the ODS Graphics destination system to set the output image size (200px wide by 400px high). Then, PROC SGPLOT is used to create a scatter plot from the previously generated 'IFS' dataset. Marker attributes are set with a small size (1) and a ForestGreen color to simulate the appearance of the tree's needles. The Y and X axes are disabled to produce a clean image of the tree.
Copied!
1ods graphics / width=200px height=400px;
2PROC SGPLOT DATA=IFS;
3 title "SAS Christmas Tree";
4 scatter x=x y=y / markerattrs=(size=1 color=ForestGreen);
5 yaxis display=none;
6 xaxis display=none;
7RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.