Title: | Generate Recursive Mazes |
---|---|
Description: | Supports the generation of parallelogram, equilateral triangle, regular hexagon, isosceles trapezoid, Koch snowflake, 'hexaflake', Sierpinski triangle, Sierpinski carpet and Sierpinski trapezoid mazes via 'TurtleGraphics'. Mazes are generated by the recursive method: the domain is divided into sub-domains in which mazes are generated, then dividing lines with holes are drawn between them, see J. Buck, Recursive Division, <http://weblog.jamisbuck.org/2011/1/12/maze-generation-recursive-division-algorithm>. |
Authors: | Steven E. Pav [aut, cre] |
Maintainer: | Steven E. Pav <[email protected]> |
License: | LGPL-3 |
Version: | 0.2.0.0001 |
Built: | 2024-11-04 02:47:22 UTC |
Source: | https://github.com/shabbychef/mazealls |
Draw a regular decagon maze, with each side consisting of
of pieces of length
unit_len
.
decagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("five_flower"), 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)
decagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("five_flower"), 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)
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. |
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 a few ways to recursively draw an decagon. The following values are acceptable:
|
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 |
Draws a maze in a regular decagon. Dissects the decagon into rhombuses.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
## Not run: turtle_init(2200,2200,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,1100) turtle_setangle(0) decagon_maze(5,21,draw_boundary=TRUE,boundary_holes=c(1,6)) }) ## End(Not run)
## Not run: turtle_init(2200,2200,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,1100) turtle_setangle(0) decagon_maze(5,21,draw_boundary=TRUE,boundary_holes=c(1,6)) }) ## End(Not run)
Draw a regular dodecagon maze, with each side consisting of
of pieces of length
unit_len
.
dodecagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("hex_ring"), 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)
dodecagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("hex_ring"), 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)
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. |
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 a few ways to recursively draw an decagon. The following values are acceptable:
|
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 |
Draws a maze in a regular dodecagon. Currently dissects the maze into a hexagon and a ring of squares and equilateral triangles.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
## Not run: turtle_init(2200,2200,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,1100) turtle_setangle(0) dodecagon_maze(5,21,draw_boundary=TRUE,boundary_holes=c(1,6)) }) ## End(Not run)
## Not run: turtle_init(2200,2200,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,1100) turtle_setangle(0) dodecagon_maze(5,21,draw_boundary=TRUE,boundary_holes=c(1,6)) }) ## End(Not run)
Recursively draw an equilateral triangle maze, with sides consisting
of pieces of length
unit_len
.
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)
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)
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:
|
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 |
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 segments
of length
unit_len
, though depth
may be non-integral.
A number of different methods are supported.
For method='uniform'
:
For method='triangles'
:
For method='two_ears'
:
For method='hex_and_three'
:
For method='shave'
:
For method='shave_all'
:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
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') })
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') })
Recursively draw a hexaflake maze, a cross between a Koch snowflake
and a Sierpinski triangle. The outer part of the flake consists of
a hexagon of side length pieces of length
unit_len
. The ‘inner’ and ‘outer’ pieces of
the flake are mazes drawn in different colors.
hexaflake_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), color1 = "black", color2 = "gray40", 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)
hexaflake_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), color1 = "black", color2 = "gray40", 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)
depth |
the depth of recursion. This controls the side length. Should be an integer. |
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. |
color1 |
The dominant color of the maze. |
color2 |
The negative color of the maze. |
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 |
Draws a maze in an Hexflake. Relies on generation of hexagonal and triangular mazes for the internals. An internal hexagon and six surrounding hexagons are recursively drawn as hexaflakes, connected by 12 equilateral triangles, drawn in the secondary color:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() turtle_do({ turtle_setpos(50,500) turtle_setangle(0) hexaflake_maze(depth=3,unit_len=10,draw_boundary=TRUE,color2='green') })
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() turtle_do({ turtle_setpos(50,500) turtle_setangle(0) hexaflake_maze(depth=3,unit_len=10,draw_boundary=TRUE,color2='green') })
Recursively draw a regular hexagon, with sides consisting
of pieces of length
unit_len
.
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)
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)
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 |
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 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'
:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
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) } })
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) } })
Draws a line with a randomly selected ‘hole’ in it.
holey_line(unit_len, num_segs, which_seg = NULL, go_back = FALSE, hole_color = NULL, hole_arrow = FALSE)
holey_line(unit_len, num_segs, which_seg = NULL, go_back = FALSE, hole_color = NULL, hole_arrow = FALSE)
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. |
num_segs |
the total number of segments. All but one of these,
of length |
which_seg |
optional numeric indicating which segment should
have the hole. If |
go_back |
whether to return the turtle to starting position when the line has been drawn. |
hole_color |
the color to plot the ‘hole’. A
|
hole_arrow |
a boolean or indicating whether to draw a perpendicular arrow at a hole. |
This function is the workhorse of drawing mazes, as it creates a maze wall with a single hole in it.
Returns the which_seg
variable, the location of the hole, though typically
the function is called for side effects only.
Steven E. Pav [email protected]
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() y <- holey_line(unit_len=20, num_segs=15) turtle_right(90) y <- holey_line(unit_len=20, num_segs=10,hole_arrow=TRUE)
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() y <- holey_line(unit_len=20, num_segs=15) turtle_right(90) y <- holey_line(unit_len=20, num_segs=10,hole_arrow=TRUE)
Make the turtle move multiple units, making turns, and possibly drawing line segments possibly with holes in them.
holey_path(unit_len, lengths, angles, draw_line = TRUE, has_hole = FALSE, hole_color = NULL, hole_locations = NULL, hole_arrows = FALSE)
holey_path(unit_len, lengths, angles, draw_line = TRUE, has_hole = FALSE, hole_color = NULL, hole_locations = NULL, hole_arrows = FALSE)
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. |
lengths |
an array of the number of units
each part of the path. An array of length |
angles |
after each part of the path is drawn, the turtle turns right by the given angle. |
draw_line |
a boolean array telling whether each part of the path is drawn at all, or whether the turtle simply moves through that path. |
has_hole |
a boolean array telling whether, conditional on the path being drawn, it has a one unit hole. |
hole_color |
the color to plot the ‘hole’.
A value |
hole_locations |
an optional array of ‘locations’
of the holes. These affect the |
hole_arrows |
a boolean or boolean array telling whether to draw a perpendicular arrow at a hole. |
Causes the turtle to move through a path of connected line segments,
possibly drawing lines, possibly drawing holes in those lines.
All arguments are recycled to the length of the longest
argument via mapply
, which simplifies
the path description.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
library(TurtleGraphics) # draw a triangle with holes on the boundaries turtle_init(1000,1000) holey_path(unit_len=20, lengths=rep(10,3), angles=c(120), draw_line=TRUE, has_hole=TRUE) # draw a square with holes on the boundaries turtle_init(1000,1000) turtle_hide() holey_path(unit_len=20, lengths=rep(10,4), angles=c(90), draw_line=TRUE, has_hole=TRUE, hole_color=c('red','green')) # draw a square spiral turtle_init(1000,1000) turtle_hide() holey_path(unit_len=20, lengths=sort(rep(1:10,2),decreasing=TRUE), angles=c(90), draw_line=TRUE, has_hole=FALSE)
library(TurtleGraphics) # draw a triangle with holes on the boundaries turtle_init(1000,1000) holey_path(unit_len=20, lengths=rep(10,3), angles=c(120), draw_line=TRUE, has_hole=TRUE) # draw a square with holes on the boundaries turtle_init(1000,1000) turtle_hide() holey_path(unit_len=20, lengths=rep(10,4), angles=c(90), draw_line=TRUE, has_hole=TRUE, hole_color=c('red','green')) # draw a square spiral turtle_init(1000,1000) turtle_hide() holey_path(unit_len=20, lengths=sort(rep(1:10,2),decreasing=TRUE), angles=c(90), draw_line=TRUE, has_hole=FALSE)
Recursively draw a isosceles trapezoid maze, with three sides consisting
of pieces of length
unit_len
, and one long
side of length pieces, starting from the
long side.
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)
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)
depth |
the depth of recursion. This controls the
side length: three sides have |
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:
|
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 |
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 segments
of length
unit_len
, while the longer has .
A number of different methods are supported.
For
method='four_trapezoids'
:
For method='one_ear'
:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
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')) })
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')) })
Recursively draw an Koch snowflake maze. The inner part of the snowflake
maze consists of an equilateral triangle of side length
pieces of length
unit_len
.
koch_maze(depth, unit_len, clockwise = TRUE, draw_boundary = TRUE, 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)
koch_maze(depth, unit_len, clockwise = TRUE, draw_boundary = TRUE, 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)
depth |
the depth of recursion. This controls the side length. Should be an integer. |
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. |
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 |
Draws a maze in an Koch snowflake, starting from the corner of the
first side. Relies on generation of triangular mazes for the internals.
The triangular part has sides consisting of 3^depth
segments
of length unit_len
.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
library(TurtleGraphics) turtle_init(2000,2000) turtle_hide() turtle_up() set.seed(1234) turtle_do({ turtle_backward(distance=400) turtle_left(90) turtle_forward(650) turtle_right(90) turtle_right(30) koch_maze(depth=3,unit_len=14) })
library(TurtleGraphics) turtle_init(2000,2000) turtle_hide() turtle_up() set.seed(1234) turtle_do({ turtle_backward(distance=400) turtle_left(90) turtle_forward(650) turtle_right(90) turtle_right(30) koch_maze(depth=3,unit_len=14) })
Generate recursive mazes.
Recursive generation of mazes proceeds roughly as follows: subdivide the domain logicall into two or more parts, creating mazes in the sub-parts, then drawing dividing lines between them with some holes. The holes in the dividing lines should be constructed so that the sub-parts form a tree, with exactly one way to get from one of the sub-parts to any one of the others. Then an optional outer boundary with optional holes is drawn to finish the maze.
The unit_len
parameter controls the graphical length of one ‘unit’,
which is the length of holes between sections of the mazes, and is roughly the width
of the ‘hallways’ of a maze. Here is an example of using different
unit lengths in a stack of trapezoids
The parameters draw_boundary
, boundary_lines
, boundary_holes
,
num_boundary_holes
and boundary_hole_color
control
the drawing of the final outer boundary of polynomial mazes. Without a boundary
the maze can be used in recursive construction. Adding a boundary provides the
typical entry and exit points of a maze. The parameter draw_boundary
is a
single Boolean that controls whether the boundary is drawn or not.
The parameter boundary_lines
may be a scalar Boolean, or a numeric
array giving the indices of which sides should have drawn boundary lines.
The sides are numbered in the order in which they appear, and are
controlled by the clockwise
parameter. The parameter boundary_holes
is a numeric array giving the indices of the boundary lines that should
have holes. If NULL
, then we uniformly choose num_boundary_holes
holes
at random. Holes can be drawn as colored segments with the
boundary_hole_color
, which is a character array giving the color of each
hole. The value 'clear' stands in for clear holes.
Arrows can optionally be drawn at the boundary holes via the
boundary_hole_arrows
parameter, which is either a logical array or a
numerical array indicating which sides should have boundary hole arrows.
The end_side
parameter controls which side of the maze the turtle ends on.
The default value of 1 essentially causes the turtle to end where it
started. The sides are numbered in the order in which the boundary would be
drawn. Along with the boundary controls, the ending side can be useful to join together
polygons into more complex mazes.
mazealls is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
This package is dedicated to my friend, Abie Flaxman, who gave me the idea, and other ideas.
If you like this package, please endorse the author for ‘mazes’ on LinkedIn.
Steven E. Pav [email protected]
News for package ‘mazealls’
adding Sierpinski hexagon mazes.
adding octagon, decagon and dodecagon mazes.
adding Sierpinski triangle, carpet and trapezoid mazes.
adding hexaflake maze.
adding option to draw arrows at boundary holes.
adding boustrophedon factor to parallelogram, triangle, trapezoid, hexagon mazes.
first CRAN release.
Draw a regular octagon maze, with each side consisting of
of pieces of length
unit_len
.
octagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("ammann_beenker"), 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)
octagon_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), method = c("ammann_beenker"), 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)
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. |
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 a few ways to recursively draw an octagon. The following values are acceptable:
|
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 |
Draws a maze in a regular octagon via dissection into rhombuses.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
## Not run: turtle_init(2000,2000,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(75,1000) turtle_setangle(0) octagon_maze(6,12,draw_boundary=TRUE) }) ## End(Not run)
## Not run: turtle_init(2000,2000,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(75,1000) turtle_setangle(0) octagon_maze(6,12,draw_boundary=TRUE) }) ## End(Not run)
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.
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)
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)
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 |
width |
the length of the second side in numbers of |
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:
|
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 |
height_boustro |
an array of two values, which help determine
the location of holes in internal lines of length
|
width_boustro |
an array of two values, which help determine
the location of any split along lines which are 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 |
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:
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:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
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) })
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) })
Recursively draw a Sierpinski carpet maze in a parallelogram,
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.
sierpinski_carpet_maze(unit_len, height, width = height, angle = 90, clockwise = TRUE, method = "random", color1 = "black", color2 = "gray40", start_from = c("midpoint", "corner"), balance = 0, 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)
sierpinski_carpet_maze(unit_len, height, width = height, angle = 90, clockwise = TRUE, method = "random", color1 = "black", color2 = "gray40", start_from = c("midpoint", "corner"), balance = 0, 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)
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 |
width |
the length of the second side in numbers of |
angle |
the angle (in degrees) between the first and second sides. |
clockwise |
whether to draw clockwise. |
method |
passed to |
color1 |
The dominant color of the maze. |
color2 |
The negative color of the maze. |
start_from |
whether to start from the midpoint of the first side of a maze, or from the corner facing the first side. |
balance |
passed to |
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 |
Draws a Sierpinski carpet as two-color maze in a parallelogram.
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
parallelogram_maze
,
sierpinski_maze
.
library(TurtleGraphics) turtle_init(800,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(35,400) turtle_setangle(0) sierpinski_carpet_maze(angle=80,unit_len=8,width=30,height=30, method='two_parallelograms',draw_boundary=TRUE,balance=-1.0,color2='green') }) ## Not run: library(TurtleGraphics) turtle_init(2000,2000,mode='clip') turtle_hide() turtle_up() bholes <- list(c(1,2), c(1), c(2)) turtle_do({ turtle_setpos(1000,1100) turtle_setangle(180) for (iii in c(1:3)) { mybhol <- bholes[[iii]] sierpinski_carpet_maze(angle=120,unit_len=12,width=81,height=81, draw_boundary=TRUE,boundary_lines=c(1,2,3),num_boundary_holes=0, boundary_holes=mybhol,balance=1.0,color2='green', start_from='corner') turtle_left(120) } }) ## End(Not run)
library(TurtleGraphics) turtle_init(800,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(35,400) turtle_setangle(0) sierpinski_carpet_maze(angle=80,unit_len=8,width=30,height=30, method='two_parallelograms',draw_boundary=TRUE,balance=-1.0,color2='green') }) ## Not run: library(TurtleGraphics) turtle_init(2000,2000,mode='clip') turtle_hide() turtle_up() bholes <- list(c(1,2), c(1), c(2)) turtle_do({ turtle_setpos(1000,1100) turtle_setangle(180) for (iii in c(1:3)) { mybhol <- bholes[[iii]] sierpinski_carpet_maze(angle=120,unit_len=12,width=81,height=81, draw_boundary=TRUE,boundary_lines=c(1,2,3),num_boundary_holes=0, boundary_holes=mybhol,balance=1.0,color2='green', start_from='corner') turtle_left(120) } }) ## End(Not run)
Draws a Sierpinski hexagon maze.
sierpinski_hexagon_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), style = c("sierpinski", "four_triangles", "hexaflake", "reverse_flake", "outer_flake", "dragon_left", "dragon_right", "dragon_leftright", "dragon_rightleft"), color1 = "black", color2 = "gray40", 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)
sierpinski_hexagon_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), style = c("sierpinski", "four_triangles", "hexaflake", "reverse_flake", "outer_flake", "dragon_left", "dragon_right", "dragon_leftright", "dragon_rightleft"), color1 = "black", color2 = "gray40", 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)
depth |
the depth of recursion. This controls the side length. Should be an integer. |
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. |
style |
controls the style of Sierpinski triangle. The following are recognized:
|
color1 |
The dominant color of the maze. |
color2 |
The negative color of the maze. |
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 |
Recursively draw a Sierpinski hexagon maze. The sides of the
hexagon consist of pieces of length
unit_len
. The hexagon is drawn as a ring of six
Sierpinski trapezoids in a ring around a Sierpinski
hexagon of a smaller size.
The ‘inner’ and ‘outer’ pieces of
mazes drawn in different colors. The
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
eq_triangle_maze
,
hexaflake_maze
,
sierpinski_carpet_maze
,
sierpinski_trapezoid_maze
.
library(TurtleGraphics) turtle_init(800,800,mode='clip') turtle_up() turtle_hide() turtle_do({ turtle_setpos(50,400) turtle_setangle(30) sierpinski_hexagon_maze(depth=4,unit_len=20,boundary_lines=TRUE, draw_boundary=TRUE,boundary_holes=c(1,3), start_from='corner', color1='black',color2='green', style='sierpinski') })
library(TurtleGraphics) turtle_init(800,800,mode='clip') turtle_up() turtle_hide() turtle_do({ turtle_setpos(50,400) turtle_setangle(30) sierpinski_hexagon_maze(depth=4,unit_len=20,boundary_lines=TRUE, draw_boundary=TRUE,boundary_holes=c(1,3), start_from='corner', color1='black',color2='green', style='sierpinski') })
Recursively draw a Sierpinski triangle maze. The sides of the
triangle consist of pieces of length
unit_len
.
The ‘inner’ and ‘outer’ pieces of
the flake are mazes drawn in different colors.
sierpinski_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), method = "random", style = c("four_triangles", "hexaflake", "dragon_left", "dragon_right"), color1 = "black", color2 = "gray40", 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)
sierpinski_maze(depth, unit_len, clockwise = TRUE, start_from = c("midpoint", "corner"), method = "random", style = c("four_triangles", "hexaflake", "dragon_left", "dragon_right"), color1 = "black", color2 = "gray40", 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)
depth |
the depth of recursion. This controls the side length. Should be an integer. |
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 |
controls the method to draw the underlying
equilateral triangles. See |
style |
controls the style of Sierpinski triangle. The following are recognized:
|
color1 |
The dominant color of the maze. |
color2 |
The negative color of the maze. |
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 |
Draws a maze in an Sierpinski equilateral Triangle. The inner quarter is
drawn in the secondary color, while the outer three quarters are drawn
recursively. This is the traditional Sierpinski Triangle, generated when
style=='four_triangles'
:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
eq_triangle_maze
,
hexaflake_maze
,
sierpinski_carpet_maze
,
sierpinski_trapezoid_maze
,
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_up() turtle_hide() turtle_do({ turtle_setpos(10,500) turtle_setangle(0) sierpinski_maze(depth=5,unit_len=19,boundary_lines=TRUE, boundary_holes=c(1,3),color1='black',color2='gray60') })
library(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_up() turtle_hide() turtle_do({ turtle_setpos(10,500) turtle_setangle(0) sierpinski_maze(depth=5,unit_len=19,boundary_lines=TRUE, boundary_holes=c(1,3),color1='black',color2='gray60') })
Recursively draw a Sierpinski isosceles trapezoid maze,
with three sides consisting
of pieces of length
unit_len
, and one long
side of length pieces, starting from the
long side.
sierpinski_trapezoid_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), color1 = "black", color2 = "gray40", flip_color_parts = 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)
sierpinski_trapezoid_maze(depth, unit_len = 4L, clockwise = TRUE, start_from = c("midpoint", "corner"), color1 = "black", color2 = "gray40", flip_color_parts = 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)
depth |
the depth of recursion. This controls the
side length: three sides have |
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. |
color1 |
The dominant color of the maze. |
color2 |
The negative color of the maze. |
flip_color_parts |
a numerical array which can contain values 1
through 4. Those parts of the maze, when drawn recursively, have
their colors flipped. A value of |
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 |
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). Differently colors the parts of the
maze for a Sierpinski effect.
Here are mazes for different values of flip_color_parts
ranging
from 1 to 4:
nothing; the function is called for side effects only, though in the future this might return information about the drawn boundary of the shape.
Steven E. Pav [email protected]
iso_trapezoid_maze
,
hexaflake_maze
,
sierpinski_carpet_maze
,
sierpinski_maze
.
require(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(500,500) turtle_setangle(0) sierpinski_trapezoid_maze(unit_len=15,depth=4,color1='black',color2='green', clockwise=TRUE,draw_boundary=TRUE,boundary_holes=c(1,3)) sierpinski_trapezoid_maze(unit_len=15,depth=4,color1='black',color2='green', clockwise=FALSE,draw_boundary=TRUE, boundary_lines=c(2,3,4),boundary_holes=3) }) # stack some trapezoids! require(TurtleGraphics) turtle_init(750,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,450) turtle_setangle(0) blines <- c(1,2,4) for (dep in seq(from=4,to=0)) { sierpinski_trapezoid_maze(unit_len=13,depth=dep,color1='black',color2='green', flip_color_parts=2, clockwise=TRUE,boundary_lines=blines,draw_boundary=TRUE,boundary_holes=c(1,3), end_side=3) turtle_right(180) blines <- c(1,2,4) } }) ## Not run: require(TurtleGraphics) turtle_init(750,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,450) turtle_setangle(0) blines <- c(1,2,4) for (dep in seq(from=5,to=0)) { sierpinski_trapezoid_maze(unit_len=13,depth=dep,color1='black',color2='green', flip_color_parts=3, clockwise=TRUE,boundary_lines=blines,draw_boundary=TRUE,boundary_holes=c(1,3), end_side=3) turtle_right(180) blines <- c(1,2,4) } }) ## End(Not run)
require(TurtleGraphics) turtle_init(1000,1000,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(500,500) turtle_setangle(0) sierpinski_trapezoid_maze(unit_len=15,depth=4,color1='black',color2='green', clockwise=TRUE,draw_boundary=TRUE,boundary_holes=c(1,3)) sierpinski_trapezoid_maze(unit_len=15,depth=4,color1='black',color2='green', clockwise=FALSE,draw_boundary=TRUE, boundary_lines=c(2,3,4),boundary_holes=3) }) # stack some trapezoids! require(TurtleGraphics) turtle_init(750,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,450) turtle_setangle(0) blines <- c(1,2,4) for (dep in seq(from=4,to=0)) { sierpinski_trapezoid_maze(unit_len=13,depth=dep,color1='black',color2='green', flip_color_parts=2, clockwise=TRUE,boundary_lines=blines,draw_boundary=TRUE,boundary_holes=c(1,3), end_side=3) turtle_right(180) blines <- c(1,2,4) } }) ## Not run: require(TurtleGraphics) turtle_init(750,900,mode='clip') turtle_hide() turtle_up() turtle_do({ turtle_setpos(25,450) turtle_setangle(0) blines <- c(1,2,4) for (dep in seq(from=5,to=0)) { sierpinski_trapezoid_maze(unit_len=13,depth=dep,color1='black',color2='green', flip_color_parts=3, clockwise=TRUE,boundary_lines=blines,draw_boundary=TRUE,boundary_holes=c(1,3), end_side=3) turtle_right(180) blines <- c(1,2,4) } }) ## End(Not run)