forked from faizan-khan-iit/gsoc_animint
/
med_vi_lilac_chaser.R
58 lines (51 loc) · 2.08 KB
/
med_vi_lilac_chaser.R
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Load required packages
library(ggplot2)
library(proto)
library(animint)
## Function to implement the vi.lilac.chaser() function from package 'animation'
vi_lilac_chaser <- function(np = 10,
nmax = 1,
col = 'magenta',
p.size = 20,
c.size = 4
)
{
x <- seq(0, 2 * pi * np/(np + 1), length = np) # Get co-ordinates to plot
# Get data in a data-frame to pass to ggplot
df <- data.frame()
for (i in 1:np) {
df <- rbind(df, cbind(sin(x[-i]), cos(x[-i]), ptn = i))}
colnames(df) <- c("sinv", "cosv", "ptn")
# Plot to display the points and the '+' mark in the middle
p1 <- ggplot(data = df) +
# Display the points
geom_point(data = df,
aes(x = sinv, y = cosv, showSelected = ptn),
col = col,
size = p.size) +
# Display the '+' mark
geom_segment(aes(x=-0.1, y=0, xend=0.1, yend=0), size=c.size) +
geom_segment(aes(x=0, y=-0.1, xend=0, yend=0.1), size=c.size) +
xlim(c(-1.33, 1.33)) +
ylim(c(-1.33, 1.33)) +
# Hide the axes, titles and others..
theme_bw() +
theme(axis.line=element_blank(),
axis.text.x=element_blank(), axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(), axis.title.y=element_blank(),
legend.position="none",
panel.background=element_blank(),panel.border=element_blank(),
panel.grid.major=element_blank(),panel.grid.minor=element_blank(),
plot.background=element_blank())
# Automate using animint taking point number 'ptn' as variable
plots <- list(plot1 = p1)
plots$time <- list(variable = "ptn", ms = 150)
plots$duration <- list(ptn=0)
animint2dir(plots, out.dir = "vi_lilac")
animint2gist(plot.list = plots,
description = "Lilac Chaser Visual Illusion",
browse = TRUE,
out.dir = "vi_lilac")
invisible(NULL)
}