-
Notifications
You must be signed in to change notification settings - Fork 9
/
front_page.R
50 lines (40 loc) · 1.17 KB
/
front_page.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
library(png)
library(ggforce)
library(animation)
library(tweenr)
jhu_png = readPNG("jhudsl.png")
x = rep(1:510,each=555)
y = rep(1:555,510)
val = jhu_png[,,3]
val = round(val)
rm(jhu_png)
ind1 = which(val ==1)
ind0 = which(val ==0)
n = 10e3
ind = c(sample(ind1,size=n),sample(ind0,size=n))
ind = ind[order(ind)]
x = x[ind]; y = 555-y[ind]; val = val[ind]
colvals = c("black","lightblue")
plot(x,y,pch=15,cex=0.3,col=colvals[(val + 1)])
df_small = data.frame(x=x,y=y,val=val)
df_small2 = data.frame(x=round(runif(2*n,min=0,max=510)),
y=round(runif(2*n,min=0,max=510)),
val=val)
df = tween_states(list(df_small2,df_small),
tweenlength=20,
statelength=1,
ease="quadratic-in",
nframes=20)
mxframe = max(df$.frame)
for(i in 1:5){
df = rbind(df,data.frame(df_small,
.frame=(mxframe+i)))
}
saveGIF(for(i in 1:max(df$.frame)){
tmp = filter(df,.frame==i)
colvals = c("black","lightblue")
plot(tmp$x,tmp$y,pch=15,
cex=0.3,
col=colvals[(tmp$val + 1)],
xaxt="n",yaxt="n",xlab="",ylab="",bty="n")
},interval=0.2,movie.name='test.gif')