Skip to content

Instantly share code, notes, and snippets.

@kohske
Created November 8, 2011 14:13
Show Gist options
  • Save kohske/1347825 to your computer and use it in GitHub Desktop.
Save kohske/1347825 to your computer and use it in GitHub Desktop.
Merry Christmas Illusion
graphics.off()
W <- 5.5
H <- 5.5
parts <- function(x0, y0, BLfin, Size) {
Nfin <- 48
BLfin <- c(BLfin, 1-BLfin)
FSize <- 1
color <- c("white",
do.call("rgb", lapply(runif(3, 0, 0.25), I)),
rgb(runif(1, 0.75, 1), runif(1, 0.75, 1), runif(1, 0.5, 1)))
j <- 1
ths <- seq(0, 2*pi, length=Nfin+1)[-1]
for (t in 1:length(ths)) {
rate <- BLfin[t%%2+1]
ts <- seq(ths[t] - 2*pi/Nfin*rate, ths[t] + 2*pi/Nfin*rate, length = 2)
r <- 0.5
px <- c(x0, r * (cos(ts))/W + x0, x0)
py <- c(y0, r * (sin(ts))/H + y0, y0)
grid.polygon(px, py, gp = gpar(col=NA, fill=color[j]))
j <- 3-j
}
r <- Size * FSize
ts <- seq(0, 2*pi, length = 32)
px <- c(x0, r * (cos(ts))/W + x0, x0)
py <- c(y0, r * (sin(ts))/H + y0, y0)
grid.polygon(px, py, gp = gpar(col=color[3], fill=color[3]))
}
quartz(width = 6, height = 6)
grid.polygon(c(0.5, 0.2, 0.8), c(1, 0.2, 0.2), gp = gpar(col = NA, fill = "darkgreen"))
grid.rect(0.5, 0.1, 0.2, 0.2, gp = gpar(col = NA, fill = "brown"))
ps <- data.frame(Xs = c(0.5, 0.4, 0.6, 0.3, 0.5, 0.7, 0.2, 0.4, 0.6, 0.8),
Ys = c(0.9, 0.7, 0.7, 0.5, 0.5, 0.5, 0.3, 0.3, 0.3, 0.3))
with(ps, {
for(i in 1:nrow(ps)) {
parts(Xs[i], Ys[i], 0.5, 0.1)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment