Log In  


Cart #32443 | 2016-11-13 | Code ▽ | Embed ▽ | No License
11

Hi all,
I'm working on a space game with procedurally generated planets and thought others may benefit from the simplex noise functions I'm using.

This is ported the reference examples at:

http://staffwww.itn.liu.se/~stegu/simplexnoise/Noise.lua

The whitepaper can be found here:

http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

Feel free to use. Be aware that perlin noise (predecessor to simplex noise) has a patent. Here's an alternative: OpenSimplexNoise

Enjoy!

Edit: That patent is for simplex noise

11


"Be aware that perlin noise (predecessor to simplex noise) has a patent."

Other way around. The simplex noise algorithm is the one that is patented. (That's the patent you linked too) IANAL, but I think you only need to be worried about using it if you are making a commercial product.


Ah thanks for finding that. Yeah I agree it's probably not a problem if you aren't selling anything.


Awesome example, thank you! How could i tile it?


Pretty cool. Gonna borrow some of this. ;)

By the way, I notice you detest 1-based array accesses too. :) Here's a helper I use for declaring 0-based arrays without needing to have fixer code below the array:

Edit: disregard this solution, MBoffin offered an even better one in the next post.

function _0(a)
 for n=0,#a do a[n]=a[n+1] end
 return a
end

Note there appears to be an off-by-one overrun bug because I iterate 0..#a, but that's to make sure the final original entry is set to nil. Working as intended. :) Anyway...

Then, thanks to the features of the lua parser where it lets you skip parens in some function calls, you can say this:

powersof2 = _0{ 1, 2, 4, 8, 16, 32, 64, 128 }

> ?powersof2[0]
1
> ?powersof2[7]
128
> ?powersof2[8]
nil

Saves a bunch of extra work, to be sure.

(#%!@ing lua, mutter.)


1

Someone else pointed out to me that you can just do this to make your arrays 0-based:

powersof2={[0]=1,2,4,8,16}

Super simple.


Oh, that's even better. I always wanted to do that with "0=..." but it didn't work. I didn't know you could bracket a numeric literal to allow its use as a key.

Cheers!


For anyone who comes across this with a newer version of pico8, the graphics buffer (now?) doesn't get drawn to the screen until _draw returns. To see the animated 3D noise you need something like this:

offset = 47
function _update()
end

z = 0
function _draw()
    for x=0,32 do
        for y=0,32 do
            local i = Simplex3D(x*.05,y*.05,z*.05)
            i += 1
            -- i /= 4
            i *= #heatmap_colors/2
            i = flr(i+.5)
            pset(x+offset,y+offset,heatmap_colors[i])
        end
    end
    z = (z + 1) % 1024
end


[Please log in to post a comment]