Difference between revisions of "Noise"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
<!--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/>
'''<translate>Supported platforms</translate>:''' [[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/>
'''<translate>Available since</translate>:''' Gideros 2019.12<br/>
 
  
=== <translate>Description</translate> ===
+
=== Description ===
<translate>FastNoise is an open source noise generation library with a large collection of different noise algorithms.
+
FastNoise is an open source noise generation library with a large collection of different noise algorithms.
[[https://github.com/Auburns/FastNoise FastNoise home page]]
+
 
</translate>
+
'''[https://github.com/Auburns/FastNoise FastNoise home page]''' and its documentation '''https://github.com/Auburns/FastNoise/wiki'''
=== <translate>Features</translate> ===
+
 
 +
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
<translate>Orignal documentation: https://github.com/Auburns/FastNoise/wiki</translate>
 
  
=== <translate>Examples</translate> ===
+
=== Examples ===
'''Example 1.'''
+
'''2D noise'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require "FastNoise"
 
require "FastNoise"
 
   
 
   
Line 48: Line 52:
 
end
 
end
 
end
 
end
</source>
+
</syntaxhighlight>
  
'''Example 2. Grayscaled noise image'''
+
'''Grayscaled noise image'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require "FastNoise"
 
require "FastNoise"
  
 
local n = Noise.new()  
 
local n = Noise.new()  
-- generate 128x128 texture
+
-- generate 128x128 texture with filtering
local tex = n:generateTexture(128, 128)
+
local tex = n:getTexture(128, 128, true)
 
-- add it to scene
 
-- add it to scene
 
stage:addChild(Bitmap.new(tex))
 
stage:addChild(Bitmap.new(tex))
</source>
+
</syntaxhighlight>
  
'''Example 3. Colored seamless noise image'''
+
'''Colored seamless noise image'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require "FastNoise"
 
require "FastNoise"
  
Line 72: Line 76:
 
n:setFractalGain(0.6)
 
n:setFractalGain(0.6)
 
n:setNoiseType(Noise.SIMPLEX_FRACTAL)
 
n:setNoiseType(Noise.SIMPLEX_FRACTAL)
-- create a color table used by noise
+
-- set a color table used by noise
-- h: height value in range [0..1]
+
-- first value - height (number), must be in range [0..1]
-- color: in RGBA format
+
-- second value - color (number) in hex format
local colors = {
+
-- third value - alpha (number), must be in range [0..1] (optional, default - 1)
{h = 0.3, color = {52,99,195,255}},
+
n:setColorLookup{
{h = 0.4, color = {54,102,198,255}},
+
{0.3, 0x4b3c37, 1},
{h = 0.45, color = {209,208,128,255}},
+
{0.4, 0xffffff, 1},
{h = 0.55, color = {88,151,24,255}},
+
{0.45, 0x5c443d, 1},
{h = 0.6, color = {63,106,20,255}},
+
{0.55, 0x3f6a14, 1},
{h = 0.7, color = {92,68,61,255}},
+
{0.6, 0x589718, 1},
{h = 0.9, color = {75,60,55,255}},
+
{0.7, 0x3666c6, 1},
{h = 1, color = {255,255,255,255}},
+
{0.9, 0xd1d080, 1},
 +
{1, 0x3463c3, 1},
 
}
 
}
 
-- generate 128x128 texture
 
-- generate 128x128 texture
local tex = n:generateTexture(128, 128, false, {wrap=Texture.REPEAT}, {tileable = true, colors = colors})
+
local tex = n:getTileTexture(128, 128, false, {wrap=Texture.REPEAT})
 
-- add it to scene
 
-- add it to scene
 
stage:addChild(Pixel.new(tex, 256,256))
 
stage:addChild(Pixel.new(tex, 256,256))
</source>
+
</syntaxhighlight>
  
See 3D examples [https://github.com/MultiPain/Gideros_examples here]
+
'''Some 3D examples [https://github.com/MultiPain/Gideros_examples here].'''
  
=== <translate>Notes</translate> ===
+
'''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;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Noise.new|Noise.new]] ''<translate>creates a new Noise object</translate>''<br/><!-- GIDEROSMTD:Noise.new() creates a new Noise object -->
+
[[Noise.new]] ''creates a new Noise object''<br/><!--GIDEROSMTD:Noise.new() creates a new Noise object-->
 
 
[[Special:MyLanguage/Noise:reset|Noise:reset]] ''<translate>reset noise parameters to default</translate>''<br/><!-- GIDEROSMTD:FastNoise:reset() reset noise parameters to default -->
 
[[Special:MyLanguage/Noise:noise|Noise:noise]] ''<translate>get noise value</translate>''<br/><!-- GIDEROSMTD:Noise:noise([x,y,z]) get noise value -->
 
[[Special:MyLanguage/Noise:noise2D|Noise:noise2D]] ''<translate>get 2D noise value</translate>''<br/><!-- GIDEROSMTD:Noise:noise2D(x,y) get 2D noise value -->
 
[[Special:MyLanguage/Noise:noise3D|Noise:noise3D]] ''<translate>get 3D noise value</translate>''<br/><!-- GIDEROSMTD:Noise:noise3D(x,y,z) get 3D noise value -->
 
[[Special:MyLanguage/Noise:whiteNoise4D|Noise:whiteNoise4D]] ''<translate>get 4D white noise value</translate>''<br/><!-- GIDEROSMTD:Noise:whiteNoise4D(x,y,z,w) get 4D white noise value -->
 
[[Special:MyLanguage/Noise:whiteNoise2DInt|Noise:whiteNoise2DInt]] ''<translate>get integer 2D white noise value</translate>''<br/><!-- GIDEROSMTD:Noise:whiteNoise2DInt(x,y) get integer 2D white noise value -->
 
[[Special:MyLanguage/Noise:whiteNoise3DInt|Noise:whiteNoise3DInt]] ''<translate>get integer 3D white noise value</translate>''<br/><!-- GIDEROSMTD:Noise:whiteNoise3DInt(x,y,z) get integer 3D white noise value -->
 
[[Special:MyLanguage/Noise:whiteNoise4DInt|Noise:whiteNoise4DInt]] ''<translate>get integer 4D white noise value</translate>''<br/><!-- GIDEROSMTD:Noise:whiteNoise4DInt(x,y,z,w) get integer 4D white noise value -->
 
[[Special:MyLanguage/Noise:simplex4D|Noise:simplex4D]] ''<translate>get 4D simplex noise value</translate>''<br/><!-- GIDEROSMTD:Noise:simplex4D(x,y,z,w) get 4D simplex noise value -->
 
[[Special:MyLanguage/Noise:gradientPerturb2D|Noise:gradientPerturb2D]] ''<translate>returns modified x, y</translate>''<br/><!-- GIDEROSMTD:Noise:gradientPerturb2D(x,y) returns modified x, y -->
 
[[Special:MyLanguage/Noise:gradientPerturb3D|Noise:gradientPerturb3D]] ''<translate>returns modified x, y, z</translate>''<br/><!-- GIDEROSMTD:Noise:gradientPerturb3D(x,y,z) returns modified x, y, z -->
 
[[Special:MyLanguage/Noise:gradientPerturbFractal2D|Noise:gradientPerturbFractal2D]] ''<translate>returns modified x,y</translate>''<br/><!-- GIDEROSMTD:Noise:gradientPerturbFractal2D(x,y) returns modified x,y -->
 
[[Special:MyLanguage/Noise:gradientPerturbFractal3D|Noise:gradientPerturbFractal3D]] ''<translate>returns modified x,y,z</translate>''<br/><!-- GIDEROSMTD:Noise:gradientPerturbFractal3D(x,y,z) returns modified x,y,z -->
 
  
[[Special:MyLanguage/Noise:setNoiseType|Noise:setNoiseType]] ''<translate>sets the type of noise returned by noise()</translate>''<br/><!-- GIDEROSMTD:Noise:setNoiseType(noiseType) sets the type of noise returned by noise() -->
+
[[Noise:getCellularDistanceFunction]] ''returns distance function type''<br/><!--GIDEROSMTD:Noise:getCellularDistanceFunction() returns distance function type-->
[[Special:MyLanguage/Noise:setFractalOctaves|Noise:setFractalOctaves]] ''<translate>the amount of noise layers used to create the fractal</translate>''<br/><!-- GIDEROSMTD:Noise:setFractalOctaves(n) the amount of noise layers used to create the fractal -->
+
[[Noise:getCellularJitter]] ''returns cellular jitter value''<br/><!--GIDEROSMTD:Noise:getCellularJitter() returns cellular jitter value-->
[[Special:MyLanguage/Noise:setInterp|Noise:setInterp]] ''<translate>changes the interpolation method used to smooth between noise values</translate>''<br/><!-- GIDEROSMTD:Noise:setInterp(interpolation) changes the interpolation method used to smooth between noise values -->
+
[[Noise:getCellularNoiseLookup]] ''returns Noise object that was set by setCellularNoiseLookup() function''<br/><!--GIDEROSMTD:Noise:getCellularNoiseLookup() returns Noise object that was set by setCellularNoiseLookup() function-->
[[Special:MyLanguage/Noise:setSeed|Noise:setSeed]] ''<translate>using different seeds will cause the noise output to change</translate>''<br/><!-- GIDEROSMTD:Noise:setSeed() using different seeds will cause the noise output to change -->
+
[[Noise:getCellularReturnType]] ''returns cellular return type''<br/><!--GIDEROSMTD:Noise:getCellularReturnType() returns cellular return type-->
[[Special:MyLanguage/Noise:setFrequency|Noise:setFrequency]] ''<translate>affects how coarse the noise output is</translate>''<br/><!-- GIDEROSMTD:Noise:setFrequency(frequency) affects how coarse the noise output is -->
+
[[Noise:getFractalGain]] ''returns noise gain''<br/><!--GIDEROSMTD:Noise:getFractalGain() returns noise gain-->
[[Special:MyLanguage/Noise:setFractalLacunarity|Noise:setFractalLacunarity]] ''<translate>the frequency multiplier between each octave</translate>''<br/><!-- GIDEROSMTD:Noise:setFractalLacunarity(lacunarity) the frequency multiplier between each octave -->
+
[[Noise:getFractalLacunarity]] ''returns noise lacunarity''<br/><!--GIDEROSMTD:Noise:getFractalLacunarity() returns noise lacunarity-->
[[Special:MyLanguage/Noise:setFractalGain|Noise:setFractalGain]] ''<translate>the relative strength of noise from each layer when compared to the last</translate>''<br/><!-- GIDEROSMTD:Noise:setFractalGain(gain) the relative strength of noise from each layer when compared to the last -->
+
[[Noise:getFractalOctaves]] ''returns number of fractal octaves''<br/><!--GIDEROSMTD:Noise:getFractalOctaves() returns number of fractal octaves-->
[[Special:MyLanguage/Noise:setFractalType|Noise:setFractalType]] ''<translate>used in all fractal noise generation</translate>''<br/><!-- GIDEROSMTD:Noise:setFractalType(noiseType) used in all fractal noise generation -->
+
[[Noise:getFractalType]] ''returns noise type''<br/><!--GIDEROSMTD:Noise:getFractalType() returns noise type-->
[[Special:MyLanguage/Noise:setCellularDistanceFunction|Noise:setCellularDistanceFunction]] ''<translate>the distance function used to calculate the cell for a given point</translate>''<br/><!-- GIDEROSMTD:Noise:setCellularDistanceFunction(distanceFunctionType) the distance function used to calculate the cell for a given point -->
+
[[Noise:getFrequency]] ''returns noise frequency''<br/><!--GIDEROSMTD:Noise:getFrequency() returns noise frequency-->
[[Special:MyLanguage/Noise:setCellularReturnType|Noise:setCellularReturnType]] ''<translate>what value does the cellular function return from its calculations</translate>''<br/><!-- GIDEROSMTD:Noise:setCellularReturnType(returnType) what value does the cellular function return from its calculations -->
+
[[Noise:getGradientPerturbAmp]] ''returns gradient perturb amplitude.''<br/><!--GIDEROSMTD:Noise:getGradientPerturbAmp() returns gradient perturb amplitude.-->
[[Special:MyLanguage/Noise:setCellularNoiseLookup|Noise:setCellularNoiseLookup]] ''<translate>TODO</translate>''<br/><!-- GIDEROSMTD:Noise:setCellularNoiseLookup(Noise) TODO -->
+
[[Noise:getInterp]] ''returns interpolation type''<br/><!--GIDEROSMTD:Noise:getInterp() returns interpolation type-->
[[Special:MyLanguage/Noise:setCellularDistance2Indices|Noise:setCellularDistance2Indices]] ''<translate>sets the 2 distance indicies used for distance2 return types</translate>''<br/><!-- GIDEROSMTD:Noise:setCellularDistance2Indices(index0, index1) sets the 2 distance indicies used for distance2 return types -->
+
[[Noise:getNoiseType]] ''returns noise type''<br/><!--GIDEROSMTD:Noise:getNoiseType() returns noise type-->
[[Special:MyLanguage/Noise:setCellularJitter|Noise:setCellularJitter]] ''<translate>sets the maximum distance a cellular point can move from its grid position</translate>''<br/><!-- GIDEROSMTD:Noise:setCellularJitter(jitter) sets the maximum distance a cellular point can move from its grid position -->
+
[[Noise:getSeed]] ''returns generator's seed''<br/><!--GIDEROSMTD:Noise:getSeed() returns generator's seed-->
[[Special:MyLanguage/Noise:setGradientPerturbAmp|Noise:setGradientPerturbAmp]] ''<translate>sets the maximum perturb distance from original location when using gradientPerturb()</translate>''<br/><!-- GIDEROSMTD:Noise:setGradientPerturbAmp(amp) sets the maximum perturb distance from original location when using gradientPerturb() -->
+
[[Noise:getTexture]] ''gets noise texture''<br/><!--GIDEROSMTD:Noise:getTexture(width, height [, filtering, textureData]) gets noise texture-->
[[Special:MyLanguage/Noise:getNoiseType|Noise:getNoiseType]] ''<translate>returns noise type</translate>''<br/><!-- GIDEROSMTD:Noise:getNoiseType() returns noise type -->
+
[[Noise:getTileTexture]] ''gets tileable texture''<br/><!--GIDEROSMTD:Noise:getTileTexture(width, height [, filtering, textureData]) gets tileable texture-->
[[Special:MyLanguage/Noise:getFractalOctaves|Noise:getFractalOctaves]] ''<translate>returns number of fractal octaves</translate>''<br/><!-- GIDEROSMTD:Noise:getFractalOctaves() returns number of fractal octaves -->
+
[[Noise:gradientPerturb2D]] ''returns modified x, y''<br/><!--GIDEROSMTD:Noise:gradientPerturb2D(x,y) returns modified x, y-->
[[Special:MyLanguage/Noise:getInterp()|Noise:getInterp()]] ''<translate>returns interpolation type</translate>''<br/><!-- GIDEROSMTD:Noise:getInterp() returns interpolation type -->
+
[[Noise:gradientPerturb3D]] ''returns modified x, y, z''<br/><!--GIDEROSMTD:Noise:gradientPerturb3D(x,y,z) returns modified x, y, z-->
[[Special:MyLanguage/Noise:getSeed|Noise:getSeed]] ''<translate>returns generator's seed</translate>''<br/><!-- GIDEROSMTD:Noise:getSeed() returns generator's seed -->
+
[[Noise:gradientPerturbFractal2D]] ''returns modified x,y''<br/><!--GIDEROSMTD:Noise:gradientPerturbFractal2D(x,y) returns modified x,y-->
[[Special:MyLanguage/Noise:getFrequency|Noise:getFrequency]] ''<translate>returns noise frequency</translate>''<br/><!-- GIDEROSMTD:Noise:getFrequency() returns noise frequency -->
+
[[Noise:gradientPerturbFractal3D]] ''returns modified x,y,z''<br/><!--GIDEROSMTD:Noise:gradientPerturbFractal3D(x,y,z) returns modified x,y,z-->
[[Special:MyLanguage/Noise:getFractalLacunarity|Noise:getFractalLacunarity]] ''<translate>returns noise lacunarity</translate>''<br/><!-- GIDEROSMTD:Noise:getFractalLacunarity() returns noise lacunarity -->
+
[[Noise:noise]] ''gets noise value''<br/><!--GIDEROSMTD:Noise:noise([x,y,z]) gets noise value-->
[[Special:MyLanguage/Noise:getFractalGain|Noise:getFractalGain]] ''<translate>return noise gain</translate>''<br/><!-- GIDEROSMTD:Noise:getFractalGain() return noise gain -->
+
[[Noise:noise2D]] ''gets 2D noise value''<br/><!--GIDEROSMTD:Noise:noise2D(x,y) gets 2D noise value-->
[[Special:MyLanguage/Noise:getFractalType|Noise:getFractalType]] ''<translate>returns noise type</translate>''<br/><!-- GIDEROSMTD:Noise:getFractalType() returns noise type -->
+
[[Noise:noise3D]] ''gets 3D noise value''<br/><!--GIDEROSMTD:Noise:noise3D(x,y,z) gets 3D noise value-->
[[Special:MyLanguage/Noise:getCellularDistanceFunction|Noise:getCellularDistanceFunction]] ''<translate>returns distance function type</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularDistanceFunction() returns distance function type -->
+
[[Noise:reset]] ''resets noise parameters to default''<br/><!--GIDEROSMTD:FastNoise:reset() resets noise parameters to default-->
[[Special:MyLanguage/Noise:getCellularReturnType|Noise:getCellularReturnType]] ''<translate>returns cellular return type</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularReturnType() returns cellular return type -->
+
[[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-->
[[Special:MyLanguage/Noise:getCellularNoiseLookup|Noise:getCellularNoiseLookup]] ''<translate>returns Noise object that was set by setCellularNoiseLookup() function</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularNoiseLookup() returns Noise object that was set by setCellularNoiseLookup() function -->
+
[[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-->
[[Special:MyLanguage/Noise:getCellularJitter|Noise:getCellularJitter]] ''<translate>returns cellular jitter value</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularJitter() returns cellular jitter value -->
+
[[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-->
[[Special:MyLanguage/Noise:getGradientPerturbAmp|Noise:getGradientPerturbAmp]] ''<translate>returns gradient perturb amplitude.</translate>''<br/><!-- GIDEROSMTD:Noise:getGradientPerturbAmp() returns gradient perturb amplitude. -->
+
[[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;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
[[Special:MyLanguage/Noise.FBM|Noise.FBM]]<br/><!-- GIDEROSCST:Noise.FBM fbm-->
+
[[Noise.BILLOW]]<br/><!--GIDEROSCST:Noise.BILLOW billow-->
[[Special:MyLanguage/Noise.BILLOW|Noise.BILLOW]]<br/><!-- GIDEROSCST:Noise.BILLOW billow-->
+
[[Noise.CELLULAR]]<br/><!--GIDEROSCST:Noise.CELLULAR cellular-->
[[Special:MyLanguage/Noise.RIGID_MULTI|Noise.RIGID_MULTI]]<br/><!-- GIDEROSCST:Noise.RIGID_MULTI rigid_multi-->
+
[[Noise.CELL_VALUE]]<br/><!--GIDEROSCST:Noise.CELL_VALUE cell_value-->
[[Special:MyLanguage/Noise.VALUE|Noise.VALUE]]<br/><!-- GIDEROSCST:Noise.VALUE value-->
+
[[Noise.CUBIC]]<br/><!--GIDEROSCST:Noise.CUBIC cubic-->
[[Special:MyLanguage/Noise.VALUE_FRACTAL|Noise.VALUE_FRACTAL]]<br/><!-- GIDEROSCST:Noise.VALUE_FRACTAL value_fractal-->
+
[[Noise.CUBIC_FRACTAL]]<br/><!--GIDEROSCST:Noise.CUBIC_FRACTAL cubic_fractal-->
[[Special:MyLanguage/Noise.PERLIN|Noise.PERLIN]]<br/><!-- GIDEROSCST:Noise.PERLIN perlin-->
+
[[Noise.DISTANCE]]<br/><!--GIDEROSCST:Noise.DISTANCE distance-->
[[Special:MyLanguage/Noise.PERLIN_FRACTAL|Noise.PERLIN_FRACTAL]]<br/><!-- GIDEROSCST:Noise.PERLIN_FRACTAL perlin_fractal-->
+
[[Noise.DISTANCE_2]]<br/><!--GIDEROSCST:Noise.DISTANCE_2 distance_2-->
[[Special:MyLanguage/Noise.SIMPLEX|Noise.SIMPLEX]]<br/><!-- GIDEROSCST:Noise.SIMPLEX simplex-->
+
[[Noise.DISTANCE_2_ADD]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_ADD distance_2_add-->
[[Special:MyLanguage/Noise.SIMPLEX_FRACTAL|Noise.SIMPLEX_FRACTAL]]<br/><!-- GIDEROSCST:Noise.SIMPLEX_FRACTAL simplex_fractal-->
+
[[Noise.DISTANCE_2_DIV]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_DIV distance_2_div-->
[[Special:MyLanguage/Noise.CELLULAR|Noise.CELLULAR]]<br/><!-- GIDEROSCST:Noise.CELLULAR cellular-->
+
[[Noise.DISTANCE_2_MUL]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_MUL distance_2_mul-->
[[Special:MyLanguage/Noise.WHITE_NOISE|Noise.WHITE_NOISE]]<br/><!-- GIDEROSCST:Noise.WHITE_NOISE white_noise-->
+
[[Noise.DISTANCE_2_SUB]]<br/><!--GIDEROSCST:Noise.DISTANCE_2_SUB distance_2_sub-->
[[Special:MyLanguage/Noise.CUBIC|Noise.CUBIC]]<br/><!-- GIDEROSCST:Noise.CUBIC cubic-->
+
[[Noise.EUCLIDEAN]]<br/><!--GIDEROSCST:Noise.EUCLIDEAN euclidean-->
[[Special:MyLanguage/Noise.CUBIC_FRACTAL|Noise.CUBIC_FRACTAL]]<br/><!-- GIDEROSCST:Noise.CUBIC_FRACTAL cubic_fractal-->
+
[[Noise.FBM]]<br/><!--GIDEROSCST:Noise.FBM fbm-->
[[Special:MyLanguage/Noise.CELL_VALUE|Noise.CELL_VALUE]]<br/><!-- GIDEROSCST:Noise.CELL_VALUE cell_value-->
+
[[Noise.HERMITE]]<br/><!--GIDEROSCST:Noise.HERMITE hermite-->
[[Special:MyLanguage/Noise.NOISE_LOOKUP|Noise.NOISE_LOOKUP]]<br/><!-- GIDEROSCST:Noise.NOISE_LOOKUP noise_lookup-->
+
[[Noise.LINEAR]]<br/><!--GIDEROSCST:Noise.LINEAR linear-->
[[Special:MyLanguage/Noise.DISTANCE|Noise.DISTANCE]]<br/><!-- GIDEROSCST:Noise.DISTANCE distance-->
+
[[Noise.MANHATTAN]]<br/><!--GIDEROSCST:Noise.MANHATTAN manhattan-->
[[Special:MyLanguage/Noise.DISTANCE_2|Noise.DISTANCE_2]]<br/><!-- GIDEROSCST:Noise.DISTANCE_2 distance_2-->
+
[[Noise.NATURAL]]<br/><!--GIDEROSCST:Noise.NATURAL natural-->
[[Special:MyLanguage/Noise.DISTANCE_2_ADD|Noise.DISTANCE_2_ADD]]<br/><!-- GIDEROSCST:Noise.DISTANCE_2_ADD distance_2_add-->
+
[[Noise.NOISE_LOOKUP]]<br/><!--GIDEROSCST:Noise.NOISE_LOOKUP noise_lookup-->
[[Special:MyLanguage/Noise.DISTANCE_2_SUB|Noise.DISTANCE_2_SUB]]<br/><!-- GIDEROSCST:Noise.DISTANCE_2_SUB distance_2_sub-->
+
[[Noise.PERLIN]]<br/><!--GIDEROSCST:Noise.PERLIN perlin-->
[[Special:MyLanguage/Noise.DISTANCE_2_MUL|Noise.DISTANCE_2_MUL]]<br/><!-- GIDEROSCST:Noise.DISTANCE_2_MUL distance_2_mul-->
+
[[Noise.PERLIN_FRACTAL]]<br/><!--GIDEROSCST:Noise.PERLIN_FRACTAL perlin_fractal-->
[[Special:MyLanguage/Noise.DISTANCE_2_DIV|Noise.DISTANCE_2_DIV]]<br/><!-- GIDEROSCST:Noise.DISTANCE_2_DIV distance_2_div-->
+
[[Noise.QUINTIC]]<br/><!--GIDEROSCST:Noise.QUINTIC quintic-->
[[Special:MyLanguage/Noise.LINEAR|Noise.LINEAR]]<br/><!-- GIDEROSCST:Noise.LINEAR linear-->
+
[[Noise.RIGID_MULTI]]<br/><!--GIDEROSCST:Noise.RIGID_MULTI rigid_multi-->
[[Special:MyLanguage/Noise.HERMITE|Noise.HERMITE]]<br/><!-- GIDEROSCST:Noise.HERMITE hermite-->
+
[[Noise.SIMPLEX]]<br/><!--GIDEROSCST:Noise.SIMPLEX simplex-->
[[Special:MyLanguage/Noise.QUINTIC|Noise.QUINTIC]]<br/><!-- GIDEROSCST:Noise.QUINTIC quintic-->
+
[[Noise.SIMPLEX_FRACTAL]]<br/><!--GIDEROSCST:Noise.SIMPLEX_FRACTAL simplex_fractal-->
[[Special:MyLanguage/Noise.EUCLIDEAN|Noise.EUCLIDEAN]]<br/><!-- GIDEROSCST:Noise.EUCLIDEAN euclidean-->
+
[[Noise.VALUE]]<br/><!--GIDEROSCST:Noise.VALUE value-->
[[Special:MyLanguage/Noise.MANHATTAN|Noise.MANHATTAN]]<br/><!-- GIDEROSCST:Noise.MANHATTAN manhattan-->
+
[[Noise.VALUE_FRACTAL]]<br/><!--GIDEROSCST:Noise.VALUE_FRACTAL value_fractal-->
[[Special:MyLanguage/Noise.NATURAL|Noise.NATURAL]]<br/><!-- GIDEROSCST:Noise.NATURAL natural-->
+
[[Noise.WHITE_NOISE]]<br/><!--GIDEROSCST:Noise.WHITE_NOISE white_noise-->
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 14:31, 13 July 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
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.

Methods

Noise.new creates a new Noise object

Noise:getCellularDistanceFunction returns distance function type
Noise:getCellularJitter returns cellular jitter value
Noise:getCellularNoiseLookup returns Noise object that was set by setCellularNoiseLookup() function
Noise:getCellularReturnType returns cellular return type
Noise:getFractalGain returns noise gain
Noise:getFractalLacunarity returns noise lacunarity
Noise:getFractalOctaves returns number of fractal octaves
Noise:getFractalType returns noise type
Noise:getFrequency returns noise frequency
Noise:getGradientPerturbAmp returns gradient perturb amplitude.
Noise:getInterp returns interpolation type
Noise:getNoiseType returns noise type
Noise:getSeed returns generator's seed
Noise:getTexture gets noise texture
Noise:getTileTexture gets tileable texture
Noise:gradientPerturb2D returns modified x, y
Noise:gradientPerturb3D returns modified x, y, z
Noise:gradientPerturbFractal2D returns modified x,y
Noise:gradientPerturbFractal3D returns modified x,y,z
Noise:noise gets noise value
Noise:noise2D gets 2D noise value
Noise:noise3D gets 3D noise value
Noise:reset resets noise parameters to default
Noise:setCellularDistance2Indices sets the 2 distance indicies used for distance2 return types
Noise:setCellularDistanceFunction 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
Noise:setCellularNoiseLookup noise used to calculate a cell value
Noise:setCellularReturnType what value does the cellular function returns from its calculations
Noise:setColorLookup sets color table used by "getTexture" and "getTileTexture"
Noise:setFractalGain the relative strength of noise from each layer when compared to the last
Noise:setFractalLacunarity the frequency multiplier between each octave
Noise:setFractalOctaves the amount of noise layers used to create the fractal
Noise:setFractalType used in all fractal noise generation
Noise:setFrequency affects how coarse the noise output is
Noise:setGradientPerturbAmp sets the maximum perturb distance from original location when using gradientPerturb()
Noise:setInterp changes the interpolation method used to smooth between noise values
Noise:setNoiseType sets the type of noise returned by noise()
Noise:setSeed using different seeds will cause the noise output to change
Noise:simplex4D gets 4D simplex noise value
Noise:whiteNoise2DInt gets integer 2D white noise value
Noise:whiteNoise3DInt gets integer 3D white noise value
Noise:whiteNoise4D gets 4D white noise value
Noise:whiteNoise4DInt gets integer 4D white noise value

Events

Constants

Noise.BILLOW
Noise.CELLULAR
Noise.CELL_VALUE
Noise.CUBIC
Noise.CUBIC_FRACTAL
Noise.DISTANCE
Noise.DISTANCE_2
Noise.DISTANCE_2_ADD
Noise.DISTANCE_2_DIV
Noise.DISTANCE_2_MUL
Noise.DISTANCE_2_SUB
Noise.EUCLIDEAN
Noise.FBM
Noise.HERMITE
Noise.LINEAR
Noise.MANHATTAN
Noise.NATURAL
Noise.NOISE_LOOKUP
Noise.PERLIN
Noise.PERLIN_FRACTAL
Noise.QUINTIC
Noise.RIGID_MULTI
Noise.SIMPLEX
Noise.SIMPLEX_FRACTAL
Noise.VALUE
Noise.VALUE_FRACTAL
Noise.WHITE_NOISE