Mandel Sheet

Animation of the mandelbrot set created in Google Sheets using Python by way of the Neptyne Sheets add-on. There are more productive ways to use Python inside of Google sheets, but this is more fun.

I find the idea of creating a mandelbrot animation inside of Google Sheets unreasonably amusing. Maybe it is how inefficient it is, or maybe it is the fact that it is possible at all. So what's going on here? We run the Python code below inside of Google sheets, using the Neptyne Python for Sheets add-on.

The code is just the standard mandelbrot set calculation, and it uses three cells on top to determine what it should render. There's a loop in the code that runs for a certain number of iterations and I just captured that, grabbed the right frames and put some music on top of it. The music is from Suno.

Or open the sheet directly

import numpy as np

def mandelbrot(c, max_iter):
    z = 0
    for n in range(max_iter):
        if abs(z) > 2:
            return n / max_iter
        z = z * z + c
    return 1

def generate_mandelbrot(center_x, center_y, zoom, size=70, max_iter=256):
    zoom = 1.05 ** (zoom - 1)
    pixels = np.zeros((size, size))
    for x in range(size):
        for y in range(size):
            re = (x - size / 2) / (0.5 * zoom * size) + center_x
            im = (y - size / 2) / (0.5 * zoom * size) + center_y
            c = complex(re, im)
            pixels[y, x] = mandelbrot(c, max_iter)
    return pixels