Ejemplo n.º 1
0
Archivo: main.py Proyecto: zbanks/axi
def main():
    args = parser.parse_args()
    d = None
    #if args.axi is not None:

    if args.command == 'render':
        d = axi.Drawing.load(args.axi)
        d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
        im = d.render()
        im.write_to_png(args.output)
        return
    device = axi.Device()
    if args.command == 'zero':
        device.zero_position()
    elif args.command == 'home':
        device.home()
    elif args.command == 'up':
        device.pen_up()
    elif args.command == 'down':
        device.pen_down()
    elif args.command == 'on':
        device.enable_motors()
    elif args.command == 'off':
        device.disable_motors()
    elif args.command == 'move':
        device.move(args.dx, args.dy)
    elif args.command == 'goto':
        device.goto(args.x, args.y)
    elif args.command == 'draw':
        d = axi.Drawing.load(args.axi)
        axi.draw(d)
    else:
        parser.error("command required")
Ejemplo n.º 2
0
def drawing_end(raw=False):
    global paths
    global title
    d = axi.Drawing(paths)
    text_pos = (PADDING, V3_SIZEX-PADDING)
    if not raw:
        if cfg.y_up:
            d = d.scale(1.0, -1.0)
        d = d.scale_to_fit(CELLSIZEX, CELLSIZEY, PADDING)
        d = d.translate(POSX*CELLSIZEX,  POSY*CELLSIZEY)
        text_pos = (POSX*CELLSIZEX, (POSY+1)*CELLSIZEY-PADDING)
        nextpos()
        
    if title:
        font = axi.Font(axi.FUTURAL, 7.5) # 
        dtext = font.text(title)
        dtext 
        dtext = dtext.translate(*text_pos)
        d.add(dtext)

    axi.draw(d)
    
    title = '' # Reset title

    print("DRAWING END")
    print("")
Ejemplo n.º 3
0
def main():
    args = sys.argv[1:]
    if len(args) == 0:
        return
    command, args = args[0], args[1:]
    command = command.lower()
    device = axi.Device()
    if command == 'zero':
        device.zero_position()
    elif command == 'home':
        device.home()
    elif command == 'up':
        device.pen_up()
    elif command == 'down':
        device.pen_down()
    elif command == 'on':
        device.enable_motors()
    elif command == 'off':
        device.disable_motors()
    elif command == 'move':
        dx, dy = map(float, args)
        device.move(dx, dy)
    elif command == 'goto':
        x, y = map(float, args)
        device.goto(x, y)
    elif command == 'draw':
        d = axi.Drawing.load(args[0])
        axi.draw(d)
    else:
        pass
Ejemplo n.º 4
0
def main():
    filename = sys.argv[1]
    print('loading image')
    im = Image.open(filename)
    im = im.convert('L')
    w, h = im.size
    data = list(im.getdata())
    paths = []
    for y in range(h):
        for x in range(w):
            if data[y * w + x] == 0:
                paths.append([(x, y), (x, y)])
    random.shuffle(paths)
    print(len(paths))
    d = axi.Drawing(paths)
    print('transforming paths')
    # d = d.scale(1, -1)
    d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
    # print 'sorting paths'
    # d = d.sort_paths()
    # print 'joining paths'
    # d = d.join_paths(0.05)
    # print len(d.paths)
    print('sorting paths')
    d = d.sort_paths()
    print('joining paths')
    d = d.join_paths(0.03)
    print(len(d.paths))
    d.paths = [x for x in d.paths if len(x) > 2]
    print('simplifying paths')
    d = d.simplify_paths(0.002)
    print(len(d.paths))
    print('rendering paths')
    d.render(line_width=0.3 / 25.4).write_to_png('out.png')
    axi.draw(d)
Ejemplo n.º 5
0
def main():
    # random.seed(1182)
    points, pairs = poisson_disc(0, 0, 11, 8.5, 0.035, 32)
    path = make_path(pairs)
    drawing = axi.Drawing([path]).scale_to_fit(11, 8.5)
    drawing.render().write_to_png('out.png')
    axi.draw(drawing)
Ejemplo n.º 6
0
def main(iteration):
    turtle = axi.Turtle()
    for i in range(1, 2**iteration):
        turtle.forward(1)
        if (((i & -i) << 1) & i) != 0:
            turtle.circle(-1, 90, 36)
        else:
            turtle.circle(1, 90, 36)
    drawing = turtle.drawing.rotate_and_scale_to_fit(11, 8.5, step=90)
    axi.draw(drawing)
