So, recently I've been learning procedural generation stuff (Perlin noise specifically) and I've kind of hit a wall.
This is the result that I've seen everyone get, but this is what I'm getting,
This is my code, (I'm using python):
import random
import math
import PIL.Image
class Noise:
def __init__(self, x, y):
self.x = x
self.y = y
def lerp(self, start, stop, t):
return start*(1-t) + (stop*t)
def smoothstep(self, t):
return 3*(t**2) - 2*(t**3)
def gradients(self):
grads = []
for _ in range(4):
x = random.randrange(0, 361)
y = random.randrange(0, 361)
grads.append((math.cos(x), math.sin(y)))
return grads
def cvectors(self):
botleft = (self.x, self.y)
botright = (self.x-1, self.y)
topleft = (self.x, self.y-1)
topright = (self.x-1, self.y-1)
cvecs = [botleft, botright, topleft, topright]
return cvecs
def makenoise(self):
dot = []
grads = self.gradients()
cvecs = self.cvectors()
for i in range(4):
(x, y) = cvecs[i]
(a, b) = grads[i]
dot.append((x*a)+(y*b))
st = self.lerp(dot[0], dot[1], self.smoothstep(x))
uv = self.lerp(dot[2], dot[3], self.smoothstep(x))
stuv = self.lerp(st, uv, self.smoothstep(self.y))
return stuv
size = 128
img = PIL.Image.new('L', (size, size))
for x in range(size):
for y in range(size):
perlin = Noise(random.uniform(0, 1), random.uniform(0, 1))
img.putpixel(tuple([x, y]), perlin.makenoise())
img.save("nois.png")
This is just a guess, but I feel like it's a scaling issue. Thanks in advance, and apologies, as well, for the horrible code.