hexagon_maze {mazealls} | R Documentation |
hexagon_maze .
Description
Recursively draw a regular hexagon, with sides consisting
of 2^{depth}
pieces of length unit_len
.
Usage
hexagon_maze(depth, unit_len, clockwise = TRUE, method = c("two_trapezoids",
"six_triangles", "three_parallelograms", "random"),
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)
Arguments
depth |
the depth of recursion. This controls the side length. If an integer then nice recursive mazes are possible, but non-integral values corresponding to log base 2 of integers are also acceptable. |
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 an isosceles trapezoid. 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 |
Details
Draws a maze in a regular hexagon, 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 trapezoids, triangles
or parallelograms. Optionally draws boundaries
around the hexagon, with control over which sides have lines and
holes. Sides of the hexagon consist of 2^{depth}
segments
of length unit_len
, though depth
may be non-integral.
A number of different methods are supported.
For method='two_trapezoids'
:
For method='six_trapezoids'
:
For method='three_trapezoids'
:
Value
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Author(s)
Steven E. Pav shabbychef@gmail.com
Examples
library(TurtleGraphics)
turtle_init(2000,2000)
turtle_hide()
turtle_do({
turtle_up()
turtle_backward(250)
turtle_right(90)
turtle_forward(150)
turtle_left(90)
turtle_right(60)
hexagon_maze(depth=3,12,clockwise=FALSE,method='six_triangles',
draw_boundary=TRUE,boundary_holes=c(1,4),boundary_hole_color='green')
})
turtle_init(2000,2000)
turtle_hide()
turtle_do({
turtle_up()
turtle_backward(250)
turtle_right(90)
turtle_forward(150)
turtle_left(90)
turtle_right(60)
hexagon_maze(depth=log2(20),12,clockwise=FALSE,method='six_triangles',
draw_boundary=TRUE,boundary_holes=c(1,4),boundary_hole_color='green')
})
turtle_init(1000,1000)
turtle_hide()
turtle_do({
turtle_up()
turtle_backward(250)
turtle_right(90)
turtle_forward(150)
turtle_left(90)
turtle_right(60)
hexagon_maze(depth=3,12,clockwise=FALSE,method='three_parallelograms',
draw_boundary=TRUE,boundary_holes=c(1,4),boundary_hole_color='green')
})
turtle_init(1000,1000)
turtle_hide()
turtle_do({
hexagon_maze(depth=3,15,clockwise=TRUE,method='two_trapezoids',
draw_boundary=TRUE,boundary_holes=c(1,4))
hexagon_maze(depth=3,15,clockwise=FALSE,method='two_trapezoids',
draw_boundary=TRUE,boundary_lines=c(2,3,4,5,6),boundary_holes=c(1,4))
})
turtle_init(1000,1000)
turtle_hide()
turtle_do({
depth <- 3
num_segs <- 2^depth
unit_len <- 8
multiplier <- -1
hexagon_maze(depth=depth,unit_len,clockwise=FALSE,method='two_trapezoids',
draw_boundary=FALSE)
for (iii in c(1:6)) {
if (iii %in% c(1,4)) {
holes <- c(1,4)
} else {
holes <- c(1)
}
hexagon_maze(depth=depth,unit_len,clockwise=TRUE,method='two_trapezoids',
draw_boundary=TRUE,boundary_holes=holes)
turtle_forward(distance=unit_len * num_segs/2)
turtle_right((multiplier * 60) %% 360)
turtle_forward(distance=unit_len * num_segs/2)
}
})