Last active
January 23, 2019 07:01
-
-
Save chichacha/85cecff90af5bb8879f3c3e4c03f830a to your computer and use it in GitHub Desktop.
Pear & Teardrop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw_heart <- function(xc=0,yc=0,npoints=1000,radius=1,...){ | |
#area = pi*r*r for circle... this heart has area of 180 = r*r | |
t = seq(-pi,pi, length.out=npoints) | |
x = xc + 16 * radius *(sin(t))^3 | |
y = yc + radius*13*cos(t) - radius*5*cos(2*t) - radius*2*cos(3*t) - radius*cos(4*t) | |
df <- tibble(theta=t,x=x,y=y) | |
df %>% | |
mutate(color=sample(trippy,size=npoints,replace=T), | |
alpha=rescale(abs(x)), | |
size=rescale(abs(x))) %>% | |
ggplot(aes(x=x,y=y)) + | |
geom_polygon(fill="#000000ae") + | |
geom_line(aes(color=color, alpha=alpha, size=size), lineend="round") + | |
scale_color_identity() + | |
scale_size_continuous(guide="none",range=c(0.1,0.6)) + | |
scale_alpha_continuous(guide="none", range=c(0.3,1)) + | |
coord_fixed() + | |
theme_void() | |
} | |
hearts <-image_graph(width=800, height=600) | |
tibble(xc=c(0,0,0,0,0,0,1,-1),yc=c(0,0,0,0,0,0,0,0)) %>% | |
pmap(., draw_heart) | |
dev.off() | |
image_animate(hearts,fps=2) %>% image_write("Heart.gif") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringdist) | |
library(hashr) | |
library(tidyverse) | |
library(scales) | |
library(magick) | |
trippy <- c("#D3D70D", "#FA7268", "#A92A5C", "#00646B", "#F97394", "#007BB7", "#0083A1", "#7D5E98") | |
sympatico <- c("#FA7268", "#F6A1A0", "#7D3C38", "#C4867C", "#EFAC87", "#E5697B", "#CDAA7F", "#DFC2A0") | |
coral <-c("#B2BAB6", "#AB5C6D", "#FA7268", "#A89E81", "#42413E", "#9B963A", "#72694E", "#164A45") | |
under_sea <- c("#2D355A", "#255498", "#E299B0", "#FA7268", "#009698", "#7E874B", "#FFDC01", "#94DBDF") | |
teardrop <- function(m=2,...) { | |
teardrop <- tibble( | |
t = seq(0,2*pi,length.out=1000), | |
x = sin(t)* (sin(0.5*t))^m, | |
y = cos(t) | |
) | |
teardrop %>% | |
ggplot(aes(x=x,y=y)) + | |
geom_polygon(fill="#009698") + | |
theme_void() + | |
coord_fixed() | |
} | |
teardrop() | |
tears <- image_graph(width=300, height=300, bg="white",res=240) | |
c(0.5,1,2,3,4,5,6,7,8,9,10) %>% map(.,teardrop) | |
dev.off() | |
image_append(image_trim(tears)) | |
image_animate(tears,fps=1) | |
pear <- function(a=2,b=1){ | |
df <- tibble( | |
t = seq(0,2*pi,length.out=1000), | |
x = b * (cos(t)) * (1 + sin(t)), | |
y = a * (1 + sin(t)) | |
) | |
df %>% | |
ggplot(aes(x=x,y=y)) + | |
geom_polygon(fill="#FFDC01") + | |
theme_void() + | |
coord_fixed() + | |
scale_y_reverse() | |
} | |
pear(2,1.2) | |
pear(3,2) | |
pear(4,3) | |
teardrop(1) | |
tears_pears <- image_graph(width=300, height=300, bg="white",res=240) | |
c(0.5,1,2,3,4) %>% map(.,teardrop) | |
list(a=c(2,2,2,2),b=c(1,1.2,1.5,2)) %>% pmap(.,pear) | |
dev.off() | |
image_append(image_trim(tears_pears)) | |
Author
chichacha
commented
Jan 23, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment