Recursively draw a hexaflake maze, a cross between a Koch snowflake
and a Sierpinski triangle. The outer part of the flake consists of
a hexagon of side length \(3^{depth}\) pieces of length
unit_len
. The ‘inner’ and ‘outer’ pieces of
the flake are mazes drawn in different colors.
hexaflake_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint",
"corner"), color1 = "black", color2 = "gray40", draw_boundary = FALSE,
num_boundary_holes = 2, boundary_lines = TRUE, boundary_holes = NULL,
boundary_hole_color = NULL, boundary_hole_locations = NULL,
boundary_hole_arrows = FALSE, end_side = 1)
the depth of recursion. This controls the side length. Should be an integer.
the unit length in graph coordinates. This controls the width of the ‘holes’ in the boundary lines and generally controls the spacing of mazes.
whether to draw clockwise.
whether to start from the midpoint of the first side of a maze, or from the corner facing the first side.
The dominant color of the maze.
The negative color of the maze.
a boolean indicating whether a final boundary shall be drawn around the maze.
the number of boundary sides which should be
randomly selected to have holes. Note that the boundary_holes
parameter takes precedence.
indicates which of the sides of the maze shall have drawn boundary lines. Can be a logical array indicating which sides shall have lines, or a numeric array, giving the index of sides that shall have lines.
an array indicating which of the boundary lines
have holes. If NULL
, then boundary holes are randomly selected
by the num_boundary_holes
parameter. If numeric, indicates
which sides of the maze shall have holes. If a boolean array, indicates
which of the sides shall have holes. These forms are recycled
if needed. See holey_path
. Note that if no line
is drawn, no hole can be drawn either.
the color of boundary holes. A value of
NULL
indicates no colored holes. See holey_path
for more details. Can be an array of colors, or colors and the
value 'clear'
, which stands in for NULL
to
indicate no filled hole to be drawn.
the ‘locations’ of the boundary holes
within each boundary segment.
A value of NULL
indicates the code may randomly choose, as is
the default.
May be a numeric array. A positive value up to the side length is
interpreted as the location to place the boundary hole.
A negative value is interpreted as counting down from the side
length plus 1. A value of zero corresponds to allowing the
code to pick the location within a segment.
A value of NA
may cause an error.
a boolean or boolean array indicating whether to draw perpendicular double arrows at the boundary holes, as a visual guide. These can be useful for locating the entry and exit points of a maze.
the number of the side to end on. A value of
1 corresponds to the starting side, while higher numbers
correspond to the drawn side of the figure in the canonical order
(that is, the order induced by the clockwise
parameter).
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Draws a maze in an Hexflake. Relies on generation of hexagonal and triangular mazes for the internals. An internal hexagon and six surrounding hexagons are recursively drawn as hexaflakes, connected by 12 equilateral triangles, drawn in the secondary color:
# NOT RUN {
library(TurtleGraphics)
turtle_init(1000,1000,mode='clip')
turtle_hide()
turtle_do({
turtle_setpos(50,500)
turtle_setangle(0)
hexaflake_maze(depth=3,unit_len=10,draw_boundary=TRUE,color2='green')
})
# }
Run the code above in your browser using DataLab