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:
Behind every successful project is a whole team of specialists. Each of them is assigned specific tasks at different stages of the work. Seemingly sounds simple, but industry terms such as Product Owner, Project Manager or UX/UI Designer can confuse you. After reading this article, the tasks of the experts we encounter during the development […]
Mobile apps are currently one of the fastest-growing sectors. Smartphone and tablet users spend most of their time just using apps, with the rest dedicated to using the web browser. It’s not just games or social networks that provide entertainment and allow you to connect with friends. Mobile apps are also crucial for business operations […]
Do you like games on your phone? If the answer is no, then ask yourself if you’ve definitely never played, at least Snake, Tetris, or Candy Crush – and answer again. Now imagine the situation: Sunday, 8 p.m., your thoughts are unfortunately already on Monday, but there is some time left, so why not use […]