-
-
Save NelsonMinar/81405e870267c4641d758fb2bc33d655 to your computer and use it in GitHub Desktop.
Histograms of noise functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Print out some histograms for the outputs of various noise functions. | |
The noise function is sampled with a uniformly random set of x/y coordinates in the range [ -100_000, 100_000 ] | |
""" | |
from opensimplex import OpenSimplex | |
import noise | |
import random, math | |
buckets = 20 | |
samples = 1000000 | |
char_width = 50 | |
def do(noisefunc): | |
histogram = [0] * (buckets) | |
for i in range(samples): | |
x = random.uniform(-100000, 100000) | |
y = random.uniform(-100000, 100000) | |
v = noisefunc(x, y) | |
p = (v+1) / 2 | |
b = round(p * (buckets-1)) | |
histogram[b] += 1 | |
biggest = max(histogram) | |
for i in range(buckets): | |
v = histogram[i] | |
n = ((i+0.5) / buckets) * 2 - 1 | |
w = char_width * v / biggest | |
c = ''.join(['*'] * round(w)) | |
print(f'{n: .2f} {c}') | |
print("Perlin noise") | |
do(noise.pnoise2) | |
print("Simplex noise") | |
do(noise.snoise2) | |
print("OpenSimplex noise2d") | |
osn = OpenSimplex() | |
do(osn.noise2d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Perlin noise | |
-0.95 | |
-0.85 | |
-0.75 | |
-0.65 | |
-0.55 *** | |
-0.45 *********** | |
-0.35 ***************** | |
-0.25 ********************************* | |
-0.15 ******************************************* | |
-0.05 ************************************************* | |
0.05 ************************************************** | |
0.15 ******************************************** | |
0.25 ********************************** | |
0.35 **************** | |
0.45 *********** | |
0.55 *** | |
0.65 * | |
0.75 | |
0.85 | |
0.95 | |
Simplex noise | |
-0.95 | |
-0.85 ********* | |
-0.75 ************** | |
-0.65 ************************* | |
-0.55 ************************************************ | |
-0.45 ************************************************* | |
-0.35 ********************************************** | |
-0.25 ********************************************** | |
-0.15 *********************************************** | |
-0.05 ********************************************** | |
0.05 ************************************************ | |
0.15 ************************************************** | |
0.25 ************************************************ | |
0.35 ************************************************ | |
0.45 ************************************************** | |
0.55 ************************************************* | |
0.65 ************************ | |
0.75 ************** | |
0.85 ********* | |
0.95 | |
OpenSimplex noise2d | |
-0.95 | |
-0.85 | |
-0.75 ***** | |
-0.65 *************** | |
-0.55 ************************** | |
-0.45 ***************************************** | |
-0.35 ************************************************** | |
-0.25 ************************************************** | |
-0.15 ************************************************* | |
-0.05 ************************************************* | |
0.05 ************************************************** | |
0.15 ************************************************* | |
0.25 ************************************************* | |
0.35 ************************************************* | |
0.45 **************************************** | |
0.55 ************************** | |
0.65 *************** | |
0.75 ***** | |
0.85 | |
0.95 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment