STUMP » Articles » Geeking Out: Making Fractals in a Spreadsheet » 25 November 2018, 20:18

Where Stu & MP spout off about everything.

Geeking Out: Making Fractals in a Spreadsheet  

by

25 November 2018, 20:18

Hey, I don’t only think about mortality.

So waaaaaay long ago (about 1991), I was learning about fractals, and found an article in some science/engineering magazine (I think it was called Radio Electronics) that gave me The following code

%!
/problistcreate {mark /counter 0 def probabilities {128 mul round cvi
{transforms counter get} repeat /counter counter 1 add def} forall
counttomark 128 sub neg dup 0 gt {[1 0 0 1 0 0] repeat} {pop} ifelse]
/problist exch def} bind def
%
/doit {problistcreate 1 1 20 {problist rand -24 bitshift get transform 2
copy moveto 0.001 10 rlineto} repeat newpath numdots {problist rand -24
bitshift get transform 2 copy moveto 0.001 0 rlineto stroke} repeat} bind def
%

/numdots 6000 def

% /transforms[
[.5 0 0 .5 0 0]
[.5 0 0 .5 4 0]
[.5 0 0 .5 2 4]
] def
%

/probabilities [.33 .33 .34] def
%
1 setlinecap 0 setlinewidth 200 300 translate 30 dup scale doit showpage
quit

That was in postscript, a language a lot of printers used long, long ago.

Well, time moved on, and printers don’t use postscript anymore (that I know of), as PDF supplanted it. It looks like one can still run postscript code using Ghostscript, but the cool thing about the postscript program was that the printer itself was running code to make fractals. It’s not nearly so cool when it’s just code making fractals like one does.

So let me do it in a spreadsheet.

THE BEAUTY OF SPREADSHEETS

I started a thread at the Actuarial Outpost last year about inappropriate spreadsheet use, and some of the craziest stuff we’ve come across are people using spreadsheets to “paint” pictures.

Some of these are quite funny.

But to be serious for a moment, the cool thing about doing fractals and other mathematically-generated pictures in a spreadsheet is that you can see every single step used to calculate results.

Let me show you some fractals that came out of my spreadsheet.

The spreadsheet is here, by the way. Check the notes tab to find out how to change what you’re looking at.

If you want to learn about the math about linear iterated function systems (which is what I’m doing), check out this website by Larry Riddle at Agnes Scott College. I don’t feel like explaining… just look at the pretty pictures!

SIERPINSKI TRIANGLE

Here is a classic fractal – the triangle made of three smaller triangles… made of 9 smaller… etc.

By the way, I created a crochet pattern to make a Sierpinski shawl, which I’ve made a couple times. It uses the ceullular automaton approach, which means, you only need to remember one rule, and not actually follow a pattern… also, it’s potentially infinite in construction… just keep crocheting til you run out of yarn.

I also did a Sierpinski spreadsheet last year, in an even more inappropriate way, using conditional formatting. Jeez.

KOCH CURVE

Also known as the Koch snowflake.

It was the Koch snowflake that really captured my imagination when I first learned about fractals — (finite area with infinite perimeter… pretty cool)

BARNSLEY FERN

This is after Michael Barnsley, who wrote the book Fractals Everywhere – obviously, the version I had from him is a lot older than 2013.

Here’s the wiki entry on this fractal:

The Barnsley fern is a fractal named after the British mathematician Michael Barnsley who first described it in his book Fractals Everywhere. He made it to resemble the black spleenwort, Asplenium adiantum-nigrum.

….
The fern is one of the basic examples of self-similar sets, i.e. it is a mathematically generated pattern that can be reproducible at any magnification or reduction. Like the Sierpinski triangle, the Barnsley fern shows how graphically beautiful structures can be built from repetitive uses of mathematical formulas with computers. Barnsley’s 1988 book Fractals Everywhere is based on the course which he taught for undergraduate and graduate students in the School of Mathematics, Georgia Institute of Technology, called Fractal Geometry. After publishing the book, a second course was developed, called Fractal Measure Theory.[ Barnsley’s work has been a source of inspiration to graphic artists attempting to imitate nature with mathematical models.

I’m pretty sure we used the 1988 text as our text for the fractals class I took at nerd school.

In the wiki article, you can see how it’s constructed.

THAT’S NOT THE SHAPE OF MY HEART

I created that for a Valentine’s Day gift for a prior boyfriend (not Stu… we have never done Valentine’s Day since we met.)

But this also gives me an opportunity to embed my favorite math-related pop song: Sting’s Shape of my Heart:

It’s all about probability— okay, it’s about something else, but check these lyrics:

He deals the cards to find the answer
The sacred geometry of chance
The hidden law of a probable outcome
The numbers lead a dance

They do indeed.

And let the fractals dance – the last ones, I’m not going to label.

FRACTAL POTPOURRI

So… one can’t just do random codes, but if you’re looking for stuff to try, search for “linear iterated function systems”…

…and maybe the next inappropriate spreadsheet I’ll do is making the Mandelbrot set….

(don’t worry, I haven’t given up on pensions… they’ll be coming….)