import random import pygame from perlin_noise import PerlinNoise def generate_planet_surface(screen, seed): width, height = screen.get_size() scale = 100 # Create a PerlinNoise instance noise_gen = PerlinNoise(seed=seed) for y in range(height): for x in range(width): # Normalize coordinates by dividing by the scale nx = x / scale ny = y / scale # Get the Perlin noise value for the current position color_val = noise_gen([nx, ny]) # Scale and clamp the color value to a 0-255 range gray = int((color_val + 1) / 2 * 255) gray = max(0, min(255, gray)) # Set the pixel color at (x, y) screen.set_at((x, y), (gray, gray, gray))