1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. Ride into the sunset with the 32nd Modeling Contest.
    Dismiss Notice
  5. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  6. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  7. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger Viewer

perlinnoise-lua-1.0.1.w3x
Variables
Initialization
Initialization
Noise
Changelogs
Permutation Initialization
Noise
Octave Perlin
Implementation
Commands
Command Buttons
Generate Perlin Noise Button
Generate Octave Perlin Button
Disable Commands
Offset X Command
Offset Y Command
Octave Command
Persistence Command
Scale Command
Multiboard
Command Board
Command Board Update
Noise
Test Code
Lock Camera
Test
Generate
Generate Process
Variables

		
Name Type Is Array Initial Value
IsOctavePerlin boolean No
Map_Height integer No
Map_Width integer No
Octaves integer No
Offset_X real No
Offset_Y real No
Persistence real No
PerSquare_Height real No
PerSquare_Width real No
Requirement unit No
Result real No
Scale real No
World_Offset_X real No
World_Offset_Y real No
X integer No
Y integer No
Initialization
  Events
    Map initialization
  Conditions
  Actions
    Game - Turn the day/night cycle Off
    Game - Set the time of day to 12
    Visibility - Disable fog of war
    Visibility - Disable black mask
Lua v1.0.0
- Initial release

Lua v1.0.1
- Fixed wrong parameters for the function perlin1D (thanks to Drake53)
- Fixed wrong parameters for the function grad1D
In a table named Noise.permutation, each value in the array stores a random number ranges from 0 to 255.
These values will be used for the Perlin Noise.

You can disable/remove this trigger if you want to make your own custom permutation table.
Permutation Initialization
  Events
    Map initialization
  Conditions
  Actions
    Custom script: Noise.permutationInit ()
Perlin Noise Lua v1.0.1

Port by Glint
Perlin Noise by Kenneth Perlin, https://mrl.nyu.edu/~perlin/noise/
do
    Noise = {}

    Noise.version = "1.0.1"
    Noise.permutation = {}

    local function floor(value)
        local n = R2I(value)
        if value < 0. and value - n ~= 0. then n = n - 1 end
        return n
    end

    local function fade(t)
        return t * t * t * (t * (t * 6. - 15.) + 10.)
    end

    local function lerp(t, a, b)
        return a + t * (b -a)
    end

    local function grad1D(hash, x)
        local h = BlzBitAnd(hash, 15)
        return (BlzBitAnd(h, 1) == 0 and x or -x)
    end

    function Noise.perlin1D (x)
        local X = BlzBitAnd(floor(x), 255)
        x = x - floor(x)
        return lerp(fade(x), grad1D(Noise.permutation[X], x), grad1D(Noise.permutation[X + 1], x - 1)) * 2
    end

    local function grad2D(hash, x, y)
        local h = BlzBitAnd(hash, 15)
        local u, v = h < 8 and x or y, h < 4 and y or x
        return (BlzBitAnd(h, 1) == 0 and u or -u) + (BlzBitAnd(h, 2) == 0 and v or -v)
    end

    function Noise.perlin2D (x, y)
        local X, Y = BlzBitAnd(floor(x), 255), BlzBitAnd(floor(y), 255)
        x, y = x - floor(x), y - floor(y)
        local u, v = fade(x), fade(y)
        local A = Noise.permutation[X] + Y
        local B = Noise.permutation[X + 1] + Y
        local a1 = lerp(u, grad2D(Noise.permutation[A], x, y), grad2D(Noise.permutation[B], x - 1, y))
        local a2 = lerp(u, grad2D(Noise.permutation[A + 1], x, y - 1), grad2D(Noise.permutation[B + 1], x - 1, y - 1))
        return lerp(v, a1, a2)
    end

    local function grad3D(hash, x, y, z)
        local h = BlzBitAnd(hash, 15)
        local u, v = h < 8 and x or y, h < 4 and y or ((h == 12 or h == 14) and x or z)
        return (BlzBitAnd(h, 1) == 0 and u or -u) + (BlzBitAnd(h, 2) == 0 and v or -v)
    end

    function Noise.perlin3D (x, y, z)
        local X, Y, Z = BlzBitAnd(floor(x), 255), BlzBitAnd(floor(y), 255), BlzBitAnd(floor(z), 255)
        x, y, z = x - floor(x), y - floor(y), z - floor(z)
        local u, v, w = fade(x), fade(y), fade(z)
        local A = Noise.permutation[X] + Y
        local AA = Noise.permutation[A] + Z
        local AB = Noise.permutation[A + 1] + Z
        local B = Noise.permutation[X + 1] + Y
        local BA = Noise.permutation[B] + Z
        local BB = Noise.permutation[B + 1] + Z
        local a1 = lerp(u, grad3D(Noise.permutation[AA], x, y, z), grad3D(Noise.permutation[BA], x - 1, y, z))
        local a2 = lerp(u, grad3D(Noise.permutation[AB], x, y - 1, z), grad3D(Noise.permutation[BB], x - 1, y - 1, z))
        local b1 = lerp(u, grad3D(Noise.permutation[AA + 1], x, y, z - 1), grad3D(Noise.permutation[BA + 1], x - 1, y, z - 1))
        local b2 = lerp(u, grad3D(Noise.permutation[AB + 1], x, y - 1, z - 1), grad3D(Noise.permutation[BB + 1], x - 1, y - 1, z - 1))
        return lerp(w, lerp(v, a1, a2), lerp(v, b1, b2))
    end

    function Noise.permutationInit ()
        for i = 0, 255 do
            Noise.permutation[i] = GetRandomInt(0, 255)
            Noise.permutation[i + 256] = Noise.permutation[i]
        end
    end
end
Octave Perlin Lua v1.0.0

A plugin for the Noise library.

Port by Glint
Octave Perlin by Flafla2, https://flafla2.github.io/2014/08/09/perlinnoise.html
do
    function Noise.octavePerlin1D(x, octaves, persistence)
        local total, frequency, amplitude, maxValue = 0., 1., 1., 0.
        for i = 0, octaves - 1 do
            total = Noise.perlin1D(x * frequency) * amplitude
            maxValue = maxValue + amplitude
            amplitude = amplitude * persistence
            frequency = frequency * 2
        end
        return total / maxValue
    end

    function Noise.octavePerlin2D(x, y, octaves, persistence)
        local total, frequency, amplitude, maxValue = 0., 1., 1., 0.
        for i = 0, octaves - 1 do
            total = Noise.perlin2D(x * frequency, y * frequency) * amplitude
            maxValue = maxValue + amplitude
            amplitude = amplitude * persistence
            frequency = frequency * 2
        end
        return total / maxValue
    end

    function Noise.octavePerlin3D(x, y, z, octaves, persistence)
        local total, frequency, amplitude, maxValue = 0., 1., 1., 0.
        for i = 0, octaves - 1 do
            total = Noise.perlin3D(x * frequency, y * frequency, z * frequency) * amplitude
            maxValue = maxValue + amplitude
            amplitude = amplitude * persistence
            frequency = frequency * 2
        end
        return total / maxValue
    end
end
Command Buttons
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    Or - Any (Conditions) are true
      Conditions
        (Ability being cast) Equal to Set Offset X
        (Ability being cast) Equal to Set Offset Y
        (Ability being cast) Equal to Set Persistence
        (Ability being cast) Equal to Set Octave
        (Ability being cast) Equal to Set Scale
  Actions
    Trigger - Run Disable_Commands <gen> (ignoring conditions)
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Ability being cast) Equal to Set Offset X
      Then - Actions
        Trigger - Turn on Offset_X_Command <gen>
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Ability being cast) Equal to Set Offset Y
      Then - Actions
        Trigger - Turn on Offset_Y_Command <gen>
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Ability being cast) Equal to Set Persistence
      Then - Actions
        Trigger - Turn on Persistence_Command <gen>
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Ability being cast) Equal to Set Octave
      Then - Actions
        Trigger - Turn on Octave_Command <gen>
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Ability being cast) Equal to Set Scale
      Then - Actions
        Trigger - Turn on Scale_Command <gen>
      Else - Actions
Generate Perlin Noise Button
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to Generate Perlin Noise
  Actions
    Set VariableSet IsOctavePerlin = False
    Trigger - Run Generate <gen> (ignoring conditions)
Generate Octave Perlin Button
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to Generate Octave Perlin
  Actions
    Set VariableSet IsOctavePerlin = True
    Trigger - Run Generate <gen> (ignoring conditions)
Disable Commands
  Events
  Conditions
  Actions
    Trigger - Turn off Octave_Command <gen>
    Trigger - Turn off Offset_X_Command <gen>
    Trigger - Turn off Offset_Y_Command <gen>
    Trigger - Turn off Persistence_Command <gen>
    Trigger - Turn off Scale_Command <gen>
Offset X Command
  Events
    Player - Player 1 (Red) types a chat message containing (stringnoformat) as A substring
  Conditions
  Actions
    Set VariableSet Offset_X = (Real((Entered chat string)))
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Offset Y Command
  Events
    Player - Player 1 (Red) types a chat message containing (stringnoformat) as A substring
  Conditions
  Actions
    Set VariableSet Offset_Y = (Real((Entered chat string)))
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Octave Command
  Events
    Player - Player 1 (Red) types a chat message containing (stringnoformat) as A substring
  Conditions
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Integer((Entered chat string))) Less than 16
        (Integer((Entered chat string))) Greater than 0
      Then - Actions
        Set VariableSet Octaves = (Integer((Entered chat string)))
        Trigger - Run Command_Board_Update <gen> (ignoring conditions)
      Else - Actions
