Beta

Perlin Noise

16 of 32QuantumSheep

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 the x axis.
  • startY: An integer used as an offset for the y axis.
  • width: An integer representing the length of the x axis. Always >= 0.
  • height: An integer representing the length of the y 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.)

Strings
Algorithms

Similar Kata:

Stats:

CreatedOct 11, 2021
PublishedOct 11, 2021
Warriors Trained273
Total Skips149
Total Code Submissions146
Total Times Completed32
C Completions16
JavaScript Completions12
TypeScript Completions8
Total Stars6
% of votes with a positive feedback rating81% of 13
Total "Very Satisfied" Votes9
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments16
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • QuantumSheep Avatar
Ad