Write a python script that will generate a mandelbrot set in the terminal
- User
Write a python script that will generate a mandelbrot set in the terminal
Assistant
Sure! Here's a simple Python script that generates a mandelbrot set in the terminal:
import matplotlib.pyplot as plt import numpy as np # Set the size of the image n = 200 # Set the maximum iteration number max_iter = 100 # Set the colors to use colors = ['#0f0', '#240', '#0f2', '#242'] # Generate the image x = np.linspace(-2, 1, n) y = np.linspace(-1, 1, n) X, Y = np.meshgrid(x, y) Z = np.zeros_like(X) # Initialize the image Z[0,:] = 0 Z[1,:] = 0 Z[2,:] = 0 # Apply the mandelbrot algorithm for i in range(max_iter): Z[i%2,:] = 0 for j in range(i): Z[(i-j)%2,:] = np.sqrt(Z[(i-j)%2,:]**2 + Z[j%2,:]**2) if np.abs(Z[0,:]) > 2.0 or np.abs(Z[1,:]) > 2.0 or np.abs(Z[2,:]) > 2.0: break # Plot the image plt.pcolormesh(X, Y, Z, cmap=plt.cm.viridis, shading='zhue') plt.colorbar() plt.show()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.