{"id":33187152,"url":"https://github.com/cj-holmes/split-polygon-art","last_synced_at":"2025-11-25T18:00:43.359Z","repository":{"id":174886574,"uuid":"652330456","full_name":"cj-holmes/split-polygon-art","owner":"cj-holmes","description":"Documenting code to recreate art","archived":false,"fork":false,"pushed_at":"2023-06-11T20:06:49.000Z","size":2264,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-18T08:44:50.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cj-holmes.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-11T20:04:56.000Z","updated_at":"2024-05-28T21:03:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"38826503-a8e9-4102-bf0a-c495f7d5a1b1","html_url":"https://github.com/cj-holmes/split-polygon-art","commit_stats":null,"previous_names":["cj-holmes/split-polygon-art"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cj-holmes/split-polygon-art","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cj-holmes%2Fsplit-polygon-art","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cj-holmes%2Fsplit-polygon-art/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cj-holmes%2Fsplit-polygon-art/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cj-holmes%2Fsplit-polygon-art/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cj-holmes","download_url":"https://codeload.github.com/cj-holmes/split-polygon-art/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cj-holmes%2Fsplit-polygon-art/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-25T02:00:05.816Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-16T05:00:30.374Z","updated_at":"2025-11-25T18:00:43.353Z","avatar_url":"https://github.com/cj-holmes.png","language":null,"funding_links":[],"categories":["Miscellaneous"],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.width=5, \n  fig.height=5, \n  out.width = \"65%\", \n  dpi = 600\n)\n```\n\n# split polygon art\n\n## Intro\n* Documenting my attempt at recreating the art I saw in [this tweet](https://twitter.com/mattdesl/status/1655857548808028161?s=20) with R.\n* Then trying to further develop the idea\n* This code is not written for speed or efficiency - using spatial libraries is certainly overkill, but it's the first way I prototyped the code and I haven't felt the need to go back and change it!\n\n```{r warning=FALSE, message=FALSE}\nlibrary(tidyverse)\nlibrary(sf)\nlibrary(lwgeom)\nlibrary(wesanderson)\n```\n\n## Function\n* Psuedo code for function\n  * Compute the (x,y) vertices of a regular polygon by rotating a line of length `radius` through equal angle steps about the point (`ox`, `oy`)\n  * Convert the vertices to an `{sf}` POLYGON\n  * Compute a random point inside the polygon if `px` and `py` is not provided\n  * Create an `{sf}` MULTILINESTRING containing a line from the point (px, py) to each vertex of the regular polygon\n  * Use the MULTILINESTRINGS to plit the regular polygon into sub polygons \n \n```{r}\n#' Return the {sf} polygons\n#'\n#' @param n_sides number of sides of regular polygon\n#' @param offset_degrees offset angle for orientation of regular polygon\n#' @param ox origin of regular polygon x coordinate\n#' @param oy origin of regular polygon y coordinate\n#' @param radius radius of or regular polygon (distance from origin to polygon vertices)\n#' @param px origin point for the splitting lines x coordinate\n#' @param py origin point for the splitting lines y coordinate\nsplit_poly \u003c- function(n_sides, offset_degrees, ox, oy, radius, px = NULL, py = NULL){\n\n    # Create polygon angles and vertex xy coords\n    a_step \u003c- (2*pi)/n_sides\n    a \u003c- seq(pi/2 + offset_degrees*(pi/180), by = a_step, l = n_sides)\n    x \u003c- ox + cos(a) * radius\n    y \u003c- oy + sin(a) * radius\n    \n    # Create POLYGON\n    # Close polygon by making the last point the same as the first point\n    shape_polygon \u003c- st_polygon(x = list(matrix(c(c(x, x[1]), c(y, y[1])), ncol = 2)))\n\n    # Compute a random point inside the polygon if no px or py is provided\n    if(is.null(px) || is.null(py)){\n        p_xy \u003c- st_coordinates(st_sample(shape_polygon, 1))\n        px \u003c- p_xy[1,1]\n        py \u003c- p_xy[1,2]}\n\n    # Create MULTILINESTRING from each polygon vertex to the random point\n    lines \u003c-\n        st_multilinestring(\n            lapply(\n                X = seq_along(a), \n                FUN = function(b) matrix(c(c(x[b], px), c(y[b], py)), ncol = 2)))\n    \n    # Split the polygon based on the MULTILINESTRING\n    lwgeom::st_split(shape_polygon, lines) |\u003e st_collection_extract(\"POLYGON\")}\n```\n\n## Explore some different setups\n* Create uniform square grid of x and y coordinates for the regular polygon centers\n* Add values for the regular polygon number of sides, offset and radius against each grid point\n* Run `split_poly()` on each point\n* Assign a colour to each if the sub polygons created from each regular polygon\n  * Use the `wesanderson` palette `Zissou1`\n* Plot the result\n```{r}\nset.seed(1)\ncrossing(ox = 1:5, oy = 1:5) |\u003e \n    mutate(\n        n_sides = 4,\n        offset_degrees = 45,\n        radius = 0.55,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(wes_palettes$Zissou1, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* Choose colours from any of the `wesanderson` palettes \n```{r}\nset.seed(4)\ncrossing(ox = 1:5, oy = 1:5) |\u003e \n    mutate(\n        n_sides = 4,\n        offset_degrees = 45,\n        radius = 0.55,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* Larger grid and vary the regular polygon radius value based on position\n```{r}\nset.seed(2)\ncrossing(ox = 1:10, oy = 1:10) |\u003e \n    mutate(\n        n_sides = 4,\n        offset_degrees = 45,\n        radius = scales::rescale(sqrt(abs(ox - 5.5)^2 + abs(oy - 5.5)^2), c(0.5, 0.3)),\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(wes_palettes$Darjeeling2, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = sample(unlist(wes_palettes), 1)))\n```\n\n* Gradually change the offset angle across the image\n```{r}\nset.seed(1)\ncrossing(ox = 1:5, oy = 1:5) |\u003e \n    mutate(\n        n_sides = 3,\n        offset_degrees = seq(0, 180, l = n()),\n        radius = 0.5,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(wes_palettes$Rushmore, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* Random integer (3:5) number of sides for regular polygons\n```{r}\nset.seed(1)\ncrossing(oy = 1:15, ox = 1:15) |\u003e \n    mutate(\n        n_sides = sample(3:5, size = n(), replace = TRUE), \n        offset_degrees = runif(n(), 0, 360),\n        radius = scales::rescale(sqrt(abs(ox - 4)^2 + abs(oy - 4)^2), c(0.5, 0.1)),\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(wes_palettes$Moonrise3, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* Use non integer number of sides\n```{r}\nset.seed(1)\ncrossing(oy = 1:7, ox = 1:7) |\u003e \n    mutate(\n        n_sides = seq(3, 4, l = n()), \n        offset_degrees = seq(0, 90, l = n()),\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* All shapes using the same px/py point\n```{r}\nset.seed(1)\ncrossing(oy = 1:19, ox = 1:19) |\u003e \n    mutate(\n        n_sides = 4, \n        offset_degrees = 45,\n        radius = 0.45,\n        px = 10,\n        py = 10,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = px,\n                    py = py,\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n\nset.seed(1)\ncrossing(oy = 1:19, ox = 1:19) |\u003e \n    mutate(\n        n_sides = 4, \n        offset_degrees = seq(0, 90, l=n()),\n        radius = 0.45,\n        px = 10,\n        py = 10,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = px,\n                    py = py,\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n\n\nset.seed(1)\ncrossing(oy = 1:7, ox = 1:7) |\u003e \n    mutate(\n        n_sides = 4, \n        offset_degrees = 45,\n        radius = 0.45,\n        px = 3,\n        py = 3.2,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = px,\n                    py = py,\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n* Vary the px/py point across the shapes\n```{r}\nset.seed(1)\ncrossing(oy = 1:7, ox = 1:7) |\u003e \n    mutate(\n        n_sides = 4, \n        offset_degrees = 45,\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = ox + scales::rescale(ox, to = c(-0.2, 0.2)),\n                    py = oy + scales::rescale(oy, to = c(-0.2, 0.2)),\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(wes_palettes$Zissou1, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n\ncrossing(oy = 1:10, ox = 1:10) |\u003e \n    mutate(\n        n_sides = 4, \n        offset_degrees = 45,\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = 5.5 + cos(seq(0, 2*pi, l= n()))*2,\n                    py = 5.5 + sin(seq(0, 2*pi, l= n()))*2,\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(\n        a = st_area(g),\n        col = sample(wes_palettes$Zissou1, size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))+\n    theme_bw()\n```\n\n* Approximate circles with high number of regular polygon sides\n* Move the px/py point and colour the sub polygons by their area\n```{r}\nset.seed(1)\ncrossing(oy = 1:7, ox = 1:7) |\u003e \n    mutate(\n        n_sides = 100, \n        offset_degrees = 0,\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy,\n                    px = ox + scales::rescale(ox, to = c(-0.2, 0.2)),\n                    py = oy + scales::rescale(oy, to = c(-0.2, 0.2)),\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(a = st_area(g)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = a), col = NA)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    scale_fill_viridis_c(option = \"mako\")+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey5\"))\n```\n\n* A nasty look at hexagons using `st_make_grid()`\n```{r}\nset.seed(1)\n\nnx \u003c- 10\nny \u003c- 10\n\nhex_centers \u003c-\n    sf::st_make_grid(\n    x = st_polygon(list(matrix(c(0, 0, nx, nx, 0, 0, ny, ny, 0, 0), ncol = 2))),\n    n = c(nx, ny), \n    what = \"centers\",\n    square = FALSE, \n    flat_topped = FALSE) |\u003e\n    st_coordinates() |\u003e \n    as_tibble() |\u003e \n    rename(ox = X, oy = Y)\n\nhex_polys \u003c-\n    sf::st_make_grid(\n    x = st_polygon(list(matrix(c(0, 0, nx, nx, 0, 0, ny, ny, 0, 0), ncol = 2))),\n    n = c(nx, ny),\n    square = FALSE, \n    flat_topped = FALSE)\n\nf \u003c- 1\nhex_centers |\u003e\n    mutate(\n        n_sides = 6,\n        offset_degrees = 0,\n        radius = (1/sqrt(3))*f,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(wes_palettes |\u003e unlist(), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA) +\n    # geom_sf(data = hex_polys, fill = NA, col = 1) +\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n\n\nf \u003c- 0.85\nhex_centers |\u003e\n    mutate(\n        n_sides = 6,\n        offset_degrees = seq(0, 45, l=n()),\n        radius = (1/sqrt(3))*f,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    px = 2, \n                    py = 2,\n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(wes_palettes |\u003e unlist(), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = NA) +\n    # geom_sf(data = hex_polys, fill = NA, col = 1) +\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```\n\n\n* Some additonal experimentation with triangles\n```{r}\nset.seed(4)\ncrossing(ox = 1:9, oy = 1:9) |\u003e \n    mutate(\n        n_sides = 3,\n        offset_degrees = rep(c(0, 180), length.out = n()),\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n\n\nset.seed(4)\ncrossing(ox = 1:9, oy = 1:9) |\u003e \n    mutate(\n        n_sides = 3,\n        offset_degrees = rep(c(0, 90, 180, 270), length.out = n()),\n        radius = 0.45,\n        g = pmap(\n            .l =\n                list(\n                    ox = ox, \n                    oy = oy, \n                    n_sides = n_sides, \n                    offset_degrees = offset_degrees,\n                    radius = radius),\n            .f = split_poly)) |\u003e \n    unnest(cols = g) |\u003e\n    group_by(ox, oy) |\u003e \n    mutate(col = sample(unlist(wes_palettes), size = n(), replace = FALSE)) |\u003e \n    st_as_sf() |\u003e \n    ggplot()+\n    geom_sf(aes(fill = I(col)), col = 1)+\n    scale_x_continuous(expand = expansion(add = c(1,1)))+\n    scale_y_continuous(expand = expansion(add = c(1,1)))+\n    theme_void()+\n    theme(\n        legend.position = \"\",\n        panel.background = element_rect(color = NA, fill = \"grey95\"))\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcj-holmes%2Fsplit-polygon-art","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcj-holmes%2Fsplit-polygon-art","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcj-holmes%2Fsplit-polygon-art/lists"}