Web
Analytics
Log In  
11

Cabledragon was talking to me about perlin and simplex noise generation, and we were looking at various web pages on the subject. One of them was a novel implementation of a simplex noise generator, written by a game dev who did not wish to be subject to Perlin's patent on his own version of simplex noise:

http://uniblock.tumblr.com/post/97868843242/noise

With a public-domain javascript implementation of 2D, 3D, and 4D noise here:

https://gist.github.com/kdotjpg/b1270127455a94ac5d19

The 3D and especially the 4D code is rather long and spaghettilike, though I suspect for good reason, but I noticed the 2D code was not too bad, really, so I took a pair of Lua shears to it and made it fit on our little platform.

It performs pretty well. It looks good, and while you can't efficiently use it to set every pixel on your screen, it's quite adequate for caching your terrain at app launch, or even for real-time generation of the area immediately around you, if you can be somewhat economical with how many times you sample the noise.

Note that, as mentioned in the code, the shell I wrote around this adaptation isn't particularly useful. It's just a custom-made and optimized-to-the-point-of-being-ugly viewer for the noise generator.

The generator code is on the second tab, and that's what you'll want to look at if you want to use it yourself.

Usage of the generator code is simple:

os2d_noise(seed)

  • Initializes the noise generator with the given seed. Different seeds produce different noise patterns.

os2d_eval(x,y)

  • Evaluate the noise pattern at x,y, returning a fraction between -1 and +1.

Edit: It's probably worth noting that the noise repeats, cleanly, at the length of the seed array generated by os2d_noise(). For larger fields, you'd want to increase the size of the array and accommodate that by adjusting the index masking that's done when referencing the array. I might actually make this configurable at some point.


Here's the demo. Use ⬅️/➡️ to change the seed, ⬆️/⬇️ to change zoom, ❎ to cycle colors, 🅾️ for help. Note that it's slowly caching the zoomed images in the background, so zooming in quickly might produce some tearing at first.

Cart [#52171#] | Copy | Code | 2018-04-30 | Link
11

V1.1: Turned off color cycling due to a complaint and put a toggle on X.

V1.2: Caching indicator, because communicating with the 0 users who run this is important!

P#52128 2018-04-29 05:16 ( Edited 2018-05-11 13:41)


:: More
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-06-23 04:03 | 0.255s | 1835k | Q:17