Last active
September 5, 2019 18:02
-
-
Save fdrobidoux/ca717e9b42ddd0d7f6b77014ac6ada44 to your computer and use it in GitHub Desktop.
Experimentation with 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
import random | |
import math | |
mapsize = 35 | |
def print_chart(i, noise): | |
outstr = '' | |
for i in noise: | |
if (i > 0.75): | |
outstr += '᷃█' | |
elif (i > 0.50): | |
outstr += '▓' | |
elif (i > 0.25): | |
outstr += '▒' | |
else: | |
outstr += '░' | |
outstr += '\n' | |
print(outstr) | |
def adjacent_min(noise): | |
output = [] | |
for i in range(len(noise) - 1): | |
output.append(min(noise[i], noise[i + 1])) | |
return output | |
def smoother(noise): | |
output = [] | |
for i in range(len(noise) - 1): | |
output.append(0.5 * (noise[i] + noise[i + 1])) | |
return output | |
MAX_SIZE = 25 | |
for i in range(60): | |
random.seed(i) | |
noise = [random.uniform(-1, +1) for i in range(mapsize)] | |
noiseList = smoother(noise) | |
base = 1.0 | |
outstr = '' | |
for y in noiseList: | |
if (y >= base - (i / mapsize)): | |
outstr += '█' | |
else: | |
outstr += ' ' | |
print(outstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment