Perlin Noise
Description:
Perlin Noise is a pseudorandom procedural texture used in various visual effects generation but also procedural world generation. Noise algorithms are used for generating world in video games like Minecraft, No Man's Sky, Noita, etc...
In this kata you should use the already implemented float perlin(float x, float y)
function to procedurally generate a 2D world of dimension width * height
. This function returns a float
between 0
and 1
.
The coordinates passed to the perlin
function must be offset from startX
and startY
and will be smoothed by multiplying by scale
. x
is considered to be the horizontal coordinate and y
the vertical coordinate.
x=0
is left and x=(width - 1)
is right.y=0
is top and y=(height - 1)
is bottom.
Input
startX
: An integer used as an offset for thex
axis.startY
: An integer used as an offset for they
axis.width
: An integer representing the length of thex
axis. Always>= 0
.height
: An integer representing the length of they
axis. Always>= 0
.scale
: A float used to smooth the coordinates. Always>= 0
.
How scale
works
Without smoothing, parameters width=20, height=10
would render that:
.▒▒..▓▒▒▓.█░..░░.▓░.
.█░..░░.▓░.░▒.▒.░..█
░..█..▓▓▓.▓....▒▒..▓
.█.░....░.▓..▓.░▒▓..
█.█.░....░.▓..▓.░▒▓.
▓░....░...█...▒.░█.█
█...▒.░..█..▓▓▓.▓...
█.▓░....░...█...▒.░█
▓░.▒▒░█..░██.█..▒▓.▒
....░.▓..▓.░▒▓..▒▒▒░
Not very great if you ask me. But when multiplying x
and y
by scale
, we obtain smoother terrain (here width=20, height=10, scale=0.08
):
........░░░▒▒▒▒▒▒▒▒▒
........░░▒▒▒▒▒▒▒▒▒▒
........░░▒▒▒▒▒▒▒▒▒▒
........░░▒▒▒▒▒▒▒▒▒▒
.......░░▒▒▒▒▒▒▒▒▒▒▒
.......░░▒▒▒▓▓▓▒▒▒▒▒
......░░▒▒▒▓▓▓▓▓▓▒▒▒
.....░░░▒▒▓▓▓▓▓▓▓▓▒▒
.....░░▒▒▒▓▓▓▓▓▓▓▓▒▒
....░░░▒▒▓▓████▓▓▓▓▒
You can smooth terrains by calling the perlin
function like so:
perlin(x * scale, y * scale);
Don't forget to addition the offsets in your code!
Output
A pointer of 32-bit unicode characters representing the world. Each line must be separated by a line jump.
You should allocate the pointer yourself.
Different unicode characters will represent the height of each position. Those characters are deduced from the perlin
function return value like so:
>= 0.90: █
>= 0.80: ▓
>= 0.65: ▒
>= 0.50: ░
< 0.50: .
(.
represents water.)
Similar Kata:
Stats:
Created | Oct 11, 2021 |
Published | Oct 11, 2021 |
Warriors Trained | 273 |
Total Skips | 149 |
Total Code Submissions | 146 |
Total Times Completed | 32 |
C Completions | 16 |
JavaScript Completions | 12 |
TypeScript Completions | 8 |
Total Stars | 6 |
% of votes with a positive feedback rating | 81% of 13 |
Total "Very Satisfied" Votes | 9 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 16 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |