Created
January 16, 2022 00:27
-
-
Save matt-dray/068dee2d817fb7be38439fdd14d8ac07 to your computer and use it in GitHub Desktop.
R function for a Link-sprite walk-cycle (to be run in the terminal)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
link_walk_cycle <- function(cycles = 5) { | |
link_v_top <- c( | |
0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0, | |
0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, | |
0,0,2,0,1,3,3,3,3,3,3,1,0,2,0,0, | |
0,0,2,0,3,3,3,3,3,3,3,3,0,2,0,0, | |
0,0,2,2,3,2,1,2,2,1,2,3,2,2,0,0, | |
0,0,2,2,3,2,3,2,2,3,2,3,2,2,0,0, | |
0,0,0,2,2,2,2,2,2,2,2,2,2,3,0,0 | |
) | |
link_v_b1 <- c( | |
0,0,0,1,1,2,2,3,3,2,2,1,1,3,0,0, | |
0,3,3,3,3,3,2,2,2,2,1,1,3,3,3,0, | |
3,3,2,3,3,3,3,1,1,1,1,1,2,3,3,0, | |
3,2,2,2,3,3,2,3,3,1,1,2,2,2,3,0, | |
3,3,2,3,3,3,2,1,3,3,3,3,2,2,2,0, | |
3,3,2,3,3,3,2,3,3,1,1,1,1,2,0,0, | |
3,3,3,3,3,3,2,1,1,1,1,1,0,0,0,0, | |
0,2,2,2,2,2,3,0,0,3,3,3,0,0,0,0, | |
0,0,0,0,3,3,3,0,0,0,0,0,0,0,0,0 | |
) | |
link_v_b2 <- c( | |
0,0,0,0,1,2,2,3,3,2,2,1,3,3,0,0, | |
0,0,3,3,3,3,3,2,2,2,1,1,1,2,0,0, | |
0,3,3,2,3,3,3,3,1,1,1,1,1,2,0,0, | |
0,3,2,2,2,3,3,2,3,3,1,1,3,0,0,0, | |
0,3,3,2,3,3,3,2,1,3,3,3,1,0,0,0, | |
0,3,3,2,3,3,3,2,3,3,1,1,1,0,0,0, | |
0,3,3,3,3,3,3,2,1,1,1,3,0,0,0,0, | |
0,0,2,2,2,2,2,0,0,3,3,3,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0 | |
) | |
# Combine vectors to get frames | |
link_f1 <- c(link_v_top, link_v_b1) | |
link_f1 <- gsub(0, "\U0020", link_f1) # background | |
link_f1 <- gsub(1, "\U2593", link_f1) # green tunic/hat | |
link_f1 <- gsub(2, "\U2588", link_f1) # skin | |
link_f1 <- gsub(3, "\U2591", link_f1) # non-tunic/hat apparel | |
link_f1_m <- t(matrix(link_f1, 16)) | |
link_f2 <- c(link_v_top, link_v_b2) | |
link_f2 <- gsub(0, "\U0020", link_f2) | |
link_f2 <- gsub(1, "\U2593", link_f2) | |
link_f2 <- gsub(2, "\U2588", link_f2) | |
link_f2 <- gsub(3, "\U2591", link_f2) | |
link_f2_m <- t(matrix(link_f2, 16)) | |
x <- 0 | |
while (x < cycles) { | |
x <- x + 1 | |
Sys.sleep(1) | |
system("clear") | |
system("clear") | |
for (i in 1:nrow(link_f1_m)) { | |
cat(link_f1_m[i, ], "\n") | |
} | |
Sys.sleep(1) | |
system("clear") | |
for (i in 1:nrow(link_f2_m)) { | |
cat(link_f2_m[i, ], "\n") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When run in the terminal: