I've built a small project that tries to generate a 10x10 grid of booleans. When you press , it toggles between using math.random to generate the booleans, and gfx.perlin. But from what I can tell, the way I'm calling the perlin method always generates a value of 0.5, resulting in a really really boring grid of like, no noise.
The full project's attached, but here's how I'm calling it:
function generatePerlinGrid()
for row = 1, size, 1 do
for col = 1, size, 1 do
local value = gfx.perlin(col, row, 1, 0)
grid[col][row] = (value < 0.5)
end
end
end
Do I need to seed this somewhere? Any idea what I'm doing wrong?
Depending on how the noise generation algorithm is implemented, it might occur that you'd get the same value on round coordinates like you do in your snippet.
In your linked project, I got something working more like you'd expect by altering the coordinates before passing them to the perlin function, in my case by dividing col and row by respectively 3.2 and 5.4.
function generatePerlinGrid()
for row = 1, size, 1 do
for col = 1, size, 1 do
local noise_x = col / 3.2
local noise_y = row / 5.4
local value = gfx.perlin(noise_x, noise_y, 1, 0)
grid[col][row] = (value < 0.5)
end
end
end
Feel free to experiment with any kind of coordinate transformation you can think of to see how they change the result.
Addendum: I don't know yet if gfx.noise can be seeded, I have yet to experiment with the Lua API, but in the meantime you can issue a random translation to make up for the possible lack of seed.
That totally worked. What made you choose those divisors? Or did you just fiddle with things until they looked good.
You're welcome. I just used random factors just to have noise coordinates that don't fall into integer coordinates, it could have been instead a multiplication or even an offset. This should be the same with the Perlin Array function Matt suggested to use (which I didn't know about until he suggested it, I mostly delved into the C API, my bad). Try to fiddle with both the coordinates and the step values to see how they work.
I also found this image from the perlin noise wiki:
helpful to understand why it's always 0.5 at the integer values.
And this generator useful to see how various params tweak things: http://kitfox.com/projects/perlinNoiseMaker/
although it'd be interesting to translate this into Playdate code.
OK, so, I didn't exactly recreate that noise maker, but I definitely took inspiration from it to make a tool to generate noise using the perlin APIs on Playdate.
Cross linking to that post in case folks find this thread first: Perlin Noise explorer