Skip to content

Instantly share code, notes, and snippets.

@ryantimpe
Last active August 13, 2021 17:54

Revisions

  1. ryantimpe revised this gist Aug 13, 2021. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions recthurs_remix.R
    Original file line number Diff line number Diff line change
    @@ -24,10 +24,7 @@ expand_grid(x = 0:(n_x+1),
    )) %>%
    #Some gentle trial and error for the shading
    #... thanks to my years playing with {rayshader} and datasaurs
    mutate(#shade = (x*tan(sqrt((x/1)^2+(y/1)^2))/y)#,
    #shade = sin(x+y)*cos(x-y)#,
    shade = sin(sqrt(abs(x^2-y^2)))
    ) %>% #View()
    mutate(shade = sin(sqrt(abs(x^2-y^2)))) %>%
    mutate(diag = x-y,
    diag2 = x+y) %>%
    ggplot() +
  2. ryantimpe revised this gist Aug 13, 2021. 1 changed file with 54 additions and 0 deletions.
    54 changes: 54 additions & 0 deletions recthurs_remix.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #Recreation Thursday - Remix
    # August 12, 2021

    library(tidyverse)
    library(ggforce)
    library(scales)

    n_x = 19 #Number of circles along bottom X
    n_y = 19 #Number of circles along side Y

    mid_point = 11.5

    riley_axis2_trans = function(){scales::trans_new("riley_axis2",
    function(x) (x-mid_point)^3,
    function(x) (x-mid_point)^3)}

    # 1-increment cirles
    expand_grid(x = 0:(n_x+1),
    y = 0:(n_y+1)) %>%
    # Between-increment circles
    bind_rows(expand_grid(
    x = (0+1/2):(n_x+1/2),
    y = (0+1/2):(n_y+1/2),
    )) %>%
    #Some gentle trial and error for the shading
    #... thanks to my years playing with {rayshader} and datasaurs
    mutate(#shade = (x*tan(sqrt((x/1)^2+(y/1)^2))/y)#,
    #shade = sin(x+y)*cos(x-y)#,
    shade = sin(sqrt(abs(x^2-y^2)))
    ) %>% #View()
    mutate(diag = x-y,
    diag2 = x+y) %>%
    ggplot() +
    geom_path(aes(x-1/4, y+1/4, group = diag),
    linetype = "dotted",
    size = 0.5, alpha = 0.8,
    color = "#fff8b4") +
    geom_path(aes(x, y+1/2, group = diag2),
    linetype = "dotted",
    size = 0.5, alpha = 0.8,
    color = "#fff8b4") +
    ggforce::geom_circle(aes(x0=x, y0=y, r=0.25,
    alpha = shade),
    color = NA, fill = "white",
    inherit.aes = FALSE) +
    coord_trans(x="riley_axis2", y="riley_axis2",
    xlim = c(0.5, n_x+0.5), ylim = c(.5, n_y+0.5), expand = 0) +
    # coord_fixed() +
    labs(caption = "#RecreationThursday | @ryantimpe") +
    theme_void() +
    theme(legend.position = "none",
    plot.background = element_rect(fill = "#090935"),
    plot.caption = element_text(color = "#fff8b4"))

  3. ryantimpe created this gist Aug 12, 2021.
    51 changes: 51 additions & 0 deletions recthurs.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #Recreation Thursday
    # August 12, 2021

    library(tidyverse)
    library(ggforce)
    library(scales)

    n_x = 13 #Number of circles along bottom X
    n_y = 19 #Number of circles along side Y

    #Create a custom y axis ----
    # Soooo much trial and error.
    # I think a cubic function is too steep
    riley_fun = function(x){
    linear_scale = 30.25*2
    mid_point = 11.5

    #These decimal values are from looking at the distortions with diff() and adjusting
    case_when(x < 6 ~ (x-mid_point)*linear_scale + 166.375,
    x > 15 ~ (x-mid_point)*linear_scale - 168.875,
    TRUE ~(x-mid_point)^3)
    }

    riley_axis_trans = function(){scales::trans_new("riley_axis",
    function(x) riley_fun(x),
    function(x) riley_fun(x))}

    # 1-increment cirles
    expand_grid(x = 1:n_x,
    y = 1:n_y) %>%
    # Between-increment circles
    bind_rows(expand_grid(
    x = (1+1/2):(n_x-1/2),
    y = (1+1/2):(n_y-1/2),
    )) %>%
    #Some gentle trial and error for the shading
    #... thanks to my years playing with {rayshader} and datasaurs
    mutate(shade = sin((x-y - 5)/3)) %>%
    ggplot() +
    ggforce::geom_circle(aes(x0=x, y0=y, r=0.3,
    alpha = shade),
    color = NA, fill = "#333333",
    inherit.aes = FALSE) +
    coord_trans(x="identity", y="riley_axis") +
    labs(caption = "#RecreationThursday | @ryantimpe") +
    theme_void() +
    theme(legend.position = "none",
    plot.background = element_rect(fill = "#d4d1ce"))