canvas_ant {aRtsy}R Documentation

Draw Langton's Ant

Description

This function draws Langton's Ant on a canvas. Langton's ant is a two-dimensional universal Turing machine with a very simple set of rules. These simple rules can lead to complex emergent behavior.

Usage

canvas_ant(colors, background = "#fafafa", iterations = 50000,
           resolution = 500)

Arguments

colors

a character (vector) specifying the color(s) used for the artwork.

background

a character specifying the color used for the background.

iterations

a positive integer specifying the number of iterations of the algorithm.

resolution

resolution of the artwork in pixels per row/column. Increasing the resolution increases the quality of the artwork but also increases the computation time exponentially.

Details

The algorithm for Langton's Ant involves repeating the following rules: 1) on a non-colored block: turn 90 degrees clockwise, un-color the block, move forward one block; 2) On a colored block: turn 90 degrees counter-clockwise, color the block, move forward one block; 3) If a certain number of iterations has passed, choose a different color which corresponds to a different combination of these rules.

Value

A ggplot object containing the artwork.

Author(s)

Koen Derks, koen-derks@hotmail.com

References

https://en.wikipedia.org/wiki/Langtons_ant

See Also

colorPalette

Examples


set.seed(1)

# Simple example
canvas_ant(colors = colorPalette("house"))



[Package aRtsy version 0.1.8 Index]