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:
In appvinio, we most often work with visionaries who want to create innovative products under a new brand, in short – with startups. But regardless of whether the application is to be a new market killer or a useful corporate tool to streamline processes, it should be built in a way to achieve the planned […]
You may have encountered a problem with build_runner before. Looking at it from the side the library is very useful. However, it has one fundamental flaw that bugs me, and it’s succinctly called: flutter pub run build_runner build –delete-conflicting-outputs. Some of you probably use the fvm library, which allows you to manage Flutter versions. You […]
I’ m sure many of you may have come across a moment when you find an idea for a new project, but in order to start it you need to go through a to-do list: add the essential libraries that you use in every project, set all the parameters in MaterialApp, copy useful widgets, prepare […]