Skip to content

Commit

Permalink
Add x3p_vertical_anime
Browse files Browse the repository at this point in the history
  • Loading branch information
YuhangTom committed Mar 21, 2024
1 parent c586a7c commit 4d36965
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--18-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--20-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main)
[![CRAN
status](https://www.r-pkg.org/badges/version/wire.png)](https://CRAN.R-project.org/package=wire)
[![Codecov test
Expand Down
Binary file added inst/x3p_bin_red_before_rotate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions inst/x3p_vertical_anime.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
x3p_bin <- x3p_read(here::here("../Wirecuts/scans/T4BW-LI-R2.x3p")) %>%
x3p_insidepoly_df(b = 1) %>%
df_rmtrend_x3p() %>%
x3p_impute() %>%
x3p_bin_stripes(
direction = "vertical",
colors = c("#b12819", "#ffffff", "#134D6B"), freqs = c(0, 0.3, 0.7, 1)
)
x3p_plot <- x3p_bin %>%
x3p_delete_mask() %>%
x3p_trim_na()

list.files(here::here("inst"), pattern = "^x3p_bin_.*.png$", full.names = TRUE) %>%
file.remove()

x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here("inst/x3p_bin_before_rotate_no_mask.png")
)
x3p_plot <- x3p_bin %>%
x3p_trim_na()
x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here("inst/x3p_bin_before_rotate.png")
)
x3p_bin_red <- x3p_extract(x3p_bin, mask_vals = "#b12819")

x3p_plot <- x3p_bin_red %>%
x3p_trim_na()
x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here("inst/x3p_bin_red_before_rotate.png")
)

angle <- -6.158554
n_frame <- 20
angle_gif <- angle / n_frame
purrr::walk(1:n_frame, function(i_frame) {
x3p_plot <- x3p_rotate(x3p_bin_red, angle_gif * i_frame)
x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here(sprintf("inst/x3p_bin_red_before_rotate_%s.png", i_frame))
)
})

x3p_plot <- x3p_bin %>%
x3p_rotate(angle)
x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here("inst/x3p_bin_after_rotate.png")
)
x3p_plot <- x3p_bin %>%
x3p_rotate(angle) %>%
x3p_delete_mask()
x3p_image(x3p_plot,
size = c(500, 200), zoom = 0.6,
file = here::here("inst/x3p_bin_after_rotate_no_mask.png")
)

library(magick)
x3p_bin_red_before_rotate_gif <- c(
rep(here::here("inst/x3p_bin_before_rotate_no_mask.png"), 10),
rep(here::here("inst/x3p_bin_before_rotate.png"), 10),
rep(here::here("inst/x3p_bin_red_before_rotate.png"), 10),
here::here(sprintf("inst/x3p_bin_red_before_rotate_%s.png", 1:n_frame)),
rep(here::here(sprintf("inst/x3p_bin_red_before_rotate_%s.png", n_frame)), 10),
rep(here::here("inst/x3p_bin_after_rotate.png"), 10),
rep(here::here("inst/x3p_bin_after_rotate_no_mask.png"), 10)
) %>%
map(image_read) %>%
image_join() %>%
image_animate()

image_write(
image = x3p_bin_red_before_rotate_gif,
path = here::here("inst/x3p_bin_red_before_rotate.gif")
)

list.files(here::here("inst"), pattern = "^x3p_bin_.*.png$", full.names = TRUE) %>%
file.remove()

0 comments on commit 4d36965

Please sign in to comment.