Persistence Command
  Events
    Player - Player 1 (Red) types a chat message containing (stringnoformat) as A substring
  Conditions
  Actions
    Set VariableSet Persistence = (Real((Entered chat string)))
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Scale Command
  Events
    Player - Player 1 (Red) types a chat message containing (stringnoformat) as A substring
  Conditions
  Actions
    Set VariableSet Scale = (Real((Entered chat string)))
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Command Board
  Events
    Time - Elapsed game time is 0.00 seconds
  Conditions
  Actions
    Multiboard - Create a multiboard with 2 columns and 6 rows, titled Information.
    Multiboard - Set the display style for (Last created multiboard) item in column 0, row 0 to Show text and Hide icons
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 1 to Offset X
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 2 to Offset Y
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 3 to Octaves
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 4 to Persistence
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 5 to Scale
    Multiboard - Set the text for (Last created multiboard) item in column 1, row 6 to Generating
    Multiboard - Set the width for (Last created multiboard) item in column 1, row 0 to 10.00% of the total screen width
    Multiboard - Show (Last created multiboard)
    Multiboard - Maximize (Last created multiboard)
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Command Board Update
  Events
  Conditions
  Actions
    Multiboard - Set the text for (Last created multiboard) item in column 2, row 1 to (String(Offset_X))
    Multiboard - Set the text for (Last created multiboard) item in column 2, row 2 to (String(Offset_Y))
    Multiboard - Set the text for (Last created multiboard) item in column 2, row 3 to (String(Octaves))
    Multiboard - Set the text for (Last created multiboard) item in column 2, row 4 to (String(Persistence))
    Multiboard - Set the text for (Last created multiboard) item in column 2, row 5 to (String(Scale))
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Generate_Process <gen> is on) Equal to True
      Then - Actions
        Multiboard - Set the text for (Last created multiboard) item in column 2, row 6 to |cffff0000Yes|r
      Else - Actions
        Multiboard - Set the text for (Last created multiboard) item in column 2, row 6 to |cff00ff00No|r
do
    function GetResult ()
        local x = (udg_Offset_X + udg_World_Offset_X + I2R(udg_X)) * udg_Scale
        local y = (udg_Offset_Y + udg_World_Offset_Y + I2R(udg_Y)) * udg_Scale
        if udg_IsOctavePerlin then
            udg_Result = Noise.octavePerlin2D(x, y, udg_Octaves, udg_Persistence)
        else
            udg_Result = Noise.perlin2D(x, y)
        end
        x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
        y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
        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
end
Lock Camera
  Events
    Time - Every 0.03 seconds of game time
  Conditions
  Actions
    Camera - Set Player 1 (Red)'s camera Distance to target to 3500.00 over 0 seconds
    Camera - Set Player 1 (Red)'s camera Angle of attack to 270.00 over 0 seconds
    Camera - Set Player 1 (Red)'s camera Rotation to 90.00 over 0 seconds
    Camera - Set Player 1 (Red)'s camera Field of view to 70.00 over 0 seconds
    Camera - Set Player 1 (Red)'s camera Far Z to 10000.00 over 0 seconds
Test
  Events
    Time - Elapsed game time is 0.00 seconds
  Conditions
  Actions
    Set VariableSet Map_Width = 32
    Set VariableSet Map_Height = 32
    Set VariableSet PerSquare_Width = 128.00
    Set VariableSet PerSquare_Height = 128.00
    Set VariableSet World_Offset_X = (Min X of (Entire map))
    Set VariableSet World_Offset_Y = (Max Y of (Entire map))
    Set VariableSet Offset_X = 0.00
    Set VariableSet Offset_Y = 0.00
    Set VariableSet Octaves = 4
    Set VariableSet Persistence = 2.00
    Set VariableSet Scale = 0.10
    Set VariableSet Requirement = Not Generating 0002 <gen>
    Selection - Select Noise Controls 0001 <gen> for Player 1 (Red)
    Trigger - Run Command_Board_Update <gen> (ignoring conditions)
Generate
  Events
  Conditions
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Generate_Process <gen> is on) Equal to True
      Then - Actions
        Cinematic - Clear the screen of text messages for (All players).
        Game - Display to (All players) the text: Still processing...
        Skip remaining actions
      Else - Actions
        Set VariableSet X = 0
        Set VariableSet Y = 0
        Cinematic - Clear the screen of text messages for (All players).
        Game - Display to (All players) the text: Processing...
        Trigger - Turn on Generate_Process <gen>
        Trigger - Run Command_Board_Update <gen> (ignoring conditions)
        Unit - Remove Requirement from the game
Generate Process
  Events
    Time - Every 0.03 seconds of game time
  Conditions
  Actions
    For each (Integer X) from 0 to (Map_Width - 1), do (Actions)
      Loop - Actions
        Custom script: GetResult()
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Y Greater than (Map_Height - 1)
      Then - Actions
        Trigger - Turn off (This trigger)
        Cinematic - Clear the screen of text messages for (All players).
        Game - Display to (All players) the text: Process complete!
        Trigger - Run Command_Board_Update <gen> (ignoring conditions)
        Custom script: udg_Requirement = CreateUnit(Player(0), FourCC("h001"), 0, 0, 270)
      Else - Actions
        Set VariableSet Y = (Y + 1)