A Reproducible Pipeline for Generating CEM’s Logo Pattern

Author

Daniel Vartanian

Published

February 13, 2026

Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows. License: GPLv3 License: CC BY-NC-SA 4.0 Contributor Covenant 3.0 code of conduct badge

Overview

This repository provides a reproducible pipeline for generating the Center for Metropolitan Studies (CEM) logo pattern, based on its 20-Year Commemorative Logo.

Set the Environment

Load Packages

Set Initial Variables

Set the number of squares to be drawn.

n <- 100

Load Custom Functions

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
}

Plot Patterns

Change the seed value to get different patterns.

seeds <- c(1, 33, 9422)
Code
for (i in seeds) {
  set.seed(i)

  i_plot <- plot_logo_pattern(n)

  ggsave(
    filename = here(
      "patterns",
      paste0("logo-pattern-", i, ".svg")
    ),
    plot = i_plot,
    width = 15,
    height = 10,
    units = "cm"
  )

  print(i_plot)
}

Animate Pattern

Code
files <- character()

for (i in seeds) {
  set.seed(i)

  i_plot <- plot_logo_pattern(n)
  i_file <- tempfile(fileext = ".png")

  ggsave(
    filename = i_file,
    plot = i_plot,
    width = 15,
    height = 10,
    units = "cm",
    dpi = 150,
    bg = "white"
  )

  files <- files |> append(i_file)
}
Code
animation <-
  files |>
  lapply(image_read) |>
  image_join() |>
  image_animate(fps = 1)
Code
animation |>
  image_write(
    here("images", "logo-pattern-animation.gif")
  )
Code
animation

License

License: GPLv3 License: CC BY-NC-SA 4.0

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 license.

Copyright (C) 2026 Center for Metropolitan Studies

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

CEM Logo
This work was developed with support from the Center for Metropolitan Studies (CEM) based at the School of Philosophy, Letters and Human Sciences (FFLCH) of the University of São Paulo (USP) and at the Brazilian Center for Analysis and Planning (CEBRAP).
FAPESP Logo
This work was financed, in part, by the São Paulo Research Foundation (FAPESP), Brazil. Process Number 2025/17879-2.