Ejemplo n.º 7
0
def main(seed):
    n = 90/2
    gs = []
    g = Generation()
    g.randomize(24, 24, 0.3, seed)
    for i in range(n + 10):
        gs.append(g)
        g = g.next()
    d = lines(gs[-n:])
    d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
    d = d.sort_paths().join_paths(0.02)
    im = d.render()
    im.write_to_png('%06d.png' % seed)
    axi.draw(d)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def main():
    points = poisson_disc(0, 0, 12, 8.5, 0.4, 64)
    index = Index(points)
    paths = []
    for x1, y1 in points:
        index.remove((x1, y1))
        x2, y2 = index.nearest((x1, y1))
        index.insert((x1, y1))
        d = math.hypot(x2 - x1, y2 - y1)
        paths.append(star(x1, y1, d / 2))
    drawing = axi.Drawing(paths)
    drawing = drawing.remove_paths_outside(12, 8.5)
    drawing = drawing.sort_paths()
    im = drawing.render()
    im.write_to_png('out.png')
    axi.draw(drawing)
Ejemplo n.º 10
0
def main():
    system = axi.LSystem({
        'A': 'A-B--B+A++AA+B-',
        'B': '+A-BB--B-A++A+B',
    })
    d = system.run('A', 5, 60)
    # system = axi.LSystem({
    #     'X': 'F-[[X]+X]+F[+FX]-X',
    #     'F': 'FF',
    # })
    # d = system.run('X', 6, 20)
    d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
    # d = d.sort_paths()
    # d = d.join_paths(0.015)
    d.render().write_to_png('out.png')
    axi.draw(d)
Ejemplo n.º 11
0
def main():
    filename = sys.argv[1]
    print 'loading paths'
    d = axi.Drawing(axi.load_paths(filename))
    print 'eliminating duplicate paths'
    d.paths = list(set([tuple(x) for x in d.paths]))
    print 'transforming paths'
    d = d.scale(1, -1)
    d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
    print 'sorting paths'
    d = d.sort_paths()
    print 'joining paths'
    d = d.join_paths(0.02)
    print 'simplifying paths'
    d = d.simplify_paths(0.001)
    print 'rendering paths'
    d.render(line_width=0.25 / 25.4).write_to_png('out.png')
    axi.draw(d)
Ejemplo n.º 12
0
def main():
    # axi.reset()
    # return

    model = Model()
    for x, y in polygon(5, 0.35):
        model.add(x, y, 1)
    model.add(0.5, 0.5, 0.1)

    paths = []
    for _ in range(500):
        x = random.random()
        y = random.random()
        path = create_path(model, 8.5, 1.25, 0, x, y, -1, 3)
        paths.append(path)

    drawing = axi.Drawing(paths).sort_paths().simplify_paths(0.001)
    axi.draw(drawing)
Ejemplo n.º 13
0
def main():
    # seed = random.randint(0, 99999999)
    # print seed
    random.seed(82480774)
    segments = [
        make_segment(X1, Y1, X2, Y1),
        make_segment(X1, Y2, X2, Y2),
        make_segment(X1, Y2, X1, Y1),
        make_segment(X2, Y2, X2, Y1),
    ]
    for i in range(50):
        # print i
        segment = new_segment(segments)
        segments.append(segment)
    paths = []
    for segment in segments:
        paths.append(list(segment.coords))
    d = axi.Drawing(paths)
    d = d.sort_paths()
    d = d.join_paths(0.001)
    d.render().write_to_png('out.png')
    axi.draw(d)
Ejemplo n.º 14
0
def main():
    args = sys.argv[1:]
    if len(args) == 0:
        return
    command, args = args[0], args[1:]
    command = command.lower()
    if command == 'render':
        d = axi.Drawing.load(args[0])
        d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
        path = args[1] if len(args) > 1 else 'out.png'
        im = d.render(scale=109 * 1, line_width=0.25 / 25.4)
        # show_axi_bounds=False, use_axi_bounds=False)
        im.write_to_png(path)
        return
    device = axi.Device()
    if command == 'zero':
        device.zero_position()
    elif command == 'home':
        device.home()
    elif command == 'up':
        device.pen_up()
    elif command == 'down':
        device.pen_down()
    elif command == 'on':
        device.enable_motors()
    elif command == 'off':
        device.disable_motors()
    elif command == 'move':
        dx, dy = map(float, args)
        device.move(dx, dy)
    elif command == 'goto':
        x, y = map(float, args)
        device.goto(x, y)
    elif command == 'draw':
        d = axi.Drawing.load(args[0])
        axi.draw(d)
    else:
        pass
Ejemplo n.º 15
0
def main():
    font = axi.FUTURAM
    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.scale_to_fit(12, 0.25)
    # d = d.center(12, 8.5)
    d = d.move(6, 0, 0.5, 0)
    d = d.translate(0, 0.01)

    d = d.move(6, 8.5, 0.5, 1)
    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))
    axi.draw(d)
Ejemplo n.º 16
0
def main():
    paths = []
    add(0, 0, 2, paths)
    new_path = [paths.pop()]
    drawing = axi.Drawing(new_path).rotate_and_scale_to_fit(2, 2)
    axi.draw(drawing)
