paradox: Paradox

View source: R/paradox.R

canvasR Documentation

Paradox

Description

Functions to make pleasing doodles

Usage

canvas()

paradox(
  shape,
  dist = 0.05,
  reverse = FALSE,
  cols = colorRampPalette(c("red", "blue"))(40),
  debug = FALSE
)

paradoxes(shapes, dist = 0.05, cols = colorRampPalette(c("red", "blue"))(40))

scale_shape(shape, scale = 1, shift = 0)

Arguments

shape

a matrix with colums x and y definining a shape to doodle within, can be any closed polygon, but some shapes work better than others.

dist

the distance up the adjacent edge where each new line will be drawn, default 0.05

reverse

should the shape be drawn in reverse order (see examples)

cols

a palate of colours as a vector of strings interpretable as colours

debug

should debug messages be produces (default FALSE)

shapes

a list of shapes (polygons) to doodle within

scale

if scaling, how much to scale by

shift

if scaling, should the shape also be shifted and by how much

Value

displays a plot

Examples


if (interactive()) {

  triangle <- cbind(x = c(0, 1, .7), y = c(0, 0.1, 1))
  triangle2 <- cbind(x = c(0, 0, .7), y = c(0, 1, 1))

  square <- cbind(x = c(0, 1, 1, 0), y = c(0, 0, 1, 1))

  canvas()
  paradox(square, 0.03)

  canvas()
  paradox(triangle, 0.042)
  paradox(triangle2, 0.042)

  canvas()
  paradox(scale_shape(square, c(0.5, 1)), 0.03)
  paradox(scale_shape(square, c(0.5, 1), c(0.5, 0)), 0.05, reverse = TRUE)

  canvas()
  dist <- 0.02
  paradox(scale_shape(square, .5), dist)
  paradox(scale_shape(square, .5, c(0.5, 0)), dist, reverse = TRUE)
  paradox(scale_shape(square, .5, .5), dist)
  paradox(scale_shape(square, .5, c(0, 0.5)), dist, reverse = TRUE)

  canvas()
  dist <- 0.02
  paradox(scale_shape(square, .5), dist, reverse = TRUE)
  paradox(scale_shape(square, .5, c(0.5, 0)), dist, reverse = TRUE)
  paradox(scale_shape(square, .5, .5), dist, reverse = TRUE)
  paradox(scale_shape(square, .5, c(0, 0.5)), dist, reverse = TRUE)

  canvas()
  dist <- 0.02

  cols1 <- colorRampPalette(c("red", "blue"))(30)
  cols2 <- colorRampPalette(c("blue", "red"))(30)
  cols3 <- colorRampPalette(c("green", "purple"))(30)
  cols4 <- colorRampPalette(c("purple", "green"))(30)

  paradox(scale_shape(square, .5), dist,
    reverse = TRUE,
    cols = c(rbind(cols1, cols2, cols3, cols4))
  )
  paradox(scale_shape(square, .5, c(0.5, 0)), dist,
    reverse = FALSE,
    cols = c(rbind(cols3, cols4, cols1, cols2))
  )
  paradox(scale_shape(square, .5, .5), dist,
    reverse = FALSE,
    cols = c(rbind(cols1, cols2, cols3, cols4))
  )
  paradox(scale_shape(square, .5, c(0, 0.5)), dist,
    reverse = TRUE,
    cols = c(rbind(cols3, cols4, cols1, cols2))
  )
}


colinpmillar/cpmtools documentation built on June 28, 2022, 10:35 p.m.