Skip to content

Instantly share code, notes, and snippets.

@ExcelRobot
Last active May 4, 2024 08:27
Show Gist options
  • Save ExcelRobot/fe2a8aa81b668ea4d2974beeec8eea02 to your computer and use it in GitHub Desktop.
Save ExcelRobot/fe2a8aa81b668ea4d2974beeec8eea02 to your computer and use it in GitHub Desktop.
Mandelbrot Lambda
/*
Name: Mandelbrot Set (Mandelbrot)
Description: Generates a Mandelbrot set based on given assumptions that can be used with conditional formatting to view the visual representation.
Parameters:
xleft - Left X value
xright - Right X value
ytop - Top Y value
ybottom - Bottom Y value
size - number of columns/rows in square output range
iterations - number of iterations
Source: Excel Robot (@ExcelRobot), inspired by Chris Rae's video: https://www.youtube.com/watch?v=v3BtrlSOrX0
*/
Mandelbrot = LAMBDA(xleft,xright,ytop,ybottom,size,iterations,
MAKEARRAY(size,size,LAMBDA(c,r,LET(
x0, xleft+(r-1)*(xright-xleft)/size,
y0, ytop+(c-1)*(ybottom-ytop)/size,
fn, LAMBDA(ixy,iteration,LET(
i, INDEX(ixy,,1),
x, INDEX(ixy,,2),
y, INDEX(ixy,,3),
repeat, AND((x*x+y*y)<=(2*2),i>=iteration-1),
newi, IF(repeat,iteration,IF(i<iteration,i,i-1)),
xtemp, IF(repeat,x*x-y*y+x0,0),
newy, IF(repeat,2*x*y+y0,0),
newx, xtemp,
CHOOSE({1,2,3},newi,newx,newy)
)),
INDEX(REDUCE({0,0,0},SEQUENCE(iterations),fn),1)
)))
);
@ExcelRobot
Copy link
Author

Mandelbrot Lambda 12

@ExcelRobot
Copy link
Author

Revised replacing CRLF line endings with just LF because AFE wasn't sync'ing properly after import.

@ExcelRobot
Copy link
Author

To reproduce the conditional formatting used in animated GIF:

  1. If cell value is equal to number of iterations, set fill color to black. And check the Stop option so it won't apply any additional conditional formats.
    image

  2. Apply 3-color scale gradient using black/purple/yellow.
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment