1 대한항공 로고

대한항공 로고를 구글 이미지 검색에서 직접 찾아 url을 복사하여 가져온다.

library(magick)
library(reshape2)
library(dplyr)
library(tidygraph)
library(particles)
library(animation)

korean_air <- image_read("https://file.namu.moe/file/8bc9e381797334eb33da66e3ba501be19d7346f9afc7bf7b3142d0cb1fa6b8213cf4795d13e247f1a5362be73b9728af") %>% 
  image_scale("300x")

korean_air

2 대한항공 로고 미립원자 1

BMW 로고를 미립자(particle)로 날려버리는 과정을 “After Effect”로 구현을 했는데 이를 R 코드로 작성한 사례를 살펴보자.

plot_fun <- function(sim) {
  df <- as_tibble(sim)
  plot(df$x, df$y, col = df$color, pch = '.', axes = FALSE, xlim = c(-100, 317), ylim = c(-268, 100), xlab = NA, ylab = NA)
}

logo <- korean_air

logo_frame <- melt(as.matrix(as.raster(logo)), c('y', 'x'), value.name = 'color', as.is = TRUE) %>% 
  filter(color != 'transparent') %>% 
  mutate(color = as.character(color),
         y = -y,
         batch = as.integer(cut(-x + rnorm(n(), 0, 10), 50)),
         include = FALSE,
         y_drift = rnorm(n(), 300, 70),
         x_drift = rnorm(n(), 300, 90))

saveGIF(
  tbl_graph(logo_frame) %>% 
    simulate(alpha_decay = 0, setup = predefined_genesis(x, y)) %>% 
    wield(y_force, y = y_drift, include = include, strength = 0.02) %>% 
    wield(x_force, x = x_drift, include = include, strength = 0.02) %>% 
    wield(random_force, xmin = -.1, xmax = .1, ymin = -.1, ymax = .1, include = include) %>% 
    evolve(120, function(sim) {
      sim <- record(sim)
      sim <- mutate(sim, include = batch < evolutions(sim) - 10)
      plot_fun(sim)
      sim
    }),
  movie.name = 'korean-air2.gif',
  interval = 1/24, ani.width=500, ani.height=300
)

대한항공 로고

3 자유한국당 로고

자유한국당 로고를 가져와서 PNG 파일에 대한 기본정보를 얻는다.

library(magick)
library(reshape2)
library(dplyr)
library(tidygraph)
library(particles)
library(animation)

logo <- image_read('fig/korea_liberty_party.png') 

logo

추출한 이미지 기본정보를 바탕으로 애니메이션 크기를 설정하여 제작한다.

plot_fun <- function(sim) {
  df <- as_tibble(sim)
  plot(df$x, df$y, col = df$color, pch = '.', axes = FALSE, xlim = c(0, 417), ylim = c(-168, 100), xlab = NA, ylab = NA)
}

# logo <- image_read('fig/korea_liberty_party.png') 

logo_frame <- melt(as.matrix(as.raster(logo)), c('y', 'x'), value.name = 'color', as.is = TRUE) %>% 
  filter(color != 'transparent') %>% 
  mutate(color = as.character(color),
         y = -y,
         batch = as.integer(cut(-x + rnorm(n(), 0, 10), 50)),
         include = FALSE,
         y_drift = rnorm(n(), 300, 70),
         x_drift = rnorm(n(), 300, 90))

saveGIF(
  tbl_graph(logo_frame) %>% 
    simulate(alpha_decay = 0, setup = predefined_genesis(x, y)) %>% 
    wield(y_force, y = y_drift, include = include, strength = 0.02) %>% 
    wield(x_force, x = x_drift, include = include, strength = 0.02) %>% 
    wield(random_force, xmin = -.1, xmax = .1, ymin = -.1, ymax = .1, include = include) %>% 
    evolve(120, function(sim) {
      sim <- record(sim)
      sim <- mutate(sim, include = batch < evolutions(sim) - 10)
      plot_fun(sim)
      sim
    }),
  movie.name = 'liberty-korea.gif',
  interval = 1/15, ani.width = 500, ani.height = 400
)

제작된 이미지를 fig/ 디렉토리 및으로 이동시킨다.

fs::file_move('liberty-korea.gif', 'fig/liberty-korea.gif')

자유한국당 로고

4 코로나19

library(magick)
library(reshape2)
library(dplyr)
library(tidygraph)
library(particles)
library(animation)

covid_19 <- image_read('fig/nCoV-CDC-23312.png') 

covid_19

애니메이션으로 제작해보자.

plot_fun <- function(sim) {
  df <- as_tibble(sim)
  plot(df$x, df$y, col = df$color, pch = '.', axes = FALSE, xlim = c(0, 300), ylim = c(-268, 100), xlab = NA, ylab = NA)
}

logo <- image_read('fig/nCoV-CDC-small.png') 

logo_frame <- melt(as.matrix(as.raster(logo)), c('y', 'x'), value.name = 'color', as.is = TRUE) %>% 
  filter(color != 'transparent') %>% 
  mutate(color = as.character(color),
         y = -y,
         batch = as.integer(cut(-x + rnorm(n(), 0, 10), 50)),
         include = FALSE,
         y_drift = rnorm(n(), 300, 70),
         x_drift = rnorm(n(), 300, 90))

saveGIF(
  tbl_graph(logo_frame) %>% 
    simulate(alpha_decay = 0, setup = predefined_genesis(x, y)) %>% 
    wield(y_force, y = y_drift, include = include, strength = 0.02) %>% 
    wield(x_force, x = x_drift, include = include, strength = 0.02) %>% 
    wield(random_force, xmin = -.1, xmax = .1, ymin = -.1, ymax = .1, include = include) %>% 
    evolve(120, function(sim) {
      sim <- record(sim)
      sim <- mutate(sim, include = batch < evolutions(sim) - 10)
      plot_fun(sim)
      sim
    }),
  movie.name = 'coronavirus.gif',
  interval = 1/24
)

코로나 바이러스