Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsfmc/3f5db1a430bfcbd24655 to your computer and use it in GitHub Desktop.
Save nsfmc/3f5db1a430bfcbd24655 to your computer and use it in GitHub Desktop.
a plotdevice file for gridding out domains and subjects
from ka_automation import *
# yeesh, gross!!!
def random_domain_color(slug, **kwargs):
import random
seed = kwargs.get('seed', 53)
print seed
random.seed(seed)
subject_count = len(subjects_for_domain(slug))
darkening = 0.3
tint_quantity = darkening / len(subjects_for_domain(slug))
colors = [color(subject_color_for(slug)) for x in range(subject_count)]
for i, c in enumerate(colors):
c.v += i * tint_quantity
random.shuffle(colors)
return colors
def subject_box(title, box_fill, stylename, **kwargs):
box_height = kwargs.get('height', 100)
stroke_width = kwargs.get('stroke_width', 0)
min_width = kwargs.get('min_width', 200)
padding = {'right': 40, 'left': 6, 'bottom': 8}
padding.update(kwargs.get('padding', {}))
label = text(title, padding['left'], box_height - padding['bottom'], style=stylename, plot=False)
label_width = textmetrics(label)[0]
box_width = label_width + padding['right']
if min_width:
box_width = max(min_width, box_width)
if stroke_width:
stroke(1)
strokewidth(stroke_width)
fill(box_fill)
rect(0, 0, box_width, box_height)
fill(1)
plot(label)
return box_width, box_height
stylesheet("subject", "proxima nova", "regular", 14)
stylesheet("domain", "proxima nova", "thin", 32)
def horizontal_grid(**kwargs):
"""prints a grid of horizontally scrubbable subjects and domains"""
y_pos = 0
seed = kwargs.get('seed')
expand = kwargs.get('expand')
for domain_title, domain in domain_list[1:]:
x_pos = 0
box_height = 0
default_width = kwargs.get('default_width', 150)
subject_area = 1024
with translate(x_pos, y_pos):
w, h = subject_box(domain_title, subject_color_for(domain), "domain",
min_width=None, padding={'right': 80})
x_pos += w
if expand:
subject_area -= x_pos
subject_count = len(subjects_for_domain(domain))
if subject_area - subject_count * default_width > 0:
default_width = subject_area / subject_count
for i, s in enumerate(subjects_for_domain(domain)):
with translate(x_pos, y_pos):
w, h = subject_box(s.get('title'),
random_domain_color(domain, seed=seed)[i],
"subject",
min_width=default_width)
x_pos += w
box_height = h
y_pos += box_height
horizontal_grid(seed=51, expand=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment