Skip to content

Instantly share code, notes, and snippets.

@chichacha
chichacha / texture_circle_with_yarn.R
Created January 26, 2019 03:57
Yarns and Circle
library(tidyverse)
df <- tibble(
t = seq(0,2*pi,length.out=1000),
x = cos(t),
y = sin(t)
) %>% mutate(idx = row_number(sample(t))) %>%
arrange(idx)
draw_yarn <- function(n=100){
@chichacha
chichacha / spiral.r
Created January 26, 2019 01:35
Going crazy with sprial
library(tidyverse)
spiral_draw <- function(a=1,b=1,c=2,d=1,e=1,n=365,sn=18){
df <-spiral_df <- tibble(
t = seq(0,sn*pi, length.out=n+1)
) %>%
mutate(r = a + b*t^(1/c),
x = r * cos(t*d),
y = r * sin(t*e))
@chichacha
chichacha / heart_animate.r
Last active January 23, 2019 07:01
Pear & Teardrop
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),
@chichacha
chichacha / grid_design.R
Created January 20, 2019 07:43
Connected Dots Patterns
library(tidyverse)
my_grid <- tibble(
x = c(1:30),
y = c(1:30)
) %>% expand.grid()
my_grid <- my_grid %>%
mutate(x_noise = rnorm(nrow(my_grid), mean=0, sd=0.1),
y_noise = rnorm(nrow(my_grid), mean=0, sd=0.1),
@chichacha
chichacha / peacock.r
Created January 15, 2019 06:19
Peacock + ggplot Experiment
library(tidyverse)
library(imager)
library(scales)
peacock <- load.image("https://farm9.staticflickr.com/8126/8647827542_3f55baed69_z.jpg")
peacock_df <- peacock %>%
@chichacha
chichacha / geom_spoke_fun.R
Created January 14, 2019 07:21
Experimenting with geom_spoke in ggplot2
library(tidyverse)
base_grid <- tibble(
x = c(1:20),
y = c(1:20)
) %>% expand.grid
my_grid <- base_grid %>%
mutate(color=sample(c("#CFF09E","#A8DBA8","#79BD9A","#3B8686","#0B486B"),
@chichacha
chichacha / ExperimentationWithFlower.R
Created January 9, 2019 07:04
Drawing Flower-Like Object with ggplot2
library(tidyverse)
flower_vertices <- function(xc,yc,radius,k=5,offset=0,d=pi*(3-sqrt(5)),npoints=360,...){
i = seq.int(0,npoints,by=1)
t = seq(0,2*pi, length.out=npoints+1)
tend = seq(0-d,2*pi-d, length.out=npoints+1)
m = sqrt(radius)*0.5 * cos(k * t) + offset
x = xc + m * cos(t)
y = yc + m * sin(t)
xend = xc + m * cos(tend)
@chichacha
chichacha / Cannabis.r
Created January 5, 2019 23:08
Drawing Half Circles & Heart & Cannabis
library(tidyverse)
cannabis_vertices <- function(xc,yc,radius,npoints=1000,...){
radius=radius/100
t = seq(-pi,pi, length.out=npoints+1)
m = (1+.9*cos(8*t)) * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) * (1+sin(t))
x = xc + m*radius * cos(t)
y = yc + m*radius * sin(t)
df <- tibble(x=x,y=y)
@chichacha
chichacha / Umbrella_Better.R
Last active January 5, 2019 20:25
When a rainy day make you think of umbrella....
## There's no need to generate progressive packed circle if you want grid of things...
df <- tibble(
x = rep(c(1:10), times=10),
y = rep(c(1:10), each=10),
radius = 0.5
)
df_triangles <- circleLayoutVertices(df,npoints=8,sizetype="radius")
df_triangles_1 <- circleLayoutVertices(df %>% mutate(radius=sqrt(radius)),
@chichacha
chichacha / DrawRandomFaces.R
Created December 30, 2018 06:57
Playing Around with Chernoff Face (aplpack package)
library(tidyverse)
library(aplpack)
draw_faces <- function(x=c(0,1,2,3,4,5),size=25, ncolors=10){
df <- tibble(
face_h = sample(x, size=size, replace=T),
face_w = sample(x, size=size, replace=T),
face_s = sample(x, size=size, replace=T),
mouth_h = sample(x, size=size, replace=T),
mouth_w = sample(x, size=size, replace=T),