Lovenoise

A Noise Library for LOVE

Download .zip Download .tar.gz View on GitHub

LoveNoise - a Love Noise library

LoveNoise is a wrapper library for LOVE's noise functions.

Syntax is based on Libnoise, a noise library written in C++.

Currently only includes Simplex noise as its core noise function. Used for all the other types of noise.

Installation

The lovenoise.lua and presets.lua files, the lovenoise and the third-party folder should be dropped into an existing project. After that, add this line ontop of your files that uses lovenoise.

local lovenoise = require "lovenoise"

Examples

Creating a 3 new modules and getting the final value:

-- Require lovenoise first
local lovenoise = require 'lovenoise'

-- Reference lovenoise.modules (optional)
local modules = lovenoise.modules

-- Creating a new Simplex module
local simplexMod = modules.Simplex:new()

-- Setting its properties (see doc)
simplexMod:setFrequency(0.01)
simplexMod:setSeed(math.random()*600)

-- Creating a new RidgedMulti module with 4 octaves (with condensed property setters)
local ridgedMod = modules.RidgedMulti:new(4):setFrequency(0.01):setSeed(math.random()*600)

-- Creating a new Min module with the previous modules as its sources
local minMod = modules.Min:new(ridgedMod, simplexMod)

-- Getting a value at location [5, 6]
local val = modules.Min:getValue(5, 6)

Use for other frameworks

You can use this library for other frameworks, just change the lnoise function in line 2 of the presets.lua file to the noise function of your choice (currently uses LOVE's Simplex Noise generator.)

Documentation

Module superclass

Functions:

  • :new() -- Creates a new module (usually overridden by subclass.)
  • :addSource(index, source) -- Adds a source module at a specified index. Indices are one-based.
  • :getValue(x, [y, z, w]) -- Gets the value of the module at a specified location (overridden by subclass.) Values usually range from -1 to 1.

NoiseModule superclass

Functions:

  • :new(seed, frequency) -- Creates a new noise module with a specified seed and frequency (overridden by subclass.)
  • :getValue(x, [y, z, w]) -- Gets the value of the module at a specified location (overridden by subclass.) Values usually range from -1 to 1.
  • :setSeed(seed) -- Sets the seed of the noise module.
  • :setFrequency(frequency) -- Sets the frequency of the noise module. Positive values equal or larger than 1 gives pseudo-random white noise while positive values less than 1 gives smoother noise values.

Fractal module

Inherits from NoiseModule.

Functions:

  • :new(octaves, lacunarity, persistence, seed, frequency) -- Creates a new Fractal module with a specified number of octaves, lacunarity, persistence, seed and frequency.
  • :setOctaves(octaves) -- Sets the amount of octaves. Higher values means more detailed noise.
  • :setLacunarity(lacunarity) -- Sets the lacunarity factor (from 0 to 1.) Determines how quickly the frequency increases.
  • :setPersistence(persistence) -- Sets the persistence factor (from 0 to 1.) Determines how quickly the amplitude diminishes.

RidgedMulti module

Inherits from Fractal.

Generates Ridged Fractal noise.

Billow module

Inherits from Fractal.

Generates Billow noise.

Add module

Inherits from Module.

Functions:

  • :new(source1, source2) -- Creates a new Add module with the specified two sources.
  • :getValue(x, [y, z, w]) -- Gets the combined values of the two sources at the specified location.

Max module

Inherits from Module. Similar to Add but returns the maximum value of the two sources.

Min module

Inherits from Module. Similar to Add but returns the minimum value of the two sources.

Multiply module

Inherits from Module. Similar to Add but returns the multiplied values of the two sources.

Power module

Inherits from Module. Similar to Add but returns the value of the first source raised to the value of the second source.

Invert module

Inherits from Module.

Functions

  • new(source) -- Creates a new Invert module with specified source.
  • getValue(x, [y, z, w]) -- Returns the inverted value of the source.

License

MIT LICENSE

Copyright (c) 2014 Phoenix Enero

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.