Skip to content

Commit

Permalink
docs: Add logo
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms committed Feb 2, 2025
1 parent 9d00cbb commit 7abb3e8
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/_templates/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

html_title = "Neuroglancer"

html_favicon = "_templates/logo.svg"

templates_path = ["_templates"]


# Don't include "View page source" links, since they aren't very helpful,
# especially for generated pages.
html_show_sourcelink = True
Expand Down Expand Up @@ -77,8 +82,9 @@
html_theme = "sphinx_immaterial"

html_theme_options = {
"logo_svg": "logo.svg",
"icon": {
"logo": "material/library",
# "logo": "material/library",
"repo": "fontawesome/brands/github",
},
"site_url": "https://google.github.io/neuroglancer/",
Expand Down
122 changes: 122 additions & 0 deletions docs/generate_logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env python3
"""Generates the Neuroglancer logo in SVG format."""

import argparse

import numpy as np


def write_logo(path: str) -> None:

letter_cells = np.array(
[
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
],
dtype=bool,
)

g_cells = np.array(
[
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
],
dtype=bool,
)

width_over_height = letter_cells.shape[1] / letter_cells.shape[0]

margin = 2

base_size = 128

screen_size = np.array(
[width_over_height * base_size + 2 * margin, base_size + 2 * margin]
)

full_screen_size = np.array(
[width_over_height * base_size * 2 + 4 * margin, base_size * 2 + 4 * margin]
)

with open(path, "w") as f:
f.write(
f'<svg xmlns="http://www.w3.org/2000/svg" '
+ f'viewBox="0 0 {full_screen_size[0]} {full_screen_size[1]}" '
# + 'style="color: white; background-color: black;"'
+ ">"
)

grid_line_width = 1.5
cell_margin = 1.5

def draw_grid_letter(letter_cells, xoffset, yoffset):
cell_size = base_size / letter_cells.shape[0]
grid_line_color = fill_color = "currentColor"
# grid_line_color = "#333"

# Draw horizontal grid lines
for i in range(letter_cells.shape[0] + 1):
f.write(
f'<line stroke="{grid_line_color}" '
+ f'stroke-width="{grid_line_width}" '
+ f'x1="{xoffset+margin-grid_line_width/2}" '
+ f'y1="{yoffset+round(margin+i*cell_size,1)}" '
+ f'x2="{xoffset+round(margin+grid_line_width/2+cell_size*letter_cells.shape[1],1)}" '
+ f'y2="{yoffset+round(margin+i*cell_size,1)}"/>'
)

# Draw vertical grid lines
for i in range(letter_cells.shape[1] + 1):
f.write(
f'<line stroke="{grid_line_color}" '
+ f'stroke-width="{grid_line_width}" '
+ f'y1="{yoffset+margin}" x1="{xoffset+round(margin+i*cell_size,1)}" '
+ f'y2="{yoffset+round(margin+grid_line_width/2+cell_size*letter_cells.shape[0],1)}" '
+ f'x2="{xoffset+round(margin+i*cell_size,1)}"/>'
)

for y in range(letter_cells.shape[0]):
for x in range(letter_cells.shape[1]):
if not letter_cells[y, x]:
continue
f.write(
f'<rect fill="{fill_color}" '
+ f'x="{xoffset+round(margin+x*cell_size+cell_margin,1)}" '
+ f'y="{yoffset+round(margin+y*cell_size+cell_margin,1)}" '
+ f'width="{round(cell_size-2*cell_margin,1)}" '
+ f'height="{round(cell_size-2*cell_margin, 1)}"/>'
)

draw_grid_letter(letter_cells, xoffset=0, yoffset=0)

draw_grid_letter(
g_cells, xoffset=full_screen_size[0] / 2, yoffset=full_screen_size[1] / 2
)

f.write("</svg>\n")


def main():
parser = argparse.ArgumentParser()
parser.add_argument("output")

args = parser.parse_args()
write_logo(args.output)


if __name__ == "__main__":
main()

0 comments on commit 7abb3e8

Please sign in to comment.