mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
Add infrared noise
This commit is contained in:
parent
8891c47e98
commit
03038689e2
4 changed files with 42 additions and 3 deletions
|
@ -520,6 +520,7 @@ Algorithm | Description
|
||||||
`sin` | A sine wave created with `math.sin()`.
|
`sin` | A sine wave created with `math.sin()`.
|
||||||
`white` | Random white noise.
|
`white` | Random white noise.
|
||||||
`red` | Red noise - has a lower frequency than white noise.
|
`red` | Red noise - has a lower frequency than white noise.
|
||||||
|
`infrared` | Even smoother than red noise. Tends to also be quite flat unless you use a slightly higher `apply` value (e.g. `20`).
|
||||||
|
|
||||||
When specifying algorithm names, the `algorithm` parameter name is optional. For example, the following are both equivalent:
|
When specifying algorithm names, the `algorithm` parameter name is optional. For example, the following are both equivalent:
|
||||||
|
|
||||||
|
|
35
worldeditadditions/lib/noise/engines/infrared.lua
Normal file
35
worldeditadditions/lib/noise/engines/infrared.lua
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
local wea = worldeditadditions
|
||||||
|
|
||||||
|
local White = dofile(wea.modpath.."/lib/noise/engines/white.lua")
|
||||||
|
|
||||||
|
local Infrared = {}
|
||||||
|
Infrared.__index = Infrared
|
||||||
|
|
||||||
|
|
||||||
|
function Infrared.new(seed)
|
||||||
|
local result = {
|
||||||
|
seed = seed or math.random(),
|
||||||
|
white = White.new(seed),
|
||||||
|
window = 2
|
||||||
|
}
|
||||||
|
setmetatable(result, Infrared)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function Infrared:noise( x, y, z )
|
||||||
|
local values = { }
|
||||||
|
for nx=x-self.window,x+self.window do
|
||||||
|
for ny=y-self.window,y+self.window do
|
||||||
|
for nz=z-self.window,z+self.window do
|
||||||
|
table.insert(values, self.white:noise(nx, ny, nz))
|
||||||
|
|
||||||
|
print("DEBUG nx", nx, "ny", ny, "nz", nz, "value", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i,value in ipairs(values) do
|
||||||
|
end
|
||||||
|
return wea.average(values)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Infrared
|
|
@ -2,10 +2,11 @@ local wea = worldeditadditions
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
available = { "perlin", "sin", "white", "red" },
|
available = { "perlin", "sin", "white", "red", "infrared" },
|
||||||
Perlin = dofile(wea.modpath.."/lib/noise/engines/perlin.lua"),
|
Perlin = dofile(wea.modpath.."/lib/noise/engines/perlin.lua"),
|
||||||
Sin = dofile(wea.modpath.."/lib/noise/engines/sin.lua"),
|
Sin = dofile(wea.modpath.."/lib/noise/engines/sin.lua"),
|
||||||
White = dofile(wea.modpath.."/lib/noise/engines/white.lua"),
|
White = dofile(wea.modpath.."/lib/noise/engines/white.lua"),
|
||||||
Red = dofile(wea.modpath.."/lib/noise/engines/red.lua")
|
Red = dofile(wea.modpath.."/lib/noise/engines/red.lua"),
|
||||||
|
Infrared = dofile(wea.modpath.."/lib/noise/engines/infrared.lua")
|
||||||
-- TODO: Follow https://www.redblobgames.com/articles/noise/introduction.html and implement different colours of noise (*especially* red and pink noise)
|
-- TODO: Follow https://www.redblobgames.com/articles/noise/introduction.html and implement different colours of noise (*especially* red and pink noise)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ function worldeditadditions.noise.make_2d(size, start_pos, params)
|
||||||
generator = wea.noise.engines.White.new()
|
generator = wea.noise.engines.White.new()
|
||||||
elseif layer.algorithm == "red" then
|
elseif layer.algorithm == "red" then
|
||||||
generator = wea.noise.engines.Red.new()
|
generator = wea.noise.engines.Red.new()
|
||||||
|
elseif layer.algorithm == "infrared" then
|
||||||
|
generator = wea.noise.engines.Infrared.new()
|
||||||
else -- We don't have any other generators just yet
|
else -- We don't have any other generators just yet
|
||||||
return false, "Error: Unknown noise algorithm '"..tostring(layer.algorithm).."' in layer "..layer_i.." of "..#params.." (available algorithms: "..table.concat(wea.noise.engines.available, ", ")..")."
|
return false, "Error: Unknown noise algorithm '"..tostring(layer.algorithm).."' in layer "..layer_i.." of "..#params.." (available algorithms: "..table.concat(wea.noise.engines.available, ", ")..")."
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue