Difference between revisions of "Noise"
(language stuff + reordering methods list) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
'''[https://github.com/Auburns/FastNoise FastNoise home page]''' and its documentation '''https://github.com/Auburns/FastNoise/wiki''' | '''[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 === | === Features === | ||
Line 23: | Line 28: | ||
=== Examples === | === Examples === | ||
'''2D noise''' | '''2D noise''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
require "FastNoise" | require "FastNoise" | ||
Line 47: | Line 52: | ||
end | end | ||
end | end | ||
− | </ | + | </syntaxhighlight> |
'''Grayscaled noise image''' | '''Grayscaled noise image''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
require "FastNoise" | require "FastNoise" | ||
Line 58: | Line 63: | ||
-- add it to scene | -- add it to scene | ||
stage:addChild(Bitmap.new(tex)) | stage:addChild(Bitmap.new(tex)) | ||
− | </ | + | </syntaxhighlight> |
'''Colored seamless noise image''' | '''Colored seamless noise image''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
require "FastNoise" | require "FastNoise" | ||
Line 89: | Line 94: | ||
-- add it to scene | -- add it to scene | ||
stage:addChild(Pixel.new(tex, 256,256)) | stage:addChild(Pixel.new(tex, 256,256)) | ||
− | </ | + | </syntaxhighlight> |
'''Some 3D examples [https://github.com/MultiPain/Gideros_examples here].''' | '''Some 3D examples [https://github.com/MultiPain/Gideros_examples here].''' | ||
Line 145: | Line 150: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | |||
=== Events === | === Events === | ||
=== Constants === | === Constants === |
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 |