Learn creative coding writing simple programs

36. Organic random animation using noise()

We have used random() in many of our episodes. We could say random() has one problem: it's too random. Things in real life do not jump from place to place, but move in small increments. The noise() function allows us to get that kind of random numbers.
There are some differences between random() and noise(). random() returns a number between a minimum and a maximum value. noise() returns a value between 0 and 1. The parameters used when calling random set the minimum and maximum values. The only parameter used in noise() is used to get random numbers that do not change too much.
So if I call noise(3.00) and then noise(3.01), they will return a random number, but in both cases the number will not be very different. This is great for animating positions, sizes, rotation or colors.
Normally we will be interested in ranges of numbers greater than the default 0 ... 1 range. We solve this by multiplying whatever number comes out of noise(). For example if we multiply noise() by 100, we will get a number between 0 and 100.
Try to use noise() in any of the programs we created in past episodes!

Tags: random, noise

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```