Difference between revisions of "Noise"

From GiderosMobile
Line 102: Line 102:
 
=== <translate>Methods</translate> ===
 
=== <translate>Methods</translate> ===
 
[[Special:MyLanguage/Noise.new|Noise.new]] ''<translate>creates a new Noise object</translate>''<br/><!-- GIDEROSMTD:Noise.new() creates a new Noise object -->
 
[[Special:MyLanguage/Noise.new|Noise.new]] ''<translate>creates a new Noise object</translate>''<br/><!-- GIDEROSMTD:Noise.new() creates a new Noise object -->
 +
 +
[[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:reset|Noise:reset]] ''<translate>reset noise parameters to default</translate>''<br/><!-- GIDEROSMTD:FastNoise:reset() reset noise parameters to default -->
 +
 +
[[Special:MyLanguage/Noise:setColorLookup|Noise:setColorLookup]] ''<translate>set color table used by "getTexture" and "getTileTexture"</translate>''<br/><!-- GIDEROSMTD:Noise:setColorLookup(table) set color table used by "getTexture" and "getTileTexture" -->
 +
[[Special:MyLanguage/Noise:getTexture|Noise:getTexture]] ''<translate>generate texture</translate>''<br/><!-- GIDEROSMTD:Noise:getTexture(width, height [, filtering, textureData]) generate texture -->
 +
[[Special:MyLanguage/Noise:getTileTexture|Noise:getTileTexture]] ''<translate>generate tileable texture</translate>''<br/><!-- GIDEROSMTD:Noise:getTileTexture(width, height [, filtering, textureData]) generate tileable texture -->
  
 
[[Special:MyLanguage/Noise:getCellularDistanceFunction|Noise:getCellularDistanceFunction]] ''<translate>returns distance function type</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularDistanceFunction() returns distance function type -->
 
[[Special:MyLanguage/Noise:getCellularDistanceFunction|Noise:getCellularDistanceFunction]] ''<translate>returns distance function type</translate>''<br/><!-- GIDEROSMTD:Noise:getCellularDistanceFunction() returns distance function type -->
Line 120: Line 129:
 
[[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: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: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: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:reset|Noise:reset]] ''<translate>reset noise parameters to default</translate>''<br/><!-- GIDEROSMTD:FastNoise:reset() reset noise parameters to default -->
 
 
[[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 -->
 
[[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 -->
 
[[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 -->
 
[[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 -->
Line 145: Line 150:
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 +
 
=== <translate>Events</translate> ===
 
=== <translate>Events</translate> ===
 
=== <translate>Constants</translate> ===
 
=== <translate>Constants</translate> ===

Revision as of 11:33, 3 July 2020

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

Orignal documentation: https://github.com/Auburns/FastNoise/wiki

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

Example 1.

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

Example 2. 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))

Example 3. 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))

See 3D examples here
Particles flow field

Notes

Methods

Noise.new creates a new Noise object

Noise:noise get noise value
Noise:noise2D get 2D noise value
Noise:noise3D get 3D noise value
Noise:reset reset noise parameters to default

Noise:setColorLookup set color table used by "getTexture" and "getTileTexture"
Noise:getTexture generate texture
Noise:getTileTexture generate tileable texture

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 return 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: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: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 return from its calculations
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 get 4D simplex noise value
Noise:whiteNoise2DInt get integer 2D white noise value
Noise:whiteNoise3DInt get integer 3D white noise value
Noise:whiteNoise4D get 4D white noise value
Noise:whiteNoise4DInt get 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