lmas / opensimplex

This repo has been migrated to https://code.larus.se/lmas/opensimplex
MIT License
241 stars 29 forks source link

Question about noiseXarray behavior #23

Closed EmmaSimon closed 2 years ago

EmmaSimon commented 2 years ago

Hello! I'm trying to use the array functions to get 2d noise, but the output is unexpected. I'm providing the x and y arrays, say for a 3x3 grid, x = [0, 1, 2], y = [0, 1, 2] and I would expect that it would return a 2D array of the noise, so that I can then access coordinates with noise_result[x][y], but instead it returns a 1D array the length of x. Do I need to manually insert each x/y combination into the input arrays like x = [0, 1, 2, 0, 1, 2, 0, 1, 2], y = [0, 0, 0, 1, 1, 1, 2, 2, 2], then do something like noise_result[x * x_size + y]?

lmas commented 2 years ago

Hiya, the returned array is a numpy array. It might have a shortcut func that you could use? The array funcs I provide really is for Numpy usage, not plain python arrays, so I recommend checking the Numpy docs for some usage examples.

noise_result[x * x_size + y] This looks alright so if you don't want to dive into numpy it should work.

Updating the docs and provide better usage notes for those array funcs are on my TODO, I'm just too busy with exams and a new semester at the moment.

EmmaSimon commented 2 years ago

Thanks for responding! No worries about response or update delays, good luck with your classes. The arrays that I'm providing are numpy arrays, the examples were just to demonstrate the data. I'm pretty new to numpy, but I'd expect two 1D inputs to result in a 2D output, not a 1D output.

Looking at this numpy perlin noise library, it has an API where you just provide the array shape, and some parameters about the noise, and it generates output in that shape, rather than taking explicit inputs.

My expectations are mostly based on the pnoise library, which has a more similar API of accepting x, y, z ndarrays:

Perlin noise will be computed for each combination of each of the input argument and returns them in a Numpy array of shape (len(x), len(y), len(z))

https://github.com/plottertools/pnoise/blob/main/pnoise/pnoise.py#L55-L61

lmas commented 2 years ago

Oh boy you're right! I just remembered seeing numpy array shapes somewhere else. Feels like an obvious expectation now that you mention it!

Thanks a lot for your comments and example, I'll definitely have my funcs updated to match this behaviour.

-- Alex

On Tue, 18 Jan 2022, at 19:32, Emma Simon wrote:

Thanks for responding! No worries about response or update delays, good luck with your classes. The arrays that I'm providing are numpy arrays, the examples were just to demonstrate the data. I'm pretty new to numpy, but I'd expect two 1D inputs to result in a 2D output, not a 1D output.

Looking at this numpy perlin noise https://github.com/pvigier/perlin-numpy library, it has an API where you just provide the array shape, and some parameters about the noise, and it generates output in that shape, rather than taking explicit inputs.

My expectations are mostly based on the pnoise library, which has a more similar API of accepting x, y, z ndarrays:

Perlin noise will be computed for each combination of each of the input argument and returns them in a Numpy array of shape (len(x), len(y), len(z))

https://github.com/plottertools/pnoise/blob/main/pnoise/pnoise.py#L55-L61

— Reply to this email directly, view it on GitHub https://github.com/lmas/opensimplex/issues/23#issuecomment-1015697767, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBDCXJRYKUKIGNITF75HP3UWWW5XANCNFSM5MAMKULQ. You are receiving this because you commented.Message ID: @.***>

lmas commented 2 years ago

Updated thanks to #24 and #25.