Description Usage Arguments Details Value Author(s) Examples
View source: R/eq_triangle_maze.r
Recursively draw an equilateral triangle maze, with sides consisting
of 2^{depth} pieces of length unit_len
.
1 2 3 4 5 6 7  eq_triangle_maze(depth, unit_len, clockwise = TRUE,
method = c("stack_trapezoids", "triangles", "uniform", "two_ears", "random",
"hex_and_three", "shave_all", "shave"), start_from = c("midpoint",
"corner"), boustro = c(1, 1), 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)

depth 
the depth of recursion. This controls the side length. 
unit_len 
the unit length in graph coordinates. This controls the width of the ‘holes’ in the boundary lines and generally controls the spacing of mazes. 
clockwise 
whether to draw clockwise. 
method 
there are many ways to recursive draw a triangle. The following values are acceptable:

start_from 
whether to start from the midpoint of the first side of a maze, or from the corner facing the first side. 
boustro 
an array of two values, which help determine
the location of holes in internal lines of length

draw_boundary 
a boolean indicating whether a final boundary shall be drawn around the maze. 
num_boundary_holes 
the number of boundary sides which should be
randomly selected to have holes. Note that the 
boundary_lines 
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. 
boundary_holes 
an array indicating which of the boundary lines
have holes. If 
boundary_hole_color 
the color of boundary holes. A value of

boundary_hole_locations 
the ‘locations’ of the boundary holes
within each boundary segment.
A value of 
boundary_hole_arrows 
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. 
end_side 
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 
Draws a maze in an equilateral triangle, starting from the midpoint
of the first side (or the corner before the first side via the
start_from
option). A number of different recursive methods
are supported, dividing the triangle into subtriangles, or hexagons,
parallelogram and triangles, and so on. Optionally draws boundaries
around the triangle, with control over which sides have lines and
holes. Side length of triangles consists of 2^{depth} segments
of length unit_len
, though depth
may be nonintegral.
A number of different methods are supported.
For method='uniform'
:
For method='triangles'
:
For method='two_ears'
:
For method='hex_and_three'
:
For method='shave'
:
For method='shave_all'
:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav shabbychef@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  library(TurtleGraphics)
turtle_init(2500,2500)
turtle_hide()
turtle_up()
turtle_do({
turtle_left(90)
turtle_forward(40)
turtle_right(90)
eq_triangle_maze(depth=3,12,clockwise=FALSE,method='two_ears',draw_boundary=TRUE)
})
turtle_init(2500,2500)
turtle_hide()
turtle_up()
turtle_do({
turtle_left(90)
turtle_forward(40)
turtle_right(90)
eq_triangle_maze(depth=3,12,clockwise=FALSE,method='random',draw_boundary=TRUE)
})
# join two together, with green holes on opposite sides
turtle_init(2500,2500)
turtle_hide()
turtle_up()
turtle_do({
turtle_left(90)
turtle_forward(40)
turtle_right(90)
eq_triangle_maze(depth=3,12,clockwise=TRUE,method='two_ears',draw_boundary=TRUE,
boundary_holes=c(1,3),boundary_hole_color=c('clear','clear','green'))
eq_triangle_maze(depth=3,12,clockwise=FALSE,method='uniform',draw_boundary=TRUE,
boundary_lines=c(2,3),boundary_holes=c(2),boundary_hole_color='green')
})
# non integral depths also possible:
turtle_init(2500,2500)
turtle_hide()
turtle_up()
turtle_do({
turtle_left(90)
turtle_forward(40)
turtle_right(90)
eq_triangle_maze(depth=log2(27),12,clockwise=TRUE,method='hex_and_three',draw_boundary=TRUE,
boundary_holes=c(1,3),boundary_hole_color=c('clear','clear','green'))
eq_triangle_maze(depth=log2(27),12,clockwise=FALSE,method='shave',draw_boundary=TRUE,
boundary_lines=c(2,3),boundary_holes=c(2),boundary_hole_color='green')
})

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.