brownian.ps - generate Brownian Curves and Landscapes, in PostScript
(/home/pjb/ps/lib/brownian.ps) run % if run fails with invalidaccess you may need to use gv --nosafer % to send it to a printer see include_run . . . usertime realtime add srand % seed random number generator if you wish % and then, to generate a Brownian Curve: /redness 1.3 def % 0=whitenoise, 1=pinknoise, 2=rednoise /n_harmonics 100 def x1 x2 y_scale redness n_harmonics new_brownian_curve newpath x1 y1 moveto /x x1 def { /y x brownian_curve def x y lineto /x x delta_x add def x x2 gt { exit } if } loop stroke % or, to generate a Brownian Landscape: /redness 2.5 def % 0=whitenoise, 1=pinknoise, 2=rednoise x1 y1 x2 y2 z_scale redness n_harmonics new_brownian_landscape /x x1 def { % plot /y y1 def { /z x y brownian_landscape def newpath z setgray x y delta_x 0.7 mul 0 360 arc fill /y y delta_y add def y y2 gt { exit } if } loop /x x delta_x add def x x2 gt { exit } if } loop
The PostScript file brownian.ps generates brownian curves and brownian landscapes, to create realistic-looking horizons and cloudscapes, islands, or subtly textured backgrounds. The scale and the roughness (white noise, pink noise, red noise etc) are easily specified.
brownian.ps uses Fourier Synthesis from the prescribed spectrum, which consumes far less CPU time and memory than Numerical Convolution in the time or space domain. Fourier Synthesis is not usually used to generate brownian noise, because beyond the wavelength of the fundamental frequency the pattern repeats periodically; however, in a typical PostScript application, the user knows in advance over what range the curve must be valid, and the fundamental frequency can be chosen to cover this.
To install: go to
www.pjb.com.au/comp/free/brownian.ps.txt
and save the file to your local disc.
Rename it to brownian.ps and move it into some appropriate
directory such as ~/ps/lib . . .
new_brownian_curve, brownian_curve, new_brownian_landscape and brownian_landscape
Where the arguments are:
x1 x2
mark the range of x values over which the generated curve
will be defined; outside this range the curve will repeat cyclically.
y_scale
is the approximate scale of y values which the generated curve
will cover. Note that because the curve is random, the
precise values of the maximum and minimum are not guaranteed.
The average y-value of the resulting curve will be zero,
but that does not mean that the minimum and maximum will be equal in size.
The curve will begin and end at the same height.
redness
is the parameter which adjusts the roughness, or the fractal dimension,
of the curve. It will usually lie in the range between 0 and 5 or 6;
redness = 0 gives whitenoise,
redness = 1 gives pinknoise, and
redness = 2 gives rednoise.
See the references for what this means,
for example Manfred Schroeder's book.
n_harmonics
is the number of harmonics which will be generated.
Increasing this number makes the curve more finely detailed,
but increases the CPU load.
Generally, n_harmonics should be about a quarter of the
number of points from the curve that you intend to plot.
Invoking new_brownian_curve leaves nothing on the stack; all the data describing the resulting curve is stored in variables internal to the subroutine. It is therefore only possible to handle one brownian curve at once.
The above invocation leaves y on the stack, assuming new_brownian_curve has already been called.
Where the arguments are:
x1 x2
mark the range of x values over which the generated landscape
will be defined; outside this range the surface will repeat cyclically.
y1 y2
mark the range of y values over which the generated surface
will be defined; outside this range the landscape will repeat cyclically.
z_scale
is the approximate scale of z values which the generated landscape
will cover. Note that because the surface is random, the
precise values of the maximum and minimum are not guaranteed.
The average z-value of the resulting landscape will be zero,
but that does not mean that the minimum and maximum will be equal in size.
redness
is the parameter which adjusts the roughness, or the fractal dimension,
of the landscape. It will usually lie in the range between 0 and 5 or 6;
redness = 0 gives whitenoise,
redness = 1 gives pinknoise, and
redness = 2 gives rednoise.
See the references for what this means,
for example Manfred Schroeder's book.
n_harmonics
is the number of harmonics which will be generated in the larger of the
two independent variable ranges.
Increasing this number makes the surface more finely detailed,
but rapidly increases the CPU load !
Generally, n_harmonics should be about a quarter of the
number of points that you intend to plot in the larger of the x
and y ranges.
Invoking new_brownian_landscape leaves nothing on the stack; all the data describing the resulting surface is stored in variables internal to the subroutine. It is therefore only possible to handle one brownian landscape at once.
As an example, see www.pjb.com.au/comp/free/sample4.ps.txt . . .
To install: save the file to your local disc, rename it to sample4.ps and edit it so that the two run statements near the beginning point to the directory where brownian.ps and colours.ps are installed on your system. Then use GhostView or something like it to view your sample4.ps.
If you wish to print it out, feel free to use something like include_run to roll the run files into sample4.ps first.
For easy viewing, PDF versions of the results are in sample4.pdf . . .
To install: go to
www.pjb.com.au/comp/free/brownian.ps.txt
and save the file to your local disc.
Rename it to brownian.ps and move it into some appropriate
directory such as ~/ps/lib . . .
Or, first change directory to where you keep your PostScript libraries:
cd /home/wherever/ps/lib/
(or wherever) and then either:
wget -O brownian.ps http://www.pjb.com.au/comp/free/brownian.ps.txt
or:
curl http://www.pjb.com.au/comp/free/brownian.ps.txt -o brownian.ps
Or, get it from gitlab:
git clone
https://gitlab.com/peterbillam/postscriptlib
Peter J Billam, www.pjb.com.au/comp/contact.html
20030324 164606 pjb add brownian_island routine 20030322 144519 pjb bug fixed (I think) with 1 add in landscape 20030304 194855 pjb n=0,m!=0 and n!=0,m=0 components too 20030301 192752 pjb add -ve freqs, eliminating down-trend ! 20030202 085915 pjb bugs fixed in phase during synthesis 20030201 204532 pjb landscapes seem to work but tend downwards 20030130 211931 pjb curves do redness correctly 20030130 185041 pjb Brownian Curves and Landscapes
Back to P J B Computing or to www.pjb.com.au . . .