eq_triangle_maze: eq_triangle_maze .

View source: R/eq_triangle_maze.r

eq_triangle_mazeR Documentation

eq_triangle_maze .

Description

Recursively draw an equilateral triangle maze, with sides consisting of 2^{depth} pieces of length unit_len.

Usage

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)

Arguments

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:

stack_trapezoids

Isosceles trapezoids are stacked on top of each other, with the long sides aligned to the first side.

triangles

The triangle maze is recursively drawn as four equilateral triangle mazes of half size, each connected to their neighbors.

uniform

The triangle maze is recursively drawn as four equilateral triangle uniform mazes of half size, each connected to their neighbors.

two_ears

The triangle maze is recursively drawn as a large parallelogram maze connected to two two half size equilateral triangle mazes, which are ‘ears’.

random

A method is randomly selected from the available methods.

hex_and_three

When 2^{depth} is a power of three, the triangle is drawn as a hexagonal maze of one third size connected to three equilateral triangular mazes, each one third size, at the corners.

shave

Here 2^{depth} can be arbitrary. A single line is ‘shaved’ off the triangle, connected to another equilateral triangle of length one less is drawn next to it. This sub triangle will either be drawn using a ‘hex_and_three’, ‘random’, or ‘shave’ methods, in decreasing order of preference, depending on the side length.

shave_all

Here 2^{depth} can be arbitrary. A single line is ‘shaved’ off the triangle, connected to another equilateral triangle of length one less is drawn next to it. This sub triangle will also be drawn using the ‘shave_all’ method. These mazes tend to look boring, and are not recommended.

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 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 sub-triangles, 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 non-integral. A number of different methods are supported.

For method='uniform':

Figure: uniform

For method='triangles':

Figure: triangles

For method='two_ears':

Figure: two ears

For method='hex_and_three':

Figure: hex and three triangles

For method='shave':

Figure: shave

For method='shave_all':

Figure: shave all

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

shabbychef/mazealls documentation built on Oct. 18, 2023, 8:27 p.m.