Difference between revisions of "Noise"
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(22 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | <!--GIDEROSOBJ:FastNoise--> | |
− | <!-- GIDEROSOBJ:FastNoise --> | + | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> |
− | ''' | + | '''Available since:''' Gideros 2019.12<br/> |
− | ''' | ||
− | === | + | === Description === |
− | + | FastNoise is an open source noise generation library with a large collection of different noise algorithms. | |
− | + | ||
− | </ | + | '''[https://github.com/Auburns/FastNoise FastNoise home page]''' and its documentation '''https://github.com/Auburns/FastNoise/wiki''' |
− | === | + | |
+ | To add FastNoise plugin to your application you call: | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | require "FastNoise" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Features === | ||
* Value Noise 2D, 3D | * Value Noise 2D, 3D | ||
* Perlin Noise 2D, 3D | * Perlin Noise 2D, 3D | ||
Line 20: | Line 25: | ||
* Texture generation | * Texture generation | ||
* Array generation | * Array generation | ||
− | |||
− | === | + | === Examples === |
− | ''' | + | '''2D noise''' |
− | < | + | <syntaxhighlight lang="lua"> |
require "FastNoise" | require "FastNoise" | ||
Line 31: | Line 35: | ||
myNoise:setSeed(456) -- set generation seed | myNoise:setSeed(456) -- set generation seed | ||
myNoise:setFrequency(0.04) -- how coarse the noise output is | myNoise:setFrequency(0.04) -- how coarse the noise output is | ||
− | myNoise:setInterp( | + | myNoise:setInterp(Noise.HERMITE) -- set noise interpolation type |
− | myNoise:setNoiseType( | + | myNoise:setNoiseType(Noise.SIMPLEX) -- set noise type |
for y = 1, 4 do | for y = 1, 4 do | ||
Line 42: | Line 46: | ||
-- myNoise:noise2D(x, y) -- true 2D noise | -- myNoise:noise2D(x, y) -- true 2D noise | ||
-- myNoise:noise3D(x, y, z) -- true 3D noise | -- myNoise:noise3D(x, y, z) -- true 3D noise | ||
− | -- difference between noise2D(x, y) and noise(x, y) is that "noise" function uses 3D noise with z = 0 | + | -- difference between noise2D(x, y) and noise(x, y) is that "noise" function uses 3D noise with |
+ | -- x = 0, y = 0, z = 0 by default where noise2D uses only 2 values. In other words: noise(x) == noise(x,0,0); | ||
+ | -- noise(x, y) == noise(x,y,0); noise(x,y) == noise2D(x,y); noise(x,y,z) == noise3D(x,y,z) | ||
print(v) | print(v) | ||
end | end | ||
end | end | ||
− | </ | + | </syntaxhighlight> |
+ | '''Grayscaled noise image''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | require "FastNoise" | ||
− | + | local n = Noise.new() | |
− | + | -- generate 128x128 texture with filtering | |
− | + | local tex = n:getTexture(128, 128, true) | |
− | -- | + | -- add it to scene |
− | + | stage:addChild(Bitmap.new(tex)) | |
− | + | </syntaxhighlight> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | n: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | stage:addChild( | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ | ||
+ | '''Colored seamless noise image''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | require "FastNoise" | ||
− | + | local n = Noise.new() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local n = Noise.new() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
n:setFrequency(0.03) | n:setFrequency(0.03) | ||
n:setFractalOctaves(5) | n:setFractalOctaves(5) | ||
n:setFractalLacunarity(2.5) | n:setFractalLacunarity(2.5) | ||
n:setInterp(Noise.HERMITE) | n:setInterp(Noise.HERMITE) | ||
− | |||
n:setFractalGain(0.6) | n:setFractalGain(0.6) | ||
n:setNoiseType(Noise.SIMPLEX_FRACTAL) | n:setNoiseType(Noise.SIMPLEX_FRACTAL) | ||
− | + | -- set a color table used by noise | |
− | + | -- first value - height (number), must be in range [0..1] | |
− | + | -- second value - color (number) in hex format | |
− | + | -- third value - alpha (number), must be in range [0..1] (optional, default - 1) | |
− | + | n:setColorLookup{ | |
− | + | {0.3, 0x4b3c37, 1}, | |
− | + | {0.4, 0xffffff, 1}, | |
− | + | {0.45, 0x5c443d, 1}, | |
− | + | {0.55, 0x3f6a14, 1}, | |
− | + | {0.6, 0x589718, 1}, | |
− | + | {0.7, 0x3666c6, 1}, | |
− | + | {0.9, 0xd1d080, 1}, | |
− | + | {1, 0x3463c3, 1}, | |
− | stage:addChild( | + | } |
− | </ | + | -- generate 128x128 texture |
+ | local tex = n:getTileTexture(128, 128, false, {wrap=Texture.REPEAT}) | ||
+ | -- add it to scene | ||
+ | stage:addChild(Pixel.new(tex, 256,256)) | ||
+ | </syntaxhighlight> | ||
− | + | '''Some 3D examples [https://github.com/MultiPain/Gideros_examples here].''' | |
+ | '''Plus [https://github.com/MultiPain/Gideros_examples/tree/master/NoiseFlowField Particles flow field].''' | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === < | + | === Methods === |
− | [[ | + | [[Noise.new]] ''creates a new Noise object''<br/><!--GIDEROSMTD:Noise.new() creates a new Noise object--> |
+ | |||
+ | [[Noise:getCellularDistanceFunction]] ''returns distance function type''<br/><!--GIDEROSMTD:Noise:getCellularDistanceFunction() returns distance function type--> | ||
+ | [[Noise:getCellularJitter]] ''returns cellular jitter value''<br/><!--GIDEROSMTD:Noise:getCellularJitter() returns cellular jitter value--> | ||
+ | [[Noise:getCellularNoiseLookup]] ''returns Noise object that was set by setCellularNoiseLookup() function''<br/><!--GIDEROSMTD:Noise:getCellularNoiseLookup() returns Noise object that was set by setCellularNoiseLookup() function--> | ||
+ | [[Noise:getCellularReturnType]] ''returns cellular return type''<br/><!--GIDEROSMTD:Noise:getCellularReturnType() returns cellular return type--> | ||
+ | [[Noise:getFractalGain]] ''returns noise gain''<br/><!--GIDEROSMTD:Noise:getFractalGain() returns noise gain--> | ||
+ | [[Noise:getFractalLacunarity]] ''returns noise lacunarity''<br/><!--GIDEROSMTD:Noise:getFractalLacunarity() returns noise lacunarity--> | ||
+ | [[Noise:getFractalOctaves]] ''returns number of fractal octaves''<br/><!--GIDEROSMTD:Noise:getFractalOctaves() returns number of fractal octaves--> | ||
+ | [[Noise:getFractalType]] ''returns noise type''<br/><!--GIDEROSMTD:Noise:getFractalType() returns noise type--> | ||
+ | [[Noise:getFrequency]] ''returns noise frequency''<br/><!--GIDEROSMTD:Noise:getFrequency() returns noise frequency--> | ||
+ | [[Noise:getGradientPerturbAmp]] ''returns gradient perturb amplitude.''<br/><!--GIDEROSMTD:Noise:getGradientPerturbAmp() returns gradient perturb amplitude.--> | ||
+ | [[Noise:getInterp]] ''returns interpolation type''<br/><!--GIDEROSMTD:Noise:getInterp() returns interpolation type--> | ||
+ | [[Noise:getNoiseType]] ''returns noise type''<br/><!--GIDEROSMTD:Noise:getNoiseType() returns noise type--> | ||
+ | [[Noise:getSeed]] ''returns generator's seed''<br/><!--GIDEROSMTD:Noise:getSeed() returns generator's seed--> | ||
+ | [[Noise:getTexture]] ''gets noise texture''<br/><!--GIDEROSMTD:Noise:getTexture(width, height [, filtering, textureData]) gets noise texture--> | ||
+ | [[Noise:getTileTexture]] ''gets tileable texture''<br/><!--GIDEROSMTD:Noise:getTileTexture(width, height [, filtering, textureData]) gets tileable texture--> | ||
+ | [[Noise:gradientPerturb2D]] ''returns modified x, y''<br/><!--GIDEROSMTD:Noise:gradientPerturb2D(x,y) returns modified x, y--> | ||
+ | [[Noise:gradientPerturb3D]] ''returns modified x, y, z''<br/><!--GIDEROSMTD:Noise:gradientPerturb3D(x,y,z) returns modified x, y, z--> | ||
+ | [[Noise:gradientPerturbFractal2D]] ''returns modified x,y''<br/><!--GIDEROSMTD:Noise:gradientPerturbFractal2D(x,y) returns modified x,y--> | ||
+ | [[Noise:gradientPerturbFractal3D]] ''returns modified x,y,z''<br/><!--GIDEROSMTD:Noise:gradientPerturbFractal3D(x,y,z) returns modified x,y,z--> | ||
+ | [[Noise:noise]] ''gets noise value''<br/><!--GIDEROSMTD:Noise:noise([x,y,z]) gets noise value--> | ||
+ | [[Noise:noise2D]] ''gets 2D noise value''<br/><!--GIDEROSMTD:Noise:noise2D(x,y) gets 2D noise value--> | ||
+ | [[Noise:noise3D]] ''gets 3D noise value''<br/><!--GIDEROSMTD:Noise:noise3D(x,y,z) gets 3D noise value--> | ||
+ | [[Noise:reset]] ''resets noise parameters to default''<br/><!--GIDEROSMTD:FastNoise:reset() resets noise parameters to default--> | ||
+ | [[Noise:setCellularDistance2Indices]] ''sets the 2 distance indicies used for distance2 return types''<br/><!--GIDEROSMTD:Noise:setCellularDistance2Indices(index0, index1) sets the 2 distance indicies used for distance2 return types--> | ||
+ | [[Noise:setCellularDistanceFunction]] ''the distance function used to calculate the cell for a given point''<br/><!--GIDEROSMTD:Noise:setCellularDistanceFunction(distanceFunctionType) the distance function used to calculate the cell for a given point--> | ||
+ | [[Noise:setCellularJitter]] ''sets the maximum distance a cellular point can move from its grid position''<br/><!--GIDEROSMTD:Noise:setCellularJitter(jitter) sets the maximum distance a cellular point can move from its grid position--> | ||
+ | [[Noise:setCellularNoiseLookup]] ''noise used to calculate a cell value''<br/><!--GIDEROSMTD:Noise:setCellularNoiseLookup(Noise) noise used to calculate a cell value--> | ||
+ | [[Noise:setCellularReturnType]] ''what value does the cellular function returns from its calculations''<br/><!--GIDEROSMTD:Noise:setCellularReturnType(returnType) what value does the cellular function returns from its calculations--> | ||
+ | [[Noise:setColorLookup]] ''sets color table used by "getTexture" and "getTileTexture"''<br/><!--GIDEROSMTD:Noise:setColorLookup(table) sets color table used by "Noise:getTexture()" and "Noise:getTileTexture()"--> | ||
+ | [[Noise:setFractalGain]] ''the relative strength of noise from each layer when compared to the last''<br/><!--GIDEROSMTD:Noise:setFractalGain(gain) the relative strength of noise from each layer when compared to the last--> | ||
+ | [[Noise:setFractalLacunarity]] ''the frequency multiplier between each octave''<br/><!--GIDEROSMTD:Noise:setFractalLacunarity(lacunarity) the frequency multiplier between each octave--> | ||
+ | [[Noise:setFractalOctaves]] ''the amount of noise layers used to create the fractal''<br/><!--GIDEROSMTD:Noise:setFractalOctaves(n) the amount of noise layers used to create the fractal--> | ||
+ | [[Noise:setFractalType]] ''used in all fractal noise generation''<br/><!--GIDEROSMTD:Noise:setFractalType(noiseType) used in all fractal noise generation--> | ||
+ | [[Noise:setFrequency]] ''affects how coarse the noise output is''<br/><!--GIDEROSMTD:Noise:setFrequency(frequency) affects how coarse the noise output is--> | ||
+ | [[Noise:setGradientPerturbAmp]] ''sets the maximum perturb distance from original location when using gradientPerturb()''<br/><!--GIDEROSMTD:Noise:setGradientPerturbAmp(amp) sets the maximum perturb distance from original location when using gradientPerturb()--> | ||
+ | [[Noise:setInterp]] ''changes the interpolation method used to smooth between noise values''<br/><!--GIDEROSMTD:Noise:setInterp(interpolation) changes the interpolation method used to smooth between noise values--> | ||
+ | [[Noise:setNoiseType]] ''sets the type of noise returned by noise()''<br/><!--GIDEROSMTD:Noise:setNoiseType(noiseType) sets the type of noise returned by noise()--> | ||
+ | [[Noise:setSeed]] ''using different seeds will cause the noise output to change''<br/><!--GIDEROSMTD:Noise:setSeed() using different seeds will cause the noise output to change--> | ||
+ | [[Noise:simplex4D]] ''gets 4D simplex noise value''<br/><!--GIDEROSMTD:Noise:simplex4D(x,y,z,w) gets 4D simplex noise value--> | ||
+ | [[Noise:whiteNoise2DInt]] ''gets integer 2D white noise value''<br/><!--GIDEROSMTD:Noise:whiteNoise2DInt(x,y) gets integer 2D white noise value--> | ||
+ | [[Noise:whiteNoise3DInt]] ''gets integer 3D white noise value''<br/><!--GIDEROSMTD:Noise:whiteNoise3DInt(x,y,z) gets integer 3D white noise value--> | ||
+ | [[Noise:whiteNoise4D]] ''gets 4D white noise value''<br/><!--GIDEROSMTD:Noise:whiteNoise4D(x,y,z,w) gets 4D white noise value--> | ||
+ | [[Noise:whiteNoise4DInt]] ''gets integer 4D white noise value''<br/><!--GIDEROSMTD:Noise:whiteNoise4DInt(x,y,z,w) gets integer 4D white noise value--> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Events === |
− | === < | + | === Constants === |
+ | [[Noise.BILLOW]]<br/><!--GIDEROSCST:Noise.BILLOW billow--> | ||
+ | [[Noise.CELLULAR]]<br/><!--GIDEROSCST:Noise.CELLULAR cellular--> | ||
+ | [[Noise.CELL_VALUE]]<br/><!--GIDEROSCST:Noise.CELL_VALUE cell_value--> | ||
+ | [[Noise.CUBIC]]<br/><!--GIDEROSCST:Noise.CUBIC cubic--> | ||
+ | [[Noise.CUBIC_FRACTAL]]<br/><!--GIDEROSCST:Noise.CUBIC_FRACTAL cubic_fractal--> | ||
+ | [[Noise.DISTANCE]]<br/><!--GIDEROSCST:Noise.DISTANCE distance--> | ||
+ | [[Noise.DISTANCE_2]]<br/><!--GIDEROSCST:Noise.DISTANCE_2 distance_2--> | ||
+ | [[Noise.DISTANCE_2_ADD]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_ADD distance_2_add--> | ||
+ | [[Noise.DISTANCE_2_DIV]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_DIV distance_2_div--> | ||
+ | [[Noise.DISTANCE_2_MUL]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_MUL distance_2_mul--> | ||
+ | [[Noise.DISTANCE_2_SUB]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_SUB distance_2_sub--> | ||
+ | [[Noise.EUCLIDEAN]]<br/><!--GIDEROSCST:Noise.EUCLIDEAN euclidean--> | ||
+ | [[Noise.FBM]]<br/><!--GIDEROSCST:Noise.FBM fbm--> | ||
+ | [[Noise.HERMITE]]<br/><!--GIDEROSCST:Noise.HERMITE hermite--> | ||
+ | [[Noise.LINEAR]]<br/><!--GIDEROSCST:Noise.LINEAR linear--> | ||
+ | [[Noise.MANHATTAN]]<br/><!--GIDEROSCST:Noise.MANHATTAN manhattan--> | ||
+ | [[Noise.NATURAL]]<br/><!--GIDEROSCST:Noise.NATURAL natural--> | ||
+ | [[Noise.NOISE_LOOKUP]]<br/><!--GIDEROSCST:Noise.NOISE_LOOKUP noise_lookup--> | ||
+ | [[Noise.PERLIN]]<br/><!--GIDEROSCST:Noise.PERLIN perlin--> | ||
+ | [[Noise.PERLIN_FRACTAL]]<br/><!--GIDEROSCST:Noise.PERLIN_FRACTAL perlin_fractal--> | ||
+ | [[Noise.QUINTIC]]<br/><!--GIDEROSCST:Noise.QUINTIC quintic--> | ||
+ | [[Noise.RIGID_MULTI]]<br/><!--GIDEROSCST:Noise.RIGID_MULTI rigid_multi--> | ||
+ | [[Noise.SIMPLEX]]<br/><!--GIDEROSCST:Noise.SIMPLEX simplex--> | ||
+ | [[Noise.SIMPLEX_FRACTAL]]<br/><!--GIDEROSCST:Noise.SIMPLEX_FRACTAL simplex_fractal--> | ||
+ | [[Noise.VALUE]]<br/><!--GIDEROSCST:Noise.VALUE value--> | ||
+ | [[Noise.VALUE_FRACTAL]]<br/><!--GIDEROSCST:Noise.VALUE_FRACTAL value_fractal--> | ||
+ | [[Noise.WHITE_NOISE]]<br/><!--GIDEROSCST:Noise.WHITE_NOISE white_noise--> | ||
|} | |} | ||
− | {{ | + | {{GIDEROS IMPORTANT LINKS}} |
Latest revision as of 14:31, 13 July 2023
Supported platforms:
Available since: Gideros 2019.12
Description
FastNoise is an open source noise generation library with a large collection of different noise algorithms.
FastNoise home page and its documentation https://github.com/Auburns/FastNoise/wiki
To add FastNoise plugin to your application you call:
require "FastNoise"
Features
- Value Noise 2D, 3D
- Perlin Noise 2D, 3D
- Simplex Noise 2D, 3D, 4D
- Cubic Noise 2D, 3D
- Gradient Perturb 2D, 3D
- Multiple fractal options for all of the above
- Cellular (Voronoi) Noise 2D, 3D
- White Noise 2D, 3D, 4D
- Texture generation
- Array generation
Examples
2D noise
require "FastNoise"
local myNoise = Noise.new() -- create FastNoise instance
myNoise:setSeed(456) -- set generation seed
myNoise:setFrequency(0.04) -- how coarse the noise output is
myNoise:setInterp(Noise.HERMITE) -- set noise interpolation type
myNoise:setNoiseType(Noise.SIMPLEX) -- set noise type
for y = 1, 4 do
for x = 1, 4 do
local v = myNoise:noise(x, y) -- generate 2D noise
-- other possible function:
-- myNoise:noise(x) -- 1D noise
-- myNoise:noise(x, y, z) -- 3D noise
-- myNoise:noise2D(x, y) -- true 2D noise
-- myNoise:noise3D(x, y, z) -- true 3D noise
-- difference between noise2D(x, y) and noise(x, y) is that "noise" function uses 3D noise with
-- x = 0, y = 0, z = 0 by default where noise2D uses only 2 values. In other words: noise(x) == noise(x,0,0);
-- noise(x, y) == noise(x,y,0); noise(x,y) == noise2D(x,y); noise(x,y,z) == noise3D(x,y,z)
print(v)
end
end
Grayscaled noise image
require "FastNoise"
local n = Noise.new()
-- generate 128x128 texture with filtering
local tex = n:getTexture(128, 128, true)
-- add it to scene
stage:addChild(Bitmap.new(tex))
Colored seamless noise image
require "FastNoise"
local n = Noise.new()
n:setFrequency(0.03)
n:setFractalOctaves(5)
n:setFractalLacunarity(2.5)
n:setInterp(Noise.HERMITE)
n:setFractalGain(0.6)
n:setNoiseType(Noise.SIMPLEX_FRACTAL)
-- set a color table used by noise
-- first value - height (number), must be in range [0..1]
-- second value - color (number) in hex format
-- third value - alpha (number), must be in range [0..1] (optional, default - 1)
n:setColorLookup{
{0.3, 0x4b3c37, 1},
{0.4, 0xffffff, 1},
{0.45, 0x5c443d, 1},
{0.55, 0x3f6a14, 1},
{0.6, 0x589718, 1},
{0.7, 0x3666c6, 1},
{0.9, 0xd1d080, 1},
{1, 0x3463c3, 1},
}
-- generate 128x128 texture
local tex = n:getTileTexture(128, 128, false, {wrap=Texture.REPEAT})
-- add it to scene
stage:addChild(Pixel.new(tex, 256,256))
Some 3D examples here.
Plus Particles flow field.
MethodsNoise.new creates a new Noise object Noise:getCellularDistanceFunction returns distance function type |
EventsConstantsNoise.BILLOW |