Functional Geometry in R

By Matthew Henderson in functional-programming

January 16, 2018

This post introduces funcgeo, an R package for functional geometry, by recreating Square Limit by M. Escher (Fig. 1) following the approach of Henderson (1982).

Squarelimit

Figure 1: Squarelimit

Peter Henderson describes Functional Geometry in two papers: Henderson (1982) and Henderson (2002). In those papers he shows how to define a language of pictures using basic concepts of functional programming.

funcgeo implements a picture language like the one described in Henderson (1982).

To install funcgeo use install_gitlab from the remotes package.

remotes::install_gitlab("MHenderson1/funcgeo")

The next section introduces the basic fish pictures used to construct Square Limit.

After that, subsequent sections, the fish are combined into more complex pictures where the lines of the fish are connected at picture boundaries. The penultimate step before constructing the complete Square Limit picture is to combine the complex pictures into the sides and corners of Square Limit.

Fish

The fish from Henderson (1982) are available in funcgeo as package data: fish_p, fish_q, fish_r and fish_s. All fish have class picture and funcgeo implements a plot method for pictures.

library(funcgeo)

plot(fish_p)
Fish P

(#fig:fish_p)Fish P

plot(fish_q)
Fish Q

(#fig:fish_q)Fish Q

Combining fish

Picture operations from Henderson (1982) like rot, flip and cycle are implemented in funcgeo.

For example, the quartet operation described in Henderson (1982) is used to combine the four fish into t, one of the building blocks of Square Limit.

t <- quartet(fish_p, fish_q, fish_r, fish_s)

plot(t)
t

(#fig:fish_t)t

Similarly, cycle and rot functions are used to create u from fish_q.

u <- cycle(rot(fish_q))

plot(u)
u

(#fig:fish_u)u

Sides

quartet is also required for building side1, one of the more complex pieces of Square Limit. side1 also requires the rot operation and nil empty picture.

side1 <- quartet(nil, nil, rot(t), t)

plot(side1)
Side 1

Figure 2: Side 1

side2 is created as a quartet involving several pictures, including side1.

side2 <- quartet(side1, side1, rot(t), t)

plot(side2)
Side 2

Figure 3: Side 2

Corners

The goal of this section is to reproduce corner from Henderson (1982). Square Limit is created by calling the cycle operation on corner. However, creating corner requires first creating corner2, which itself is based on corner1 which is a quartet of three null pictures and u.

corner1 <- quartet(nil, nil, nil, u)

plot(corner1)
Corner 1

Figure 4: Corner 1

corner2 is also a quartet made from corner1 side1 and u.

corner2 <- quartet(corner1, side1, rot(side1), u)

plot(corner2)
Corner 2

Figure 5: Corner 2

nonet is a \(3 \times 3\) equivalent of quartet and is used with corner2 side2, u, t, and fish_q to create corner, the only picture we need to create Square Limit.

corner <- nonet(
  corner2, side2, side2,
  rot(side2), u, rot(t),
  rot(side2), rot(t), rot(fish_q)
)

plot(corner)
Corner

Figure 6: Corner

Square Limit

Square Limit now is just cycle with corner.

squarelimit <- cycle(corner)

plot(squarelimit)
Square Limit

Figure 7: Square Limit

Posted on:
January 16, 2018
Length:
3 minute read, 452 words
Categories:
functional-programming
Tags:
r-packages generative-art
See Also: