Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Created January 14, 2020 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skrylar/9ba6ac4060e32dd0f8fb0cfa285c7afe to your computer and use it in GitHub Desktop.
Save Skrylar/9ba6ac4060e32dd0f8fb0cfa285c7afe to your computer and use it in GitHub Desktop.
tytel: hmm, wonder what 1D worley noise would be like
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')
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment