- Joined
- May 9, 2014
- Messages
- 1,820
This … is quite an unusual resource in the Spells section. An algorithm of sorts that normally doesn't pertain to the usual ideas centered around spells. I'll reserve judgment to @Dr Super Good and @Frotty.
// Constants functions
constant function NoiseVersion takes nothing returns string
// Interface functions (pre-1.29 only)
function NoiseBitAnd takes integer x, integer y returns integer
function NoiseBitXor takes integer x, integer y returns integer
// GetRandomIntInterface arguments and return (GUI Variables)
integer NoiseGetRandomIntLow
integer NoiseGetRandomIntHigh
integer NoiseGetRandomIntReturn
// Noise functions
function PerlinNoise1D takes real x returns real
function PerlinNoise2D takes real x, real y returns real
function PerlinNoise3D takes real x, real y, real z returns real
function OpenSimplex2D takes real x, real y returns real
// Permutation Generation functions
function GeneratePermutationTableCustom takes code GetRandomIntInterface returns nothing
function GeneratePermutationTable takes nothing returns nothing
// Initialization
function InitNoise takes nothing returns nothing
struct Noise extends array
// Constants
readonly static string version
// GetRandomIntInterface arguments and return
static method operator getRandomIntLow takes nothing returns integer
static method operator getRandomIntHigh takes nothing returns integer
static method operator getRandomIntReturn= takes integer value returns nothing
// Noise static methods
static method perlin1D takes real x returns real
static method perlin2D takes real x, real y returns real
static method perlin3D takes real x, real y, real z returns real
static method openSimplex2D takes real x, real y returns real
// Permutation Generation static methods
static method generatePermutationTableCustom takes code GetRandomIntInterface returns nothing
static method generatePermutationTable takes nothing returns nothing
// Initialization
static method initialize takes nothing returns nothing
// Constants
Noise.version
// Noise functions
function Noise.perlin1D(x) returns number
function Noise.perlin2D(x, y) returns number
function Noise.perlin3D(x, y, z) returns number
function Noise.openSimplex2D(x, y) returns number
// Permutation Generation functions
function Noise.generatePermutationTable (getRandomIntInterface)
// Initialization
function InitNoise ()
class Noise
// Constants
constant string getVersion
// Noise static methods
static function perlin (real x) returns real
static function perlin (vec2) returns real
static function perlin (vec3) returns real
static function openSimplex (vec2) returns real
// Permutation Generation static methods
static function generateRandomPermutation(NoiseRandom random)
static function generateRandomPermutation()
// Initialization
static function initialize()
grill install https://github.com/eGlint/wurstNoiselib
function GetResult takes nothing returns nothing
local real x = (udg_Offset_X + I2R(udg_X)) * udg_Scale
local real y = (udg_Offset_Y + I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
set udg_Result = OpenSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
set udg_Result = OctavePerlin2D(x, y, udg_Octaves, udg_Persistence)
else
set udg_Result = PerlinNoise2D(x, y) * udg_Amplitude
endif
set x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
set y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
set udg_Result = udg_Result * -1
endif
if udg_Result < .1 then
call SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
elseif udg_Result < .2 then
call SetTerrainType(x, y, 'Ldro', 0, 1, 0)
elseif udg_Result < .25 then
call SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
elseif udg_Result < .5 then
call SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
call SetTerrainType(x, y, 'Lrok', 0, 1, 0)
endif
endfunction
function GetResult takes nothing returns nothing
local real x = (udg_Offset_X + I2R(udg_X)) * udg_Scale
local real y = (udg_Offset_Y+ I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
set udg_Result = Noise.openSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
set udg_Result = Noise.octavePerlin2D(x, y, udg_Octaves, udg_Persistence)
else
set udg_Result = Noise.perlin2D(x, y) * udg_Amplitude
endif
set x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
set y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
set udg_Result = udg_Result * -1
endif
if udg_Result < .1 then
call SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
elseif udg_Result < .2 then
call SetTerrainType(x, y, 'Ldro', 0, 1, 0)
elseif udg_Result < .25 then
call SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
elseif udg_Result < .5 then
call SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
call SetTerrainType(x, y, 'Lrok', 0, 1, 0)
endif
endfunction
function GetResult ()
local x = (udg_Offset_X + I2R(udg_X)) * udg_Scale
local y = (udg_Offset_Y + I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
udg_Result = Noise.openSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
udg_Result = Noise.octavePerlin2D(x, y,udg_Octaves, udg_Persistence)
else
udg_Result = Noise.perlin2D(x, y) * udg_Amplitude
end
x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
udg_Result = udg_Result * -1.
end
if udg_Result < .1 then
SetTerrainType(x, y, FourCC("Ldrt"), 0, 1, 0)
elseif udg_Result < .2 then
SetTerrainType(x, y, FourCC("Ldro"), 0, 1, 0)
elseif udg_Result < .25 then
SetTerrainType(x, y, FourCC("Lgrs"), 0, 1, 0)
elseif udg_Result < .5 then
SetTerrainType(x, y, FourCC("Ldrg"), 0, 1, 0)
else
SetTerrainType(x, y, FourCC("Lrok"), 0, 1, 0)
end
end
function getResult()
real x
real y
let noisePos = vec2((udg_Offset_X + udg_X) * udg_Scale,
(udg_Offset_Y + udg_Y) * udg_Scale)
if udg_IsOpenSimplex
udg_Result = Noise.openSimplex(noisePos) * udg_Amplitude
else if udg_IsOctavePerlin
udg_Result = octavePerlin(noisePos, udg_Octaves, udg_Persistence)
else
udg_Result = Noise.perlin(noisePos) * udg_Amplitude
x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
y = udg_World_Offset_Y + -(udg_Y * udg_PerSquare_Height)
if udg_Result < 0
udg_Result *= -1
if udg_Result < .1
SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
else if udg_Result < .2
SetTerrainType(x, y, 'Ldro', 0, 1, 0)
else if udg_Result < .25
SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
else if udg_Result < .5
SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
SetTerrainType(x, y, 'Lrok', 0, 1, 0)
[NativeLuaMemberContainer]
internal static class Noise
{
[NativeLuaMember("Noise.perlin1D")]
public static extern float Perlin(float x);
[NativeLuaMember("Noise.perlin2D")]
public static extern float Perlin(float x, float y);
[NativeLuaMember("Noise.perlin3D")]
public static extern float Perlin(float x, float y, float z);
[NativeLuaMember("Noise.openSimplex2D")]
public static extern float OpenSimplex(float x, float y);
[NativeLuaMember("Noise.initialize")]
public static extern void Initialize();
}