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:

two_trapezoids

Two isosceles trapezoids are placed next to each other, with a holey line between them.

size_triangles

Six equilateral triangles are packed together, with five holey lines and one solid line.

three_parallelograms

Three parallelograms are packed together, with two holey lines and one solid line between them.

random

A method is chosen uniformly at random.

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 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 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':

Figure: two trapezoids

For method='six_trapezoids':

Figure: six triangles

For method='three_trapezoids':

Figure: three parallelograms

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)
	}
})

[Package mazealls version 0.2.0 Index]