parallelogram_maze {mazealls}R Documentation

parallelogram_maze .

Description

Recursively draw a parallelogram maze, with the first side consisting of height segments of length unit_len, and the second side width segments of length unit_len. The angle between the first and second side may be set.

Usage

parallelogram_maze(unit_len, height, width = height, angle = 90,
  clockwise = TRUE, method = c("two_parallelograms", "four_parallelograms",
  "uniform", "random"), start_from = c("midpoint", "corner"), balance = 0,
  height_boustro = c(1, 1), width_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

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.

height

the length of the first side in numbers of unit_len segments.

width

the length of the second side in numbers of unit_len segments.

angle

the angle (in degrees) between the first and second sides. Note that this is the angle that the Turtle turns when rounding the first corner, so it is the internal angle at the starting point (if starting from a corner), and the external angle at the second corner.

clockwise

whether to draw clockwise.

method

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

two_parallelograms

The parallelogram maze is built as two parallelogram mazes with a holey line between them.

four_parallelograms

The parallelogram maze is built as four parallelogram mazes with three holey lines and one solid line between them.

uniform

The parallelogram maze is built as four parallelogram mazes with three holey lines and one solid line between them. Sub-mazes are chosen to be nearly equal in size.

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.

balance

for the two_parallelograms method, we choose whether to split on height or width based on a balance condition. The log odds of choosing height over width is the factor balance times the sign of the difference height - width. When balance takes the default value of 0, you have equal odds of selecting to split on height or width. Note that balance is positive and large, you tend to generate nearly uniform splits. When balance is negative and large, you tend to have imbalanced mazes, and the imbalance propagates.

height_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 shape1 and shape2 the two elements of height_boustro in order. In sub mazes, this parameter is reversed, which can lead to ‘boustrophedonic’ mazes. The sum of values should probably not exceed 30, as otherwise the location of internal holes is forced.

width_boustro

an array of two values, which help determine the location of any split along lines which are length width.

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 parallelogram, starting from the midpoint of the first side (or the corner before the first side via the start_from option). Can recursively subdivide into two or four parallelograms. The first (and third) side shall consist of height segments of length unit_len. The second and fourth side consist of width segments of length unit_len. The angle between them is angle. Here is an example maze:

Figure: parallelogram maze

This function admits a balance parameter which controls how the maze should be recursively subdivided. A negative value creates imbalanced mazes, while positive values create more uniform mazes. Here are create seven mazes created side by side with an increasing balance parameter:

Figure: parallelogram maze

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(500,300,mode='clip')
turtle_hide()
turtle_up()
turtle_do({
 turtle_setpos(15,15)
 turtle_setangle(0)
 parallelogram_maze(angle=90,unit_len=10,width=45,height=25,method='uniform',
 	start_from='corner',draw_boundary=TRUE)
})

# testing imbalance condition
turtle_init(400,500,mode='clip')
turtle_hide()
turtle_up()
turtle_do({
 turtle_setpos(15,250)
 turtle_setangle(0)
 parallelogram_maze(angle=90,unit_len=10,width=30,height=40,
   method='two_parallelograms',draw_boundary=TRUE,balance=-1.0)
})

# a bunch of imbalanced mazes, fading into each other
turtle_init(850,400,mode='clip')
turtle_hide()
turtle_up()
turtle_do({
  turtle_setpos(15,200)
  turtle_setangle(0)
  valseq <- seq(from=-1.5,to=1.5,length.out=4)
  blines <- c(1,2,3,4)
  bholes <- c(1,3)
  set.seed(12354)
  for (iii in seq_along(valseq)) {
     parallelogram_maze(angle=90,unit_len=10,width=20,height=25,
      method='two_parallelograms',draw_boundary=TRUE,balance=valseq[iii],
       end_side=3,boundary_lines=blines,boundary_holes=bholes)
     turtle_right(180)
     blines <- c(2,3,4)
     bholes <- c(3)
  }
})

# a somewhat 'boustrophedonic' maze
turtle_init(500,300,mode='clip')
turtle_hide()
turtle_up()
turtle_do({
 turtle_setpos(15,15)
 turtle_setangle(0)
 parallelogram_maze(angle=90,unit_len=10,width=47,height=27,
    method='two_parallelograms', height_boustro=c(21,3),width_boustro=c(21,3),balance=-0.25,
		 start_from='corner',draw_boundary=TRUE)
})

[Package mazealls version 0.2.0 Index]