Logo Pattern
Overview
This repository provides a fully reproducible pipeline for generating the Center for Metropolitan Studies (CEM) logo pattern, based on its 20-Year Commemorative Logo.
Set the Environment
Code
rounded_square <- function(
x,
y,
side,
fill = "black",
radius = unit(0.1, "npc")
) {
assert_number(x)
assert_number(y)
assert_number(side, lower = 0)
assert_string(fill)
assert_class(radius, "unit")
half <- side / 2
grob <- roundrectGrob(
x = unit(0.5, "npc"),
y = unit(0.5, "npc"),
width = unit(1, "npc"),
height = unit(1, "npc"),
r = radius,
gp = gpar(fill = fill, lwd = 0)
)
annotation_custom(
grob = grob,
xmin = x - half,
xmax = x + half,
ymin = y - half,
ymax = y + half
)
}
Code
plot_logo_pattern <- function(
n = 100,
shape_1 = 2, # 2 # hist(rbeta(10000, 2, 50))
shape_2 = 50, # 2
min_size = 0.25,
max_size = 15,
step = 0.01,
margin = 1,
aspect_ratio = c(15, 10)
) {
assert_count(n, positive = TRUE)
assert_number(shape_1, lower = 0)
assert_number(shape_2, lower = 0)
assert_number(max_size, lower = 1)
assert_number(min_size, lower = 0, upper = max_size)
assert_number(step, lower = 0.0001)
assert_number(margin, lower = 0, upper = min(aspect_ratio))
assert_numeric(aspect_ratio, len = 2, lower = 1)
data <- tibble(
x = sample(seq(margin, aspect_ratio[1] - margin, by = step), n, TRUE),
y = sample(seq(margin, aspect_ratio[2] - margin, by = step), n, TRUE),
size =
rbeta(n, shape_1, shape_2) |>
rescale(to = c(min_size, max_size), from = c(0, 1)),
fill = sample(
x = get_brand_color(c("primary", "secondary", "tertiary")),
size = n,
replace = TRUE
)
)
plot <-
ggplot() +
xlim(0, aspect_ratio[1]) +
ylim(0, aspect_ratio[2]) +
theme_void() +
coord_fixed()
for (i in split(data, seq_len(nrow(data)))) {
plot <-
plot +
rounded_square(
x = i$x,
y = i$y,
side = i$size,
fill = i$fill,
r = unit(0.1, "npc")
)
}
plot
}
Set Variables
Set the number of squares to be drawn.
n <- 100
Plot Patterns
Change the seed value to get different patterns.
seeds <- c(1, 33, 9422)
Animate Pattern
Code
animation <-
files |>
lapply(image_read) |>
image_join() |>
image_animate(fps = 1)
Code
animation |> image_write(here("images", "logo-pattern-animation.gif"))
License
The code in this report is licensed under the GNU General Public License Version 3, while the report is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International.
Copyright (C) 2025 Daniel Vartanian
The code in this report is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
Acknowledgments
This study was financed, in part, by the São Paulo Research Foundation (FAPESP), Brazil. Process Number 2025/17879-2.