Python script to generate a mandelbrot in the terminal
- User
Python script to generate a mandelbrot in the terminal
Assistant
Here is a basic Python script to generate a Mandelbrot set in the terminal using ASCII characters:
import sys def mandelbrot(x, y, max_iterations): c = complex(x, y) z = 0.0j for i in range(max_iterations): z = z * z + c if abs(z) > 2: return i return max_iterations def print_mandelbrot(xmin, xmax, ymin, ymax, height, width, max_iterations): for y in range(height): for x in range(width): real = (xmax - xmin) * (x / (width - 1)) + xmin imag = (ymax - ymin) * (y / (height - 1)) + ymin iteration = mandelbrot(real, imag, max_iterations) print("#" * iteration, end="") print() if __name__ == "__main__": if len(sys.argv) != 8: print("Usage: python mandelbrot.py xmin xmax ymin ymax height width max_iterations") sys.exit(1) xmin = float(sys.argv[1]) xmax = float(sys.argv[2]) ymin = float(sys.argv[3]) ymax = float(sys.argv[4]) height = int(sys.argv[5]) width = int(sys.argv[6]) max_iterations = int(sys.argv[7]) print_mandelbrot(xmin, xmax, ymin, ymax, height, width, max_iterations)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.