Skip to content

Instantly share code, notes, and snippets.

@alistaire47
Last active February 15, 2019 07:11
Show Gist options
  • Save alistaire47/009cd815a91077a4d4877a18b204ae97 to your computer and use it in GitHub Desktop.
Save alistaire47/009cd815a91077a4d4877a18b204ae97 to your computer and use it in GitHub Desktop.
heart animation
library(tidyverse)
library(gganimate)
p <- crossing(t = (1:4)*pi/2,
x = seq(0, 2*pi, length = 501)) %>%
mutate(y = 2 - 2*sin(x) + sin(x) * sqrt(abs(cos(x)))/(sin(x) + 1.4),
x = (x + t) %% (2*pi)) %>%
ggplot(aes(x, y, color = x)) +
geom_path(size = 2, show.legend = FALSE) +
scale_color_gradient2(low = '#7a0177', mid = '#f768a1', high = '#fcc5c0') +
coord_polar() +
theme_void() +
transition_states(t, 1, 0)
animate(p, nframes = 300, fps = 30)
@alistaire47
Copy link
Author

heart

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