[Python] Why do most seeds result in the perlin noise become vertical lines?

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying my hand at perlin noise so that i could make dnd maps, but my python project seems to always come up with either perfectly vertical lines or noise that comes out extremely vertical.Typical generation Typical half generation


    from asyncio import WindowsProactorEventLoopPolicy
    import numpy as np
    import matplotlib.pyplot as plt
    from noise import pnoise2
    import random
    import tkinter as tk
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

    def update_plot():
    shuffle_and_plot()

    def generate_perlin_map(width, height, scaling, octaves=6, persistence=0.6, lacunarity=5, threshold=0.7, seed=None):
    """Generates a Perlin noise heat map with thresholding and an optional random seed."""
    if seed is not None:
    random.seed(seed)

    noise_map = np.zeros((height, width))
    for y in range(height):
    for x in range(width):
    noise_map[y][x] = pnoise2(x / width, y / height, octaves=10, persistence=.8, lacunarity=2, base=seed)

    # Normalize values to range 0-1
    noise_map = (noise_map - noise_map.min()) / (noise_map.max() - noise_map.min())

    # Apply thresholding
    #noise_map = np.where(noise_map > threshold, .5, 0)
    return noise_map

    def plot_heatmap(noise_map):
    """Displays the generated heat map."""
    plt.imshow(noise_map, cmap='gray', interpolation='nearest')
    plt.title("Perlin Noise Heat Map")
    plt.show()

    def shuffle_and_plot():
    """Regenerates the noise map with a new seed and plots it."""
    global noise_map
    new_seed = random.randint(0, 10000) # Randomize seed for different patterns
    noise_map = generate_perlin_map(width = 1000, height = 1000, scaling = .02, seed=new_seed)
    plot_heatmap(noise_map)

    root = tk.Tk()
    root.title("Perlin Noise Generator")
    button = tk.Button(root, text="Shuffle", command=update_plot)
    button.pack()
    root.mainloop()



    I have tried increasing and decreasing the width, height, octaves, persistence and lacunarity, as well as adding a scaling variable for the width and heights, but it always results in the vertical lines (at least on most seeds).

    Continue reading...

Compartilhe esta Página