Examples of use
Below I give you a list of great examples of using Perlin noise.
Terrain/Worlds Generation:
Different:
A bit of theory:
There are no fully random numbers in programming, there are pseudorandom numbers which are difficult to distinguish from real random numbers (but for simplicity they are called random). Such numbers are usually generated on the basis of some sequence of characters called seed.
We will try to illustrate how random numbers look like and how their relationship between one number and the next one looks like. Let’s draw 10 numbers from the range 1 to 100 inclusive:
1. 4
2. 72
3. 94
4. 28
5. 100
6. 81
7. 35
8. 21
9. 89
10. 51
To better understand how scattered they are across the range, I propose to represent them with a graph, where the X-axis is consecutive draws and the Y-axis is the values of those draws. We drew 200 numbers ranging from 0 to 400:
As you can see, the values are chaotically scattered throughout the numerical range and each previous value is not related in any way to the next.
Sometimes there is a situation where we want to have the phenomenon of randomness, but more structured, fluid. A good example is the algorithm for creating terrain in Minecraft. Each new world is created randomly (using seed), but in a way where you can easily distinguish meadows, mountains, oceans, etc. In this case, ordinary random numbers won’t do the job and we need the help of Perlin noise.
Perlin Noise is an algorithm that, based on a seed, creates a random sequence of numbers that is “smooth”. What does it mean? Each previous number is in the close range of the next number. This makes the chaos disappear. It is best illustrated by the following graphic:
Each dot is randomly generated and each time we introduce a different seed we will see a different graph. Moreover, the algorithm allows us to perform various operations on these pseudo random numbers. We can flatten or sharpen, narrow or widen this graph, so we can get a hillier or flatter result. Additionally, Perlin Noise allows us to create multi-dimensional graphs. Below you can see the difference between regular random numbers and the numbers generated by Perlin Noise. Each pixel had a random value between 0 and 255 that determined its color.
Random numbers
Numbers generated by Perlin Noise
In the terrain creation algorithm, we could take darker pixels for mountainous terrain and whiter pixels for plains or oceans.
One of the most obvious things could be a splash screen or some background that will be moving in an unrepeatable manor. The following example with a few modifications and a change of color could easily serve as such a background:
After adding appropriate colors:
Below I give you a list of great examples of using Perlin noise.
Terrain/Worlds Generation:
Different:
A bit of theory:
Websites and apps are used by most people virtually every day. While the differences between websites and mobile apps are apparent at first glance, some people may be unaware that the “website” they are using is actually a web app. This article will dispel any doubts about the definitions and differences between websites and all […]
It started with an idea. From the idea came the design of a mobile application. Later – the finished product. And… what next? How to get the app into stores and make it available to users? “This is a slightly more complicated topic than in the case of browser-based applications,”—says one of the two main […]
Do you remember the early days of the pandemic? It was a very difficult and uncertain time, during which both employees and companies didn’t know what their work would look like—that’s when the remote mode, not very popular at the time, was implemented. When the first dust settled and the pandemic became our new reality, […]