Difference between revisions of "love.math.noise"
(Created page) |
m (→Examples: Some polish.) |
||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{newin|[[0.9.0]]|090|type=function}} | {{newin|[[0.9.0]]|090|type=function}} | ||
− | Generates a Simplex noise value in 1-4 dimensions. | + | Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments. |
[http://en.wikipedia.org/wiki/Simplex_noise Simplex noise] is closely related to [http://en.wikipedia.org/wiki/Perlin_noise Perlin noise]. It is widely used for procedural content generation. | [http://en.wikipedia.org/wiki/Simplex_noise Simplex noise] is closely related to [http://en.wikipedia.org/wiki/Perlin_noise Perlin noise]. It is widely used for procedural content generation. | ||
− | There are | + | There are many [http://libnoise.sourceforge.net/noisegen/ webpages] which discuss Perlin and Simplex noise in detail. |
+ | |||
+ | {{notice|The return value might be constant if only integer arguments are used. Avoid solely passing in integers, to get varying return values.}} | ||
== Function == | == Function == | ||
Generates Simplex noise from 1 dimension. | Generates Simplex noise from 1 dimension. | ||
Line 14: | Line 16: | ||
{{param|number|x|The number used to generate the noise value.}} | {{param|number|x|The number used to generate the noise value.}} | ||
=== Returns === | === Returns === | ||
− | {{param|number|value|The noise value in the range of [ | + | {{param|number|value|The noise value in the range of [0, 1].}} |
== Function == | == Function == | ||
Generates Simplex noise from 2 dimensions. | Generates Simplex noise from 2 dimensions. | ||
Line 25: | Line 27: | ||
{{param|number|y|The second value of the 2-dimensional vector used to generate the noise value.}} | {{param|number|y|The second value of the 2-dimensional vector used to generate the noise value.}} | ||
=== Returns === | === Returns === | ||
− | {{param|number|value|The noise value in the range of [ | + | {{param|number|value|The noise value in the range of [0, 1].}} |
== Function == | == Function == | ||
− | Generates Simplex noise from 3 dimensions. | + | Generates Perlin noise (Simplex noise in version [[0.9.2]] and older) from 3 dimensions. |
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 37: | Line 39: | ||
{{param|number|z|The third value of the 3-dimensional vector used to generate the noise value.}} | {{param|number|z|The third value of the 3-dimensional vector used to generate the noise value.}} | ||
=== Returns === | === Returns === | ||
− | {{param|number|value|The noise value in the range of [ | + | {{param|number|value|The noise value in the range of [0, 1].}} |
== Function == | == Function == | ||
− | Generates Simplex noise from 4 dimensions. | + | Generates Perlin noise (Simplex noise in version [[0.9.2]] and older) from 4 dimensions. |
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 50: | Line 52: | ||
{{param|number|w|The fourth value of the 4-dimensional vector used to generate the noise value.}} | {{param|number|w|The fourth value of the 4-dimensional vector used to generate the noise value.}} | ||
=== Returns === | === Returns === | ||
− | {{param|number|value|The noise value in the range of [-1, +1]. | + | {{param|number|value|The noise value in the range of [0, 1].}} |
+ | |||
+ | == Examples == | ||
+ | Fills a two-dimensional grid with simplex noise each time a key is pressed. | ||
+ | |||
+ | <source lang="lua"> | ||
+ | local grid = {} | ||
+ | |||
+ | local function generateNoiseGrid() | ||
+ | -- Fill each tile in our grid with noise. | ||
+ | local baseX = 10000 * love.math.random() | ||
+ | local baseY = 10000 * love.math.random() | ||
+ | for y = 1, 60 do | ||
+ | grid[y] = {} | ||
+ | for x = 1, 60 do | ||
+ | grid[y][x] = love.math.noise(baseX+.1*x, baseY+.2*y) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function love.load() | ||
+ | generateNoiseGrid() | ||
+ | end | ||
+ | function love.keypressed() | ||
+ | generateNoiseGrid() | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | local tileSize = 8 | ||
+ | for y = 1, #grid do | ||
+ | for x = 1, #grid[y] do | ||
+ | love.graphics.setColor(1, 1, 1, grid[y][x]) | ||
+ | love.graphics.rectangle("fill", x*tileSize, y*tileSize, tileSize-1, tileSize-1) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love.math]] | * [[parent::love.math]] |
Latest revision as of 19:20, 29 September 2022
Available since LÖVE 0.9.0 |
This function is not supported in earlier versions. |
Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.
Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.
There are many webpages which discuss Perlin and Simplex noise in detail.
The return value might be constant if only integer arguments are used. Avoid solely passing in integers, to get varying return values. |
Contents
Function
Generates Simplex noise from 1 dimension.
Synopsis
value = love.math.noise( x )
Arguments
number x
- The number used to generate the noise value.
Returns
number value
- The noise value in the range of [0, 1].
Function
Generates Simplex noise from 2 dimensions.
Synopsis
value = love.math.noise( x, y )
Arguments
number x
- The first value of the 2-dimensional vector used to generate the noise value.
number y
- The second value of the 2-dimensional vector used to generate the noise value.
Returns
number value
- The noise value in the range of [0, 1].
Function
Generates Perlin noise (Simplex noise in version 0.9.2 and older) from 3 dimensions.
Synopsis
value = love.math.noise( x, y, z )
Arguments
number x
- The first value of the 3-dimensional vector used to generate the noise value.
number y
- The second value of the 3-dimensional vector used to generate the noise value.
number z
- The third value of the 3-dimensional vector used to generate the noise value.
Returns
number value
- The noise value in the range of [0, 1].
Function
Generates Perlin noise (Simplex noise in version 0.9.2 and older) from 4 dimensions.
Synopsis
value = love.math.noise( x, y, z, w )
Arguments
number x
- The first value of the 4-dimensional vector used to generate the noise value.
number y
- The second value of the 4-dimensional vector used to generate the noise value.
number z
- The third value of the 4-dimensional vector used to generate the noise value.
number w
- The fourth value of the 4-dimensional vector used to generate the noise value.
Returns
number value
- The noise value in the range of [0, 1].
Examples
Fills a two-dimensional grid with simplex noise each time a key is pressed.
local grid = {}
local function generateNoiseGrid()
-- Fill each tile in our grid with noise.
local baseX = 10000 * love.math.random()
local baseY = 10000 * love.math.random()
for y = 1, 60 do
grid[y] = {}
for x = 1, 60 do
grid[y][x] = love.math.noise(baseX+.1*x, baseY+.2*y)
end
end
end
function love.load()
generateNoiseGrid()
end
function love.keypressed()
generateNoiseGrid()
end
function love.draw()
local tileSize = 8
for y = 1, #grid do
for x = 1, #grid[y] do
love.graphics.setColor(1, 1, 1, grid[y][x])
love.graphics.rectangle("fill", x*tileSize, y*tileSize, tileSize-1, tileSize-1)
end
end
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info