[TI-84Evo] Sierpinski Fractals v1.0
by Christopher "Kerm Martian" Mitchell, Ph.D.
https://z80.me
----------------------------------------------
Written on the Amtrak Lake Shore Limited,
Released May 17, 2026 for TI-84 Evo
----------------------------------------------

Requirements: TI-84 Evo or TI-84 Evo-T

Installation: Send SIERPNSK (SIERPNSK.8xp2) to your calculator. Run
              prgmSIERPNSK from the homescreen via the [PRGM] key.

How to use it:
1. Enter the number of sides for the fractal that you want to generate.
   For example, 3 creates a Sierpinski Triangle, while 4 creates a
   Sierpinski Carpet (the 2D version of a Menger Sponge). You can generate
   any N-gon, so enter any positive integer 3 or larger.
2. Press [ENTER]. The fractal will begin generating.
3. While the fractal is generating, press [CLEAR] or any other key
   to quit the program.

Why This Program, and How It Works:
TI graphing calculators like the TI-82 and TI-83 used to come with a thick,
hundreds-of-pages physical manual all about using your calculator. The
manual of course included fine detail about how to use the calculators'
math and graphing features, but it also covered how to write TI-BASIC. The
manual contained an example program to generate a Sierpinski Triangle, the
3-sided Sierpinski fractal, composed of nested triangles where each of the
three corner sub-triangles in any given triangle are themselves a Sierpinski
triangle, and the central triangle is removed.

That example has stuck in my mind for decades, and I recently took the time
to actually understand how it works: a technique known as the Chaos Game
(https://en.wikipedia.org/wiki/Chaos_game). To create a Sierpinski triangle
with the Chaos game, you select a random point within the triangle, pick one
of the three vertices of the triangle, and then move 1/2 of the distance from
your randomly chosen point to that vertex. You plot a point there, then repeat
the process by picking another random point, moving again, and plotting again.

But this can be generalized to create Sierpinski N-gons, where in each case,
the central polygon is removed, and N of the same fractal are packed around the
edges (or for a square, N=4, 8 copies). For a Sierpinski Triangle, this is the
central triangle removed and the three sub-Sierpinksi Triangles placed at each
of the three vertices. For a Sierpinski Carpet, the the central square is removed
and 8 Carpets are placed, one at each vertex and edge. For a Sierpinski Pentagon
or Hexagon, the central polygon is removed, and 5 or 6 shrunken copies appear at
each vertex.

Each of these uses the same algorithm as the Sierpinski Triangle, with the minor
exception of the Carpet moving towards either one of the four vertices or the
midpoints of one of the four edges. They do differ in how far they move from the
last point plotted to the chosen target vertex or midpoint: the ratio value,
which in this program is represented by the variable F, is well-defined for any
n-sided N-gon: see:
https://en.wikipedia.org/wiki/Chaos_game#Optimal_value_of_r_for_every_regular_polygon

If you have any questions, suggestions, or bug reports, please feel free to contact
me via the contact methods listed on z80.me, or post on Cemetech: https://www.cemetech.net