noise()function takes one, two, or three arguments, as noise is computed in one, two, or three dimensions. Let’s start by looking at one-dimensional noise.
var x = random(0, width); ellipse(x, 180, 16, 16);
var x = noise(0, width); ellipse(x, 180, 16, 16);
random()function specify a range of values between a minimum and a maximum,
noise()does not work this way. Instead,
noise()expects us to pass in an argument that signifies a "moment in time," and always returns a value between 0 and 1. We can think of one-dimensional Perlin noise as a linear sequence of values over time. For example, here are example inputs and return values:
noise()function. For example:
var n = noise(0.03);
noise(3)will return 0.490 at time equals 0.03. We could improve this by using a variable for time and asking for a noise value continuously in
noise()function at the same point in time—3—over and over. If we increment the time variable
t, however, we’ll get a different result.
map()function, which will help us in more situations later on. The
map()function takes five arguments. First up is the value we want to map, in this case
n. Then we have to give it the value’s current range (minimum and maximum), followed by our desired range.
ty. This is because we need to keep track of two time variables, one for the x-location of the
Walkerobject and one for the y-location. But there is something a bit odd about these variables. Why does
txstart at 0 and
tyat 10,000? While these numbers are arbitrary choices, we have very specifically initialized our two time variables with different values. This is because the noise function is deterministic: it gives you the same result for a specific time
teach and every time. If we asked for the noise value at the same time
ywould always be equal, meaning that the
Walkerobject would only move along a diagonal. Instead, we simply use two different parts of the noise space, starting at 0 for
xand 10,000 for
ycan appear to act independently of each other.
xoffto indicate the x-offset along the noise graph, rather than
tfor time (as noted in the diagram).
Walkerin a slightly different way. Have fun!