Created
January 14, 2020 23:45
-
-
Save Skrylar/9ba6ac4060e32dd0f8fb0cfa285c7afe to your computer and use it in GitHub Desktop.
tytel: hmm, wonder what 1D worley noise would be like
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
from math import sqrt | |
from tqdm import tqdm | |
from random import random | |
import matplotlib | |
from matplotlib import pyplot as plt | |
point_count = 20 | |
zoop = [0]*2048 | |
points = [0]*point_count | |
def closest_point(x): | |
"""Find the closest point to a given position.""" | |
best = 0 | |
best_dist = 4000000000 | |
x2 = x * x | |
for y, z in enumerate(points): | |
score = abs((z * z) - x2) | |
if score < best_dist: | |
best_dist = score | |
best = y | |
return points[best] | |
def lerp(a, b, t): | |
return ((1.0 - t) * a) + (t * b) | |
print("Placing 1D Worley points") | |
for i in tqdm(range(0, point_count)): | |
points[i] = round(random() * 2048) | |
print("Sorting") | |
points = sorted(points) | |
print("Closest point check") | |
for i in tqdm(range(0, 2048)): | |
point = closest_point(i) | |
zoop[i] = point | |
print("Distance testing") | |
for i in tqdm(range(0, 2048)): | |
dist = abs((zoop[i] * zoop[i]) - (i * i)) | |
zoop[i] = sqrt(dist) | |
fig, ax = plt.subplots() | |
ax.plot(zoop) | |
fig.savefig('worley.svg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment