대한항공 로고를 구글 이미지 검색에서 직접 찾아 url을 복사하여 가져온다.
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
)
자유한국당 로고를 가져와서 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/
디렉토리 및으로 이동시킨다.
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
)