Tutorial number 5
Selecting a random pattern
In the "Introduction to Scripting" window you saw a script which looked complicated. This script is designed to generate a random pattern just as you would by using the "random" menu item. This patters is saved and then correlated with itself and the second highest correlation value examined. If the second highest point is low we consider the pattern to be good. We compare this value with that of the previously lowest value and it is lower the pattern is placed is storage as the lowest. A new pattern is then generated so on until a loop counter exits the loop with the selected pattern in the big array.
The script starts with START and finally exits at the lower right.
The loop returns to START after the
branch icon. This icon terminates the loop after a count down.
Two paths arrive at this icon. One path just shows the current peak while the
other branch saves a new best pattern.
The "peak finder" icon selects between these two paths. If the second
highest peak is lower than the previous lowest then the green path is taken
and the pattern is retrieved in that branch and saved again for the end. The
settings in the dialog for this icon are shown below.
As you can see from examining this dialog the last execution of the icon did not result in the assignment of a new lowest pattern. The latest peak was 7.58183 while the best so far in the search was 6.304. At the start you should set that number to something like 16 or 20. The search is on the magnitude squared of the big array.
You may rightly be wondering how it is that we are looking at the second highest peak. The reason is that the highest peak is always at the center and it height is 512^2 (the number of pixels in a 512x512 screen). That peak was removed from the correlation by the "make dot" icon which has been set to multiply by an anti-dot at (0,0), leaving the second highest peak to be found by the branching peak finder. The settings for the dialog for that peak finder is above.
The remainder of the script from the start icon to the first peak finder creates the set of random phase numbers all with magnitude one and then makes the auto correlation with itself. these are the steps. We will follow these steps from the start.
The
random icon puts a set of random number ranging from one to
minus one into the real part and sets the imaginary part to zero. The
rescale icon is set to multiply the big array by pi and
then adding 1 to the imaginary part. The
icon changes from polar representations of the numbers to rectangular form.
The contents of the big array, which now consists of random-phase complex numbers
with magnitude one, are now captured by the
icon to be recovered if this set of numbers has a cleaner auto-correlation.
The
icons create the auto correlation of the array which is then tested. You should
be able to build and run this but the script is available in the answer folder
on my web site.
![]() |
For testing purposes, I usually set the branching icon to return to the start 50 times before following the final green path to quit. If you click the start button the script is run without resetting the peak finder or the clip icons. So the previous highest peak value is saved and the pattern persists in the lower left most clip icon. If the script is saved at this point the peak value is saved with the icon but the pattern is not saved. |
To save the result insert a save file icon at the end to save the latest best random pattern.