Ejemplo n.º 17
0
def main():
    # parse osm file into shapely geometries
    geometries = osm2shapely.parse(sys.argv[1])

    # setup map projection
    projection = LambertAzimuthalEqualAreaProjection(LAT, LNG)
    geometries = [projection.transform(g) for g in geometries]

    # determine width and height of map
    w = MAP_WIDTH_KM
    if LANDSCAPE:
        h = float(w) * PAGE_HEIGHT_IN / PAGE_WIDTH_IN
    else:
        h = float(w) * PAGE_WIDTH_IN / PAGE_HEIGHT_IN

    # process geometries
    gs = []
    roads = []
    for g in geometries:
        highway = g.tags.get('highway')
        if highway and highway in WEIGHTS:
            weight = WEIGHTS[highway]
            if weight:
                g = g.buffer(LANE_WIDTH_M / 1000.0 * weight)
            g = crop(g, w * 1.1, h * 1.1)
            roads.append(g)
        # elif 'natural' in g.tags:
        #     gs.append(g)
        elif 'building' in g.tags:
            gs.append(g)

    print 'crop'
    gs = [crop(g, w * 1.1, h * 1.1) for g in gs]
    roads = [crop(g, w * 1.1, h * 1.1) for g in roads]

    # gs = []
    # for key, ways in handler.ways.items():
    #     if key not in WEIGHTS:
    #         print 'skip', key, len(ways)
    #         continue
    #     print 'layer', key, len(ways)
    #     ggs = []
    #     for way in ways:
    #         coords = [projection.project(*handler.coords[x]) for x in way]
    #         if key == 'natural' and coords[0] == coords[-1]:
    #             ggs.append(geometry.Polygon(coords))
    #         else:
    #             ggs.append(geometry.LineString(coords))
    #     # g = paths_to_shapely(paths)
    #     g = geometry.collection.GeometryCollection(ggs)
    #     if key == 'railway':
    #         paths = shapely_to_paths(g)
    #         g = paths_to_shapely(paths)
    #         points = follow(g, 20 / 1000.0)
    #         s = 4 / 1000.0
    #         for x, y, a in points:
    #             x1 = x + math.cos(a + math.pi / 2) * s
    #             y1 = y + math.sin(a + math.pi / 2) * s
    #             x2 = x + math.cos(a - math.pi / 2) * s
    #             y2 = y + math.sin(a - math.pi / 2) * s
    #             paths.append([(x1, y1), (x2, y2)])
    #         g = paths_to_shapely(paths)
    #     if key == 'natural':
    #         gs.append(crop(paths_to_shapely(shapely_to_paths(g)), w * 1.1, h * 1.1))
    #         paths = hatch(g, 45, 10 / 1000.0)
    #         g = paths_to_shapely(paths)
    #     weight = WEIGHTS[key]
    #     if weight:
    #         g = g.buffer(LANE_WIDTH_M / 1000.0 * weight)
    #     g = crop(g, w * 1.1, h * 1.1)
    #     gs.append(g)

    print 'union'
    roads = ops.cascaded_union(roads)
    all_roads = []
    while not roads.is_empty:
        all_roads.append(roads)
        roads = roads.buffer(-LANE_WIDTH_M / 1000.0 / 3)
    g = geometry.collection.GeometryCollection(gs + all_roads)
    g = paths_to_shapely(shapely_to_paths(g))

    print 'crop'
    g = crop(g, w, h)

    paths = shapely_to_paths(g)

    # dot at origin
    # s = 3 / 1000.0 / 3
    # for i in range(4):
    #     paths.append(circle(0, 0, i * s, 360))

    # border around map
    s = 6 / 1000.0 / 2
    for m in range(1):
        paths.append(box(w - s * m, h - s * m))

    print 'axi'
    d = axi.Drawing(paths)
    d = d.rotate_and_scale_to_fit(PAGE_WIDTH_IN, PAGE_HEIGHT_IN, step=90)
    d = d.sort_paths().join_paths(0.002).simplify_paths(0.002)
    im = d.render()
    im.write_to_png('out.png')
    axi.draw(d)
Ejemplo n.º 18
0
def main():
    path = []
    for i in range(10):
        path.extend(circle(4, 4, (i + 1) * 0.2, 3600))
    drawing = axi.Drawing([path]).simplify_paths(0.001)
    axi.draw(drawing)
Ejemplo n.º 19
0
def main():
    paths = create_paths(Image.open(sys.argv[1]))
    drawing = axi.Drawing(paths).rotate_and_scale_to_fit(11, 8.5, step=90)
    drawing = drawing.sort_paths().join_paths(0.02)
    axi.draw(drawing)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
import axi
import time

d = axi.Device()
d.enable_motors()

turtle = axi.Turtle()

##turtle.goto(0,0)
#
#turtle.pd()
#turtle.pu()

turtle.goto(5, 1)

for i in range(360):
    print "move forward by 1"
    #turtle.pd() # pen down
    turtle.forward(0.01)  # gehe 0.5inch nach vorwaerts
    turtle.rt(1)  # drehe dich um 60grad
    #turtle.pu() # pen up

drawing = turtle.drawing
axi.draw(drawing)
d.disable_motors()