fold <- function(dir, n, paper) {
if (dir == "x") {
paper1 <- paper[,1:(n)]
paper2 <- paper[,(n+2):ncol(paper)]
paper2 <- t(apply(paper2, 1, rev))
} else if (dir == "y") {
paper1 <- paper[1:(n),]
paper2 <- paper[(n+2):nrow(paper), ]
paper2 <- apply(paper2, 2, rev)
}
return(ifelse(paper1 | paper2, TRUE, FALSE))
}
for(i in 1:nrow(folds)) {
paper <- fold(folds$X1[i], folds$X2[i], paper)
coordX <- c()
coordY <- c()
for(r in 1:nrow(paper)) {
for(c in 1:ncol(paper)) {
if(paper[r,c]) {
coordX <- append(coordX, r)
coordY <- append(coordY, c)
}
}
}
points <- data.frame(cbind(coordX, coordY)) %>%
ggplot() +
geom_point(aes(x = coordY, y = -coordX)) +
xlim(0, max(c(coordX, coordY))) +
ylim(-max(c(coordX, coordY)), 0)
if(i == nrow(folds))
print(points)
}