-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from matt-dray/5-grid
Use {grid} and support images
- Loading branch information
Showing
13 changed files
with
403 additions
and
447 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
Package: hexbase | ||
Title: Make a Hex Logo | ||
Title: Create Simple Dependency-Free Hex Logos | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person("Matt", "Dray", , "mwdray@gmail.com", role = c("aut", "cre")) | ||
Description: A simple, dependency-free way to create a hexagon-shaped logo | ||
to help promote your R package or other projects. | ||
Description: A simple interface to create hexagon-shaped logos that help | ||
promote your R package or other projects. Uses only base R. | ||
License: MIT + file LICENSE | ||
URL: https://github.com/matt-dray/hexbase | ||
BugReports: https://github.com/matt-dray/hexbase/bugs | ||
Imports: | ||
grDevices, | ||
grid | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 | ||
Encoding: UTF-8 | ||
Issues: https://github.com/matt-dray/hexbase | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.2 | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.get_hex_coords <- function(d = 1) { | ||
a <- d / 2 | ||
b <- sqrt(3) * a | ||
list( | ||
x = c(-b, 0, b, b, 0, -b), | ||
y = c(-a, -2 * a, -a, a, 2 * a, a) | ||
) | ||
} | ||
|
||
.scale_outer_coords <- function(outer_coord_val) { | ||
num <- outer_coord_val - min(outer_coord_val) | ||
dem <- max(outer_coord_val) - min(outer_coord_val) | ||
num / dem | ||
} | ||
|
||
.get_inner_hex_coords_scaled <- function(coords_inner, coords_outer) { | ||
|
||
coords_inner_scaled <- vector("list", length = length(coords_inner)) | ||
names(coords_inner_scaled) <- c("x", "y") | ||
|
||
for (i in seq_along(coords_inner)) { | ||
coords_inner_scaled[[i]] <- .scale_inner_coords( | ||
coords_inner[[i]], | ||
min(coords_outer[[i]]), | ||
max(coords_outer[[i]]) | ||
) | ||
} | ||
|
||
coords_inner_scaled | ||
|
||
} | ||
|
||
.scale_inner_coords <- function(inner_val, outer_val_min, outer_val_max) { | ||
num <- inner_val - pmin(min(inner_val), outer_val_min) | ||
dem <- pmax(max(inner_val), outer_val_max) - pmin(min(inner_val), outer_val_min) | ||
num / dem | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.engrob_hex <- function(coords, fill_col) { | ||
grid::polygonGrob( | ||
coords[["x"]], | ||
coords[["y"]], | ||
gp = grid::gpar(fill = fill_col) | ||
) | ||
} | ||
|
||
.engrob_text <- function( | ||
text_string, | ||
text_x, | ||
text_y, | ||
text_col, | ||
text_size, | ||
text_font | ||
) { | ||
grid::textGrob( | ||
text_string, | ||
x = grid::unit(text_x, "npc"), | ||
y = grid::unit(text_y, "npc"), | ||
gp = grid::gpar( | ||
col = text_col, | ||
fontsize = text_size, | ||
fontfamily = text_font, | ||
lineheight = 0.75 | ||
) | ||
) | ||
} | ||
|
||
.engrob_img <- function( | ||
img_object, | ||
img_x, | ||
img_y, | ||
img_width, | ||
img_height | ||
) { | ||
grid::rasterGrob( | ||
img_object, | ||
x = grid::unit(img_x, "npc"), | ||
y = grid::unit(img_y, "npc"), | ||
width = grid::unit(img_width, "npc"), | ||
height = grid::unit(img_height, "npc") | ||
) | ||
} |
Oops, something went wrong.