File: vi.grid.illusion.R

package info (click to toggle)
r-cran-animation 2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,268 kB
  • sloc: javascript: 873; sh: 15; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' Visual illusions: Scintillating grid illusion and Hermann grid illusion
#'
#' The two most common types of grid illusions are Hermann grid illusions and
#' Scintillating grid illusions. This function provides illustrations for both
#' illusions.
#'
#' A grid illusion is any kind of grid that deceives a person's vision.
#'
#' This is actually a static image; pay attention to the intersections of the
#' grid and there seems to be some moving points (non-existent in fact).
#' @param nrow number of rows for the grid
#' @param ncol number of columns for the grid
#' @param lwd line width for grid lines
#' @param cex magnification for points in Scintillating grid illusions
#' @param col color for grid lines
#' @param type type of illusions: \code{'s'} for Scintillating grid illusions
#'   and \code{'h'} for Hermann grid illusions
#' @return \code{NULL}
#' @author Yihui Xie
#' @seealso \code{\link{points}}, \code{\link{abline}}
#' @export
#' @examples
#' ## default to be Scintillating grid illusions
#' vi.grid.illusion()
#'
#' ## set wider lines to see Hermann grid illusions
#' vi.grid.illusion(type = 'h', lwd = 22, nrow = 5, ncol = 5,
#'     col = 'white')
vi.grid.illusion = function(
  nrow = 8, ncol = 8, lwd = 8, cex = 3, col = 'darkgray', type = c('s', 'h')
) {
  op = par(mar = rep(0, 4), bg = 'black')
  plot.new()
  x = seq(0, 1, length = ncol)
  y = seq(0, 1, length = nrow)
  abline(v = x, h = y, col = col, lwd = lwd)
  if (type[1] == 's')
    points(rep(x, each = nrow), rep(y, ncol), col = 'white', cex = cex, pch = 20)
  par(op)
}