canvas_collatz {aRtsy} | R Documentation |
Draw Collatz Sequences
Description
This function draws the Collatz conjecture on a canvas. The
conjecture of the Collatz sequence is that no matter what positive integer
is chosen as the starting point of the sequence, the sequence will
eventually reach the number 1. This conjecture has been verified for all
starting integers up to very large numbers, but it has not been proven
mathematically. Despite its simple rule, the sequence can produce long and
complicated chains of numbers before eventually reaching 1. See the
Details
section for more specific information about the algorithm
used in this function.
Usage
canvas_collatz(
colors,
background = "#fafafa",
n = 200,
angle.even = 0.0075,
angle.odd = 0.0145,
side = FALSE
)
Arguments
colors |
a string or character vector specifying the color(s) used for the artwork. |
background |
a character specifying the color used for the background. |
n |
a positive integer specifying the number of random starting integers to use for the lines. Can also be a vector of numbers to use as starting numbers. |
angle.even |
a value specifying the angle (in radials) to use in bending the sequence at each odd number. |
angle.odd |
a value specifying the angle (in radials) to use in bending the sequence at each even number. |
side |
logical. Whether to put the artwork on its side. |
Details
The Collatz sequence, also known as the 3n+1
problem, is a
sequence of numbers generated by the following rule:
Start with any positive integer
n
.If
n
is even, divide it by 2.If
n
is odd, multiply it by 3 and add 1.Repeat this process with the new value of
n
, generating a new number in the sequence.
Value
A ggplot
object containing the artwork.
Author(s)
Koen Derks, koen-derks@hotmail.com
References
https://nl.wikipedia.org/wiki/Collatz_Conjecture
See Also
colorPalette
Examples
set.seed(1)
# Simple example
canvas_collatz(colors = colorPalette("tuscany3"))