So I have been working on some procedural generating and i managed to create a circular monochrome gradient map which i use to generate other maps.
def create_circular_gradient(self, world):
center_x, center_y = self.mapSize[1] // 2, self.mapSize[0] // 2
circle_grad = np.zeros_like(world)
for y in range(world.shape[0]):
for x in range(world.shape[1]):
distx = abs(x - center_x)
disty = abs(y - center_y)
dist = math.sqrt(distx * distx + disty * disty)
circle_grad[y][x] = dist
# get it between -1 and 1
max_grad = np.max(circle_grad)
circle_grad = circle_grad / max_grad
circle_grad -= 0.5
circle_grad *= 2.0
circle_grad = -circle_grad
# shrink gradient
for y in range(world.shape[0]):
for x in range(world.shape[1]):
if circle_grad[y][x] > 0:
circle_grad[y][x] *= 20
# get it between 0 and 1
max_grad = np.max(circle_grad)
circle_grad = circle_grad / max_grad
grad_world = self.apply_gradient_noise(world, circle_grad)
return grad_world
Now my question is, how exactly would i need to modify this to create a swirly gradient in a random way? and even maybe a box or a diverse linear gradients?
Note that world
is a randomly generated 2d array (and can be any shape like 100x100 or even 100x50 but of course i use it a whole lot bigger) and to the circle gradient, I add a perlin noise to randomize the generation. The code that randomizes it will work for any map but i'm not sure where to start creating different shapes of gradient.
Edit Ignore the magic numbers, that was the only way i found how to create a circular monochrome gradient