Skip to content

Instantly share code, notes, and snippets.

@bearloga
Last active Aug 29, 2015
Embed
What would you like to do?
For Oliver Keyes (@Quominus) who tweeted that he "would like a magic 8-ball only instead of the future it tells [him] if [he's] being insecure and/or nuts."
library(shape) # install.packages('shape')
magic_8ball <- function(x = c("yes","no")) {
greys <- greycol(50, interval = c(0, 1))
colours <- shadepalette("#000079", "blue", n = 20)
emptyplot(xlim = c(-5, 5), ylim = c(-5, 5), col = "white", frame.plot = FALSE)
filledellipse(rx1 = 4.9, ry1 = 4.9, col = "black")
filledellipse(rx1 = 2, ry1 = 3.5, col = greys[2:50], angle = -45, dr = .1, mid = c(-2, 2))
filledellipse(rx1 = 0.25, ry1 = 0.25, col = "white", mid = c(-2, 2))
filledellipse(rx1 = 2.8, ry1 = 2.8, col = "white")
filledellipse(rx1 = 2.77, ry1 = 2.77, col = "black")
filledmultigonal(rx = 2.7, ry = 2.7, col = colours, nr = 3, angle = 30)
if ( runif(1) < 0.1 ) {
text(0, 0, "ASK\nAGAIN\nLATER", col = "white")
} else {
if (length(x) == 2) {
text(0, 0, toupper(sample(c(x, paste0(x, collapse = "\n&\n")), 1)),
col = "white")
} else {
text(0, 0, toupper(sample(x, 1)), col = "white", cex = 2)
}
}
}
magic_8ball(c("insecure","bonkers"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment