Replies: 2 comments 6 replies
-
Hi, @TomLarrow! Maybe you could use this as a way to introduce the idea of vectorizing? You could do this with the nested for loops and then show that it is slow, then do one row at a time in a for loop and show that it is somewhat faster, then do all of it in one shot with numpy's grid tools. Actually, you might get much of the performance gain from doing one row at a time, without having to to do the grid stuff. It would go from O(N^2) to O(N). There is a tutorial on generating noise. The thing you have to be careful about here is that |
Beta Was this translation helpful? Give feedback.
-
I wrote something up here: https://codeberg.org/TomLarrow/creative-coding-experiments/src/branch/main/x_0057/x_0057.py Much of it is from the noise tutorial, but for me, coming from using other forms of Processing, the big change was switching defining the arrays with numpy.arange, rather than numpy.linspace When doing things in for loops, I'm used to scaling the noise by something like 0.02, or 0.005, so thinking about the numbers incrementing by this noise scaling made sense to me. I'm used to thinking, oh, these values are 0.02 apart as I go across horizontally so: somehow feel more intuitive than because with the first it was easier for me to mentally "see" that one number was noise_increment away from the next one Yes, linspace gives the exact same result, but the numeric difference in the noise value from one pixel to the next felt more abstract (Maybe this is just me being relatively new to numpy and scientific Python in general, but that's kind of the target audience for this exercise) |
Beta Was this translation helpful? Give feedback.
-
So, this is a port of Shiffman's original 2D noise example that came from Processing Python mode, comes from a Processing Java example:
So, this is too slow, but the challenge is: how to improve this with the new py5 capabilities in a way that a beginner can understand?
I think that the
np.mgrid
+ vectorized noise approach is a bit steep for beginners, can you think of something in between?Calling @TomLarrow to think of something together 😃
PS: I'm slowly going through all the Processing Python mode examples again (but I should be working on my PhD...):
https://github.com/villares/py5examples/tree/processing-python-mode-examples/examples-from-Processing-Python-mode
Beta Was this translation helpful? Give feedback.
All reactions