Module noiseplane
Utility for procedurally generating planes of random noise by various methods.
globalseed |
The global seed for all procedural generation. |
pos |
A table containing positional information passed to all generation functions. |
data |
A table to store and pass arbitrary data between generation functions. |
-
globalseed
-
The global seed for all procedural generation.
Initialised to a random seed. If you do not require run-to-run determinism, you can safely ignore this value.
-
pos
-
A table containing positional information passed to all generation functions.
Each generation function invocation receives a unique pos table.
- cx
integer
The x index of the current chunk.
- cy
integer
The y index of the current chunk.
- csize
integer
The size of the current chunk.
- x0
integer
The low x position of the current chunk.
- x1
integer
The high x position of the current chunk.
- y0
integer
The low y position of the current chunk.
- y1
integer
The high y position of the current chunk.
-
data
-
A table to store and pass arbitrary data between generation functions.
When generating a base-layer chunk, a data table is constructed to pass to all generation functions that will be called to generate that chunk.
By default, this is an empty table; to change this, see noisePlane:makeData.
-
NoisePlane()
-
Create a new NoisePlane.
Returns:
The new NoisePlane instance.
-
noisePlane:setSeed(seed)
-
Set the seed for this NoisePlane.
Each NoisePlane instance begins with its seed initialised randomly. If you do not require run-to-run determinism, you can safely ignore this function.
Each NoisePlane in a scenario should use a different seed.
Parameters:
- seed
integer
The seed to set.
Returns:
self
-
noisePlane:makeData(fn)
-
Provide a function to set the initial data table for generating a chunk.
If this function is not used, the data table will be initialised as a new empty table.
Parameters:
- fn
function
The function to generate the table.
Returns:
self
-
noisePlane:windows(size, fn)
-
Add a function called over a window of chunks below this layer.
The function will be called over a
size
xsize
area centred on the chunk being generated.
This function must be followed by an invocation of noisePlane:chunks to result in a valid NoisePlane instance.
Parameters:
- size
integer
The size of the desired window.
- fn
function
The function to call, which will be called with (pos, data)
Returns:
self
-
noisePlane:chunks(size, fn)
-
Add a function that merges several chunks below this layer into one.
The function will merge an area of
size
xsize
into a single chunk; all layers above this one will see the new chunk size.
Parameters:
- size
integer
The size of the desired area to merge into one chunk.
- fn
function
The function to call, which will be called with (pos, data)
Returns:
self
-
noisePlane:sample(cx, cy)
-
Sample this NoisePlane at the given coordinates.
Parameters:
- cx
integer
The x index to sample.
- cy
integer
The y index to sample.
Returns:
table
The data table after all generation functions have completed.