holey_path: holey_path .

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/holey_path.r

Description

Make the turtle move multiple units, making turns, and possibly drawing line segments possibly with holes in them.

Usage

1
2
holey_path(unit_len, lengths, angles, draw_line = TRUE, has_hole = FALSE,
  hole_color = NULL, hole_locations = NULL, hole_arrows = FALSE)

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.

lengths

an array of the number of units each part of the path. An array of length n.

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 NULL or 'clear' corresponds to no drawn hole, the latter being useful for mixing drawn colored holes with no hole drawn at all (for which 'white' would be an acceptable choice if the background were white). Filled holes are often useful for indicating the entry and exit points of a maze. See the colors function for acceptable values.

hole_locations

an optional array of ‘locations’ of the holes. These affect the which_seg of any holey lines which are drawn. If an array of numeric values, a value of zero corresponds to allowing the code to randomly choose the location of a hole; negative values are ‘inverted’ by adding length + 1, so that if the same segment is drawn twice, in different directions, only the sign of the hole location needs to be flipped to have aligned holes. NA values will throw an error for now, though this may change in the future.

hole_arrows

a boolean or boolean array telling whether to draw a perpendicular arrow at a hole.

Details

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.

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

See Also

holey_line.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)

mazealls documentation built on May 2, 2019, 3:39 a.m.