Skip to content

Instantly share code, notes, and snippets.

@jrosell
Created October 30, 2024 14:57
Show Gist options
  • Save jrosell/31c8a7fcf19ea8ab7df9299190886156 to your computer and use it in GitHub Desktop.
Save jrosell/31c8a7fcf19ea8ab7df9299190886156 to your computer and use it in GitHub Desktop.
library(magick)
library(lofifonts) # remotes::install_github('coolbutuseless/lofifonts')
library(purrr)
bitmap_text_coords("Hello", font = 'unifont') |>
head()
text <- glue::glue("It is a period of civil war.
Rebel spaceships, striking
from a hidden base, have won
their first victory against
the evil Galactic Empire.
During the battle, Rebel
spies managed to steal secret
plans to the Empire's
ultimate weapon, the DEATH
STAR, an armored space
station with enough power to
destroy an entire planet.
Pursued by the Empire's
sinister agents, Princess
Leia races home aboard her
starship, custodian of the
stolen plans that can save
her people and restore
freedom to the galaxy....")
text_img <- text |>
bitmap_text_raster() |>
image_read() |>
image_resize("237x320") |>
image_border(color = "white", geometry = "20x20") |>
image_resize("261x360")
out_list <- seq(360, 0, by = -10) |>
map(\(y) {
img <- text_img |>
image_border(color = "white", geometry = paste0("x", y)) |>
image_crop("261x360")
coordinates <- c(0, 0, 100, 0, # Top left corner moves inward
image_info(img)$width, 0, image_info(img)$width - 100, 0, # Top right corner moves inward
0, image_info(img)$height, 0, image_info(img)$height, # Bottom left stays the same
image_info(img)$width, image_info(img)$height, image_info(img)$width, image_info(img)$height) # Bottom right stays the same
img |>
image_distort("perspective", coordinates)
})
animation <- image_animate(image_join(out_list), fps = 2, optimize = TRUE)
print(animation)
@jrosell
Copy link
Author

jrosell commented Oct 30, 2024

starwards-intro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment