Exemple #1
0
def title():
    d1 = axi.Drawing(axi.text('Topography of', axi.METEOROLOGY))
    d1 = d1.scale_to_fit_height(0.25)
    d2 = axi.Drawing(axi.text('Vancouver Island', axi.METEOROLOGY))
    d2 = d2.scale_to_fit_height(0.375)
    d = vertical_stack([d1, d2], 0.125, False)
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    d = d.move(0, 8.5, 0, 1)
    return d
Exemple #2
0
def title(rule):
    d1 = axi.Drawing(axi.text('Rule %d' % rule, axi.FUTURAM))
    d1 = d1.scale_to_fit_height(0.25)
    d2 = axi.Drawing(axi.text('Elementary Cellular Automaton', axi.FUTURAL))
    d2 = d2.scale_to_fit_height(0.1875)
    ds = [d1, d2]
    d = vertical_stack(ds, 0.125)
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    return d
Exemple #3
0
def punchcard_from_csv(csv_path):
    with open(csv_path, 'rb') as fp:
        reader = csv.reader(fp)
        csv_rows = list(reader)
    row_labels = [x[0] for x in csv_rows[1:]]
    col_labels = csv_rows[0][1:]
    data = []
    for csv_row in csv_rows[1:]:
        row = []
        for value in csv_row[1:]:
            try:
                value = float(value)
            except ValueError:
                value = None
            row.append(value)
        data.append(row)
    lo = min(x for row in data for x in row if x)
    hi = max(x for row in data for x in row if x)
    min_area = math.pi * (MIN_SIZE / 2.0)**2
    max_area = math.pi * (MAX_SIZE / 2.0)**2
    paths = []
    for r, row in enumerate(data):
        for c, value in enumerate(row):
            if not value:
                continue
            pct = 1.0 * (value - lo) / (hi - lo)
            pct = pct**0.5
            area = pct * (max_area - min_area) + min_area
            radius = (area / math.pi)**0.5
            paths.extend(fill_circle(c, r, radius, 90))
    for r, label in enumerate(row_labels):
        d = axi.Drawing(axi.text(label.upper(), axi.TIMESR))
        d = d.scale(0.02, 0.02).move(-1, r, 0.5, 0.5)
        paths.extend(d.paths)
    for c, label in enumerate(col_labels):
        d = axi.Drawing(axi.text(label.upper(), axi.TIMESR))
        d = d.scale(0.02, 0.02).move(c, -1, 0.5, 0.5)
        paths.extend(d.paths)
    d = axi.Drawing(paths)
    d = d.scale_to_fit(12, 8.5)

    print('joining paths')
    d = d.join_paths(0.02)
    print('simplifying paths')
    d = d.simplify_paths(0.001)

    d.render().write_to_png('out.png')
    axi.draw(d)
Exemple #4
0
def multiple_label(text):
    d = axi.Drawing(axi.text(text, axi.FUTURAL))
    d = d.scale_to_fit_height(0.125)
    d = d.move(0, 8.5, 0, 1)
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    return d
Exemple #5
0
def label():
    d = axi.Drawing(axi.text(LABEL, axi.FUTURAL))
    d = d.scale_to_fit_height(0.125)
    d = d.rotate(-90)
    d = d.move(12, 8.5, 1, 1)
    d = d.join_paths(0.01)
    return d
Exemple #6
0
def vpype_text(string, font, size, position, align):
    """
    Generate text using a Hershey font.
    """

    # skip if text is empty
    if string.strip() == "":
        return vp.LineCollection()

    lines = axi.text(string, font=FONTS[font])
    lc = vp.LineCollection()
    for line in lines:
        lc.append([x + 1j * y for x, y in line])

    # by default, axi's font appear to be approx 18px size
    scale_factor = size / 18.0
    lc.scale(scale_factor, scale_factor)

    min_x, _, max_x, _ = lc.bounds()
    if align == "left":
        lc.translate(-min_x, 0)
    elif align == "center":
        lc.translate(-(max_x - min_x) / 2, 0)
    elif align == "right":
        lc.translate(-max_x, 0)
    else:
        logging.warning(f"text: unknown align parameters: {align}")

    lc.translate(position[0], position[1])

    return lc
Exemple #7
0
def title():
    d = axi.Drawing(
        axi.text('Topography of the Western United States', axi.FUTURAM))
    d = d.scale_to_fit_height(0.25)
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    return d
Exemple #8
0
def title():
    ds = [axi.Drawing(axi.text(line, axi.TIMESIB)) for line in TITLE]
    spacing = max(d.height for d in ds) * 1.5
    ds = [d.translate(-d.width / 2, i * spacing) for i, d in enumerate(ds)]
    d = concat(ds)
    d = d.scale_to_fit_width(8.5)
    d = d.join_paths(0.01)
    return d
def main():
    W = 8.5
    H = 0.5
    total = sum(x[1] for x in DATA)
    lo = min(x[0] for x in DATA)
    hi = max(x[0] for x in DATA)
    peak = max(x[1] for x in DATA)
    paths = []
    path = []
    for key, count in DATA:
        x = W * (key - lo) / (hi - lo)
        y = H * count / peak
        path.append((x, -y))
        if y > 0.01:
            paths.append([(x, 0), (x, -y)])
    paths.append(path)

    paths.append([(0, 0), (W, 0)])

    labels = [0, 1000, 2000, 3000, 3851]
    for key in labels:
        x = W * (key - lo) / (hi - lo)
        paths.append([(x, 0.0), (x, 0.05)])
        d = axi.Drawing(axi.text(str(key), axi.FUTURAL))
        d = d.scale_to_fit_height(0.1)
        d = d.move(x, 0.15, 0.5, 0)
        paths.extend(d.paths)

    title = 'Elevation Distribution (meters above sea level)'
    d = axi.Drawing(axi.text(title, axi.FUTURAL))
    d = d.scale_to_fit_height(0.15)
    d = d.move(W / 2, 0.3, 0.5, 0)
    paths.extend(d.paths)

    d = axi.Drawing(paths)
    d = d.rotate(180)
    d = d.rotate_and_scale_to_fit(8.5, 8.5, step=90)
    d = d.move(12, 8.5 / 2, 1, 0.5)
    print d.bounds

    d = d.sort_paths()
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)

    d.render().write_to_png('out.png')
    d.dump('out.axi')
Exemple #10
0
def lat_label(text, y):
    d = axi.Drawing(axi.text(text, axi.FUTURAL))
    d = d.scale_to_fit_height(0.1)
    d = d.move(WIDTH + 1 / 8, y, 0, 1)
    # d.paths.append(circle(12.125 + d.width + 1 / 16, y - d.height, 1 / 48, 36))
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    paths = d.paths
    # paths.append([(WIDTH, y), (WIDTH + 1 / 16, y)])
    return paths
Exemple #11
0
 def justify_text(self, text, width):
     d = self.text(text)
     w = d.width
     spaces = text.count(' ')
     if spaces == 0 or w >= width:
         return d
     e = ((width - w) / spaces) / self.scale
     d = axi.Drawing(axi.text(text, self.font, extra=e))
     d = d.scale(self.scale)
     return d
Exemple #12
0
def lng_label(text, x):
    d = axi.Drawing(axi.text(text, axi.FUTURAL))
    d = d.scale_to_fit_height(0.1)
    d = d.move(x, HEIGHT + 0.125, 0.5, 1)
    # d.paths.append(circle(x + d.width / 2 + 1 / 16, 8.5 + 0.125 - d.height, 1 / 48, 36))
    d = d.join_paths(0.01)
    d = d.simplify_paths(0.001)
    paths = d.paths
    paths.append([(x, HEIGHT - 1 / 8), (x, HEIGHT - 1 / 16)])
    return paths
 def __post_init__(self):
     super().__post_init__()
     lines = axi.text(self.text, self.font)
     self.item_lc = vp.LineCollection()
     for line in lines:
         self.item_lc.append([x + 1j * y for x, y in line])
     x1, y1, x2, y2 = self.item_lc.bounds()
     self.item_lc.translate(-(x1 + x2) / 2, -(y1 + y2) / 2)
     s = self.unit_length / (y2 - y1)
     self.item_lc.scale(s, -s)
Exemple #14
0
def multiple():
    w = 32
    h = 137

    # rules = [x for x in range(256) if bin(x).count('1') == 4]
    # rules = [18, 22, 26, 30, 41, 45, 54, 60, 73, 90, 105, 106, 110, 122, 126, 146, 150, 154]
    # rules = sorted(random.sample(rules, 6))
    # print rules

    # rules = sorted([22, 30, 60, 90, 106, 150, 105, 122, 154])
    rules = sorted([22, 30, 60, 90, 106, 150])
    ds = []
    for rule in rules:
        d1 = create_drawing(rule, w, h)
        d1 = d1.scale_to_fit_height(8)
        d2 = axi.Drawing(axi.text('Rule %d' % rule, axi.FUTURAL))
        d2 = d2.scale_to_fit_height(0.125)
        d = vertical_stack([d1, d2], 0.125)
        ds.append(d)
    title = axi.Drawing(axi.text('Elementary Cellular Automata', axi.FUTURAM))
    title = title.scale_to_fit_height(0.25)
    d = horizontal_stack(ds, 0.25)
    d = vertical_stack([title, d], 0.2)
    d = d.scale_to_fit(12, 8.5)
    # d.add(multiple_label('#31'))
    print len(d.paths)
    print 'joining paths'
    d = d.join_paths(0.01)
    print len(d.paths)
    print 'sorting paths'
    d = d.sort_paths()
    print len(d.paths)
    print 'joining paths'
    d = d.join_paths(0.01)
    print len(d.paths)
    print 'simplifying paths'
    d = d.simplify_paths(0.001)
    print d.bounds
    d.dump('out.axi')
    im = d.render(scale=109 * 1, line_width=0.3 / 25.4, show_axi_bounds=False)
    im.write_to_png('out.png')
Exemple #15
0
def subtitle():
    # ds = [axi.Drawing(p) for p in axi.justify_text(SUBTITLE, axi.TIMESR)]
    # spacing = max(d.height for d in ds) * 1.5
    # ds = [d.translate(0, i * spacing) for i, d in enumerate(ds)]
    ds = [axi.Drawing(axi.text(line, axi.TIMESR)) for line in SUBTITLE]
    spacing = max(d.height for d in ds) * 1.5
    ds = [d.translate(-d.width / 2, i * spacing) for i, d in enumerate(ds)]
    d = concat(ds)
    d = d.scale_to_fit_width(8.5 * 2 / 3)
    d = d.scale_to_fit_height(0.4)
    d = d.join_paths(0.01)
    return d
Exemple #16
0
def main():
    font = axi.SCRIPTS
    ds = [
        axi.Drawing(axi.text(line, font)).scale_to_fit_height(1)
        for line in LINES
    ]
    d = stack_drawings(ds, 0.1)
    # d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
    # d = d.scale(0.02, 0.02)
    # d = d.center(12, 8.5)
    # d = d.move(0, 0, 0, 0)
    d = d.scale_to_fit(12, 8.5)
    # d = d.center(12, 8.5)
    d = d.move(6, 0, 0.5, 0)
    d = d.translate(0, 0.01)
    d = d.join_paths(0.01)
    d.render().write_to_png('out.png')
    print sum(x.t for x in axi.Device().plan_drawing(d))
Exemple #17
0
def title():
    d = axi.Drawing(axi.text(TITLE, axi.FUTURAM))
    d = d.scale_to_fit_height(0.25)
    d = d.move(6, 8.5, 0.5, 1)
    d = d.join_paths(0.01)
    return d
def render_text(txt: str) -> vp.LineCollection:
    lines = axi.text(txt, font=axi.hershey_fonts.FUTURAL)
    text = vp.LineCollection()
    for line in lines:
        text.append([x + 1j * y for x, y in line])
    return text
Exemple #19
0
 def text(self, text):
     d = axi.Drawing(axi.text(text, self.font))
     d = d.scale(self.scale)
     return d
Exemple #20
0
 def __init__(self, font, point_size):
     self.font = font
     self.max_height = axi.Drawing(axi.text(string.printable, font)).height
     # self.cap_height = axi.Drawing(axi.text('H', font)).height
     height = point_size / 72
     self.scale = height / self.max_height
Exemple #21
0
def drawAxi(citation):
    #t = axi.text(citation, axi.FUTURAL)
    t = axi.text(citation, axi.GOTHICENG)
    drawing = axi.Drawing(t)
    drawing = drawing.rotate_and_scale_to_fit(11, 1, step=180)  #8.5
    axi.draw(drawing)