iso_trapezoid_maze {mazealls}R Documentation

iso_trapezoid_maze .

Description

Recursively draw a isosceles trapezoid maze, with three sides consisting of 2^{depth} pieces of length unit_len, and one long side of length 2^{depth+1} pieces, starting from the long side.

Usage

iso_trapezoid_maze(depth, unit_len = 4L, clockwise = TRUE,
  start_from = c("midpoint", "corner"), method = c("four_trapezoids",
  "one_ear", "random"), 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: three sides have round(2^depth) segments of length unit_len, while the long side is twice as long. depth need not be integral.

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.

start_from

whether to start from the midpoint of the first side of a maze, or from the corner facing the first side.

method

there are many ways to recursive draw an isosceles trapezoid. The following values are acceptable:

four_trapezoids

Four isosceles trapezoids are packed around each other with a ‘bone’ between them.

one_ear

A parallelogram is placed next to an equilateral triangle (an ‘ear’). Note this method is acceptable when depth is not an integer.

random

A method is chosen uniformly at random.

boustro

an array of two values, which help determine the location of holes in internal lines of length height. The default value, c(1,1) results in uniform selection. Otherwise the location of holes are chosen with probability proportional to a beta density with the ordered elements of boustro set as shape1 and shape2. In sub mazes, this parameter is reversed, which can lead to ‘boustrophedonic’ mazes. It is suggested that the sum of values not exceed 40, as otherwise the location of internal holes may be not widely dispersed from the mean value.

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_holes parameter takes precedence.

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 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.

boundary_hole_color

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.

boundary_hole_locations

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.

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 clockwise parameter).

Details

Draws a maze in an isoscelese trapezoid with three sides of equal length and one long side of twice that length, starting from the midpoint of the long side (or the corner before the first side via the start_from option). A number of different recursive methods are supported. Optionally draws boundaries around the trapezoid, with control over which sides have lines and holes. Three sides of the trapezoid consist of 2^{depth} segments of length unit_len, while the longer has 2^{depth}. A number of different methods are supported. For method='four_trapezoids':

Figure: four trapezoids

For method='one_ear':

Figure: one ear

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(1000,1000)
turtle_hide() 
iso_trapezoid_maze(depth=4,20,clockwise=FALSE,draw_boundary=TRUE)

turtle_init(1000,1000)
turtle_hide() 
turtle_do({
iso_trapezoid_maze(depth=3,20,clockwise=TRUE,draw_boundary=TRUE,boundary_holes=3)
})

turtle_init(2000,2000)
turtle_hide() 
turtle_up()
turtle_do({
	len <- 22
	iso_trapezoid_maze(depth=log2(len),15,clockwise=TRUE,draw_boundary=TRUE,
	  boundary_holes=c(1,3),method='one_ear',
	  boundary_hole_color=c('clear','clear','green','clear'))
	iso_trapezoid_maze(depth=log2(len),15,clockwise=FALSE,draw_boundary=TRUE,
	  boundary_lines=c(2,3,4),boundary_holes=c(2),method='one_ear',
	  boundary_hole_color=c('red'))
})

[Package mazealls version 0.2.0 Index]