@@ -8,6 +8,8 @@ description: Learn how to generate procedural noise using Python scripting in GR
88image : images/noise_01.webp
99links :
1010 g_region : " [g.region](https://grass.osgeo.org/grass-stable/manuals/g.region.html)"
11+ g_extension : " [g.extension](https://grass.osgeo.org/grass-stable/manuals/g.extension.html)"
12+ r_random_walk : " [r.random.walk](https://grass.osgeo.org/grass-stable/manuals/addons/r.random.walk.html)"
1113 r_mapcalc : " [r.mapcalc](https://grass.osgeo.org/grass-stable/manuals/r.mapcalc.html)"
1214 r_neighbors : " [r.neighbors](https://grass.osgeo.org/grass-stable/manuals/r.neighbors.html)"
1315 r_surf_fractal : " [r.surf.fractal](https://grass.osgeo.org/grass-stable/manuals/r.surf.fractal.html)"
@@ -37,6 +39,7 @@ such as terrain, water, and clouds.
3739Let's implement procedural noise using map algebra in GRASS!
3840This tutorial covers:
3941
42+ * Random walks
4043* Gradient noise
4144* Billow noise
4245* Ridge noise
@@ -92,6 +95,74 @@ session = gj.init(Path(temporary.name, "xy"))
9295gs.run_command("g.region", n=200, e=800, s=0, w=0, res=1)
9396```
9497
98+ # Random Walks
99+
100+ In a random walk,
101+ a walker traverses a space
102+ by taking a sequence of steps
103+ in random directions.
104+ Random walks can used to simulate stochastic processes
105+ such as migration, searching, foraging, accumulation, and diffusion.
106+ Depending on the number of walkers and steps,
107+ 2-dimensional random walks can create
108+ sparse or dense stochastic surfaces,
109+ which can be useful
110+ for generating other forms of procedural noise.
111+ In GRASS, 2-dimensional random walks
112+ can be generated with the addon
113+ {{< meta links.r_random_walk >}}.
114+ Walkers will traverse the computational region,
115+ each stepping cell by cell
116+ in a random direction
117+ across a raster grid.
118+ The output raster records the frequency of visits per cell.
119+ First install {{< meta links.r_random_walk >}} with
120+ {{< meta links.g_extension >}}.
121+
122+ ``` {python}
123+ gs.run_command("g.extension", extension="r.random.walk")
124+ ```
125+
126+ Then run {{< meta links.r_random_walk >}}
127+ with multiple walkers.
128+ Experiment with the parameters.
129+ Try varying the number of steps and walkers.
130+ If it runs slowly, try increasing the memory or number of processes.
131+ The resulting random walk can be used
132+ instead of an initial random or fractal surface
133+ in the following sections of this tutorial.
134+
135+ ``` {python}
136+ # Set parameters
137+ directions = 8
138+ steps = 50000
139+ walkers = 10
140+ memory = 1200
141+
142+ # Generate random walks
143+ gs.run_command(
144+ "r.random.walk",
145+ output="walk",
146+ directions=directions,
147+ steps=steps,
148+ nwalkers=walkers,
149+ memory=memory,
150+ flags="s",
151+ overwrite=True
152+ )
153+
154+ # Set color gradient
155+ gs.run_command("r.colors", map="walk", color="viridis")
156+
157+ # Visualize
158+ m = gj.Map(width=800)
159+ m.d_rast(map="walk")
160+ m.d_legend(raster="walk", color="white", at=(5, 95, 1, 3))
161+ m.show()
162+ ```
163+
164+ ![ Random walks] ( images/noise_00.webp )
165+
95166# Gradient Noise
96167
97168The original form of gradient noise - Perlin noise -
@@ -121,7 +192,9 @@ the `iterations` of smoothing,
121192and the ` wavelength ` of the moving window.
122193Experiment with these parameters.
123194Try setting different values for each of them.
124- Then try using a fractal surface
195+ Then try using random walks
196+ generated with {{< meta links.r_random_walk >}}
197+ or a fractal surface
125198generated with {{< meta links.r_surf_fractal >}}
126199instead of a random surface.
127200
@@ -149,6 +222,9 @@ for i in range(iterations):
149222 overwrite=True
150223 )
151224
225+ # Set color gradient
226+ gs.run_command("r.colors", map="noise", color="viridis")
227+
152228# Visualize
153229m = gj.Map(width=800)
154230m.d_rast(map="noise")
@@ -428,7 +504,6 @@ for octave in range(octaves):
428504 dimension = dimension + gain
429505 amplitude = amplitude + gain
430506 wavelength = round(wavelength * lacunarity)
431- ```suggestion
432507 if wavelength % 2 == 0:
433508 wavelength += 1
434509
0 commit comments