Giter Site home page Giter Site logo

loise's Introduction

Loise

A Noise-Generator for LFE

Introduction

This is a library, written in LFE, useful for generating Perlin and Simplex noise. Perlin noise is a computer-generated visual effect developed by Ken Perlin, who won an Academy Award for Technical Achievement for inventing it. It can be used to simulate elements from nature, and is especially useful in circumstances where computer memory is limited. (See the complete Perlin Wikipedia article.)

Simplex noise, on the other hand, is a method for constructing an n-dimensional noise function comparable to Perlin noise ("classic" noise) but with a lower computational overhead, especially in larger dimensions. Ken Perlin designed the algorithm in 2001 to address the limitations of his classic noise function, especially in higher dimensions. (See the complete Simplex Wikipedia article for more.)

Background

This is a port of the Racket noise-generator by jpverkamp to LFE.

Dependencies

This project assumes that you have rebar installed somwhere in your $PATH.

Eye Candy

The data generated with the perlin and simplex functions can be used to create images. Erlang is not a good language for image generation, however this library does provide some convenience functions for generating images.

Perlin

Below are 4 perlin noise images generated at 1x, 2x, 4x, and 8x, respectively.

These were generated with the following from the REPL:

    > (loise-img:create-perlin-image "perlin-1.png" 'png 256 128 1)
    ok
    > (loise-img:create-perlin-image "perlin-2.png" 'png 256 128 2)
    ok
    > (loise-img:create-perlin-image "perlin-4.png" 'png 256 128 4)
    ok
    > (loise-img:create-perlin-image "perlin-8.png" 'png 256 128 8)
    ok

Simplex

Below are 4 simplex noise images generated at 1x, 2x, 4x, and 8x, respectively.

These were generated with the following from the REPL:

    > (loise-img:create-simplex-image "simplex-1.png" 'png 256 128 1)
    ok
    > (loise-img:create-simplex-image "simplex-2.png" 'png 256 128 2)
    ok
    > (loise-img:create-simplex-image "simplex-4.png" 'png 256 128 4)
    ok
    > (loise-img:create-simplex-image "simplex-8.png" 'png 256 128 8)

Using Loise

The first place to start is ensuring that the code you obtained works as expected. To find out, run the unit tests:

    $ cd loise
    $ make check

From the REPL

Once everything is working, start up an LFE REPL:

    $ make shell

You can now use loise by itself, if you so desire. Here is some example usage:

    > (loise:perlin 3.14 1.59 2.65)
    -0.3772216257243449
    > (loise:simplex 0.1)
    0.4410072765
    > (loise:simplex 0.1 0.2)
    0.9410934374999996
    > (loise:simplex 0.1 0.2 0.9)
    -0.07602014100000003

Or, iterating over some values:

    > (set input
        (lists:map
          (lambda (x)
            (/ x 10))
          (lists:seq 0 9))))
    (0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9)
    > (lists:map
        (lambda (x)
          (loise:round
            (loise:perlin x)
          2))
        input)
    (0.0 0.11 0.23 0.37 0.46 0.5 0.46 0.37 0.23 0.11)

In a Module

    (defmodule mymodule
      (export all)
      (import
        (from loise
          (perlin 3)
          (simplex 3))))

    (def get-perlin-pie ()
      (perlin 3.14 1.59 2.65))

    (def get-simplex-pie ()
      (simplex 3.14 1.59 2.65))

loise's People

Contributors

oubiwann avatar

Watchers

James Cloos avatar

Forkers

lfex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.