Exemplo n.º 1
0
def create_drawing(filename, x, y, w, h, p):
    paths = load_paths(filename)
    paths = xy.remove_duplicates(paths)
    drawing = xy.Drawing(paths)
    drawing = drawing.rotate_and_scale_to_fit(w - p, h - p, step=5)
    drawing = drawing.move(x + w / 2, y + h / 2, 0.5, 0.5)
    return drawing
Exemplo n.º 2
0
def main():
    paths = create_paths()
    drawing = xy.Drawing(paths).origin().scale_to_fit(240, 165).center()
    drawing = drawing.sort_paths()
    im = drawing.render()
    im.write_to_png('eyes.png')
    xy.draw(drawing)
Exemplo n.º 3
0
def main():
    device = xy.Device()
    time.sleep(2)
    device.pen_up()
    time.sleep(1)
    device.home()
    print 'main'
    im = cv2.imread('/Users/fogleman/Workspace/maptiles/zoom20clean.png')
    im = isolate_buildings(im)
    # im = combine_images()
    contours = find_contours(im)
    contours = filter_contours(contours)
    print len(contours)
    im[:] = 0
    cv2.drawContours(im, contours, -1, 255, -1)
    cv2.imwrite('out.png', im)
    paths = contour_paths(contours)
    print 'scaling paths'
    drawing = xy.Drawing(paths).rotate_and_scale_to_fit(315, 380, step=90).scale(1, -1)
    drawing = drawing.move(300, 0, 1, 0)
    drawing.render().write_to_png('buildings.png')
    print 'drawing paths'
    paths = drawing.paths
    paths.sort(key=lambda path: path[0][1])
    n = 100
    for i in range(0, len(paths), n):
        print i
        group = paths[i:i+n]
        group.sort(key=lambda path: path[0][0])
        for path in group:
            device.draw(xy.simplify(path, 0.05))
Exemplo n.º 4
0
def main():
    t0 = 0
    t1 = pi * 24
    n = 100000
    path = [butterfly(t) for t in times(t0, t1, n)]
    drawing = xy.Drawing([path]).scale_to_fit(315, 380)
    xy.draw(drawing)
Exemplo n.º 5
0
def main():
    points = [(0, 0)] + hexagon()
    corners = [
        (2, 1, 6),
        (1, 2, 0),
        (2, 0, 6),
        (0, 6, 1),
        (0, 2, 3),
        (2, 3, 4),
        (3, 4, 0),
        (4, 0, 2),
        (4, 0, 6),
        (0, 6, 5),
        (6, 5, 4),
        (5, 4, 0),
    ]
    paths = []
    for a, b, c in corners:
        p1 = points[a]
        p2 = points[b]
        p3 = points[b]
        p4 = points[c]
        paths.extend(lines(p1, p2, p3, p4, 32))
    drawing = xy.Drawing(paths).scale_to_fit(315, 380)
    drawing = drawing.sort_paths()
    drawing.render().write_to_png('lines.png')
    xy.draw(drawing)
Exemplo n.º 6
0
def main():
    args = sys.argv[1:]
    if len(args) != 1:
        print('Usage: python main.py input_image')
        return
    paths = []
    model = Model(args[0])
    previous = None
    for i in range(ITERATIONS):
        error = model.average_error()
        if previous is None or previous - error > ERROR_RATE:
            print(i, error)
            if SAVE_FRAMES:
                model.render('frames/%06d.png' % i)
            previous = error
        paths.extend(model.split())
    model.render('output.png')
    print('-' * 32)
    depth = Counter(x.depth for x in model.quads)
    for key in sorted(depth):
        value = depth[key]
        n = 4**key
        pct = 100.0 * value / n
        print('%3d %8d %8d %8.2f%%' % (key, n, value, pct))
    print('-' * 32)
    print('             %8d %8.2f%%' % (len(model.quads), 100))
    # for max_depth in range(max(depth.keys()) + 1):
    #     model.render('out%d.png' % max_depth, max_depth)
    drawing = xy.Drawing(paths).scale_to_fit(315, 315)
    drawing.render().write_to_png('quads.png')
Exemplo n.º 7
0
def main():
    paths = []
    for path in PATHS:
        paths.extend(xy.parse_svg_path(path))
    drawing = xy.Drawing(paths).scale(1, -1).scale_to_fit(9 * 25.4, 12 * 25.4)
    im = drawing.render()
    im.write_to_png('svg.png')
    xy.draw(drawing)
Exemplo n.º 8
0
def main():
    im = Image.open(sys.argv[1])
    paths = create_paths(im)
    drawing = xy.Drawing(paths).rotate_and_scale_to_fit(315, 380, step=90)
    drawing = drawing.sort_paths()
    drawing = drawing.join_paths(tolerance = 0.1)
    im = drawing.render()
    im.write_to_png('image.png')
Exemplo n.º 9
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 = xy.Drawing(xy.text(text, self.font, extra=e))
     d = d.scale(self.scale)
     return d
Exemplo n.º 10
0
def main(filenames, nx):
    paths = []
    w = h = 100
    p = 10
    for index, filename in enumerate(filenames):
        i = index % nx
        j = index / nx
        x = i * w
        y = j * h
        drawing = create_drawing(filename, x, y, w, h, p)
        paths.extend(drawing.paths)
    drawing = xy.Drawing(paths)
    drawing = xy.Drawing(paths).rotate_and_scale_to_fit(315, 380, step=90)
    drawing = drawing.move(315 / 2.0, 380 / 2.0, 0.5, 0.5)
    # drawing.paths = [x for x in drawing.paths if len(x) > 1]
    # drawing = drawing.simplify_paths()
    drawing = drawing.sort_paths_greedy()
    drawing = drawing.join_paths()
    # drawing = drawing.simplify_paths()
    im = drawing.render()
    im.write_to_png('grid.png')
Exemplo n.º 11
0
def main(filename):
    paths = load_paths(filename)
    paths = xy.remove_duplicates(paths)
    drawing = xy.Drawing(paths).rotate_and_scale_to_fit(315, 380, step=90)
    # drawing = drawing.move(315 / 2.0, 380 / 2.0, 0.5, 0.5)
    drawing.paths = [x for x in drawing.paths if len(x) > 1]
    # drawing = drawing.simplify_paths()
    drawing = drawing.sort_paths_greedy()
    drawing = drawing.join_paths()
    # drawing = drawing.simplify_paths()
    im = drawing.render()
    im.write_to_png('paths.png')
    xy.draw(drawing)
Exemplo n.º 12
0
def create_drawing(rule, h):
    rows = compute_rows(rule, h)
    rows = pad(rows)
    rows = crop_diagonal(rows)
    # rows = crop(rows)
    rows = pad(rows)
    pairs, points = form_pairs(rows)
    paths = [trim_pair(x, 0.25) for x in pairs]
    for x, y in points:
        paths.append(xy.circle(x, y, 0.25))
    drawing = xy.Drawing(paths)
    drawing = drawing.scale(1, -1).rotate(45)
    drawing = drawing.scale_to_fit(315, 380)
    return drawing
Exemplo n.º 13
0
def main():
    paths = []
    for i in range(50):
        x = i / 100.0
        paths.append([
            (0 + x, 0 + x),
            (1 - x, 0 + x),
            (1 - x, 1 - x),
            (0 + x, 1 - x),
            (0 + x, 0 + x),
        ])
    paths = [xy.xkcdify(path, 0.005, 0.01 / 4) for path in paths]
    drawing = xy.Drawing(paths).scale_to_fit(315, 380)
    im = drawing.render()
    im.write_to_png('xkcd.png')
Exemplo n.º 14
0
def main():
    paths = []
    for path in PATHS:
        path = xy.parse_svg_path(path)
        path.append(path[0])
        paths.extend(path)
    polygons = [geometry.Polygon(x) for x in paths]
    lines = geometry.MultiPolygon(polygons)
    for i in range(4):
        n = 3 - i
        o = i * 10
        for j in range(-n, n + 1):
            paths += convert(lines.buffer(o + j * 0.667))
    drawing = xy.Drawing(paths).scale(1, -1).rotate_and_scale_to_fit(315,
                                                                     380,
                                                                     step=90)
    im = drawing.render()
    im.write_to_png('frog.png')
Exemplo n.º 15
0
 def wrap(self, text, width, line_spacing=1, align=0, justify=False):
     lines = word_wrap(text, width, self.measure)
     ds = [self.text(line) for line in lines]
     max_width = max(d.width for d in ds)
     if justify:
         jds = [self.justify_text(line, max_width) for line in lines]
         ds = jds[:-1] + [ds[-1]]
     spacing = line_spacing * self.max_height * self.scale
     result = xy.Drawing()
     y = 0
     for d in ds:
         if align == 0:
             x = 0
         elif align == 1:
             x = max_width - d.width
         else:
             x = max_width / 2 - d.width / 2
         result.add(d.translate(x, y))
         y += spacing
     return result
Exemplo n.º 16
0
def create_drawing():
    random.seed(1004)
    occupied = set()
    pipes = [Pipe(occupied) for _ in range(PIPES)]
    for _ in range(60000):
        done = True
        for pipe in pipes:
            if pipe.update():
                done = False
        if done:
            break
    print(len(occupied))
    shapes = []
    for pipe in pipes:
        pipe.add_sphere(pipe.position)
        shapes.extend(pipe.shapes)
    print(len(shapes))
    scene = xyz.Scene(shapes)
    paths = scene.render((25, 25, 10), (0, 0, 0), (0, 0, 1), 60, 1, 0.1, 100,
                         0.05)
    # paths.append([(-1, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)])
    drawing = xy.Drawing(paths).rotate(90).scale_to_fit(315, 380).rotate(-90)
    return drawing
Exemplo n.º 17
0
def main():
    shapes = []
    for x in range(-4, 5):
        for y in range(-4, 5):
            z = random.random() * 2
            r = random.random() + 0.5
            shapes.append(xyz.Sphere(r, (x, y, z)))
            # shapes.append(pipe((x, y, 0), (x, y, z), 0.25))
            # shapes.append(sphere(x, y, z, 0.25))

    # shapes.append(sphere(0, 0, 0, 0.5))
    # shapes.append(pipe((0, 1, 2), (0, 3, 2), 0.25))
    # shapes.append(pipe((-3, -1, 5), (3, -1, 5), 0.25))
    # shapes.append(sphere(-3, -1, 5, 0.25))
    # shapes.append(sphere(3, -1, 5, 0.25))
    # shapes.append(sphere(0, 1, 2, 0.25))
    # shapes.append(sphere(0, 3, 2, 0.25))
    # shapes.append(pipe((0, 0, 1), (0, 0, 4), 0.25))
    # shapes.append(pipe((0, 1, 0), (0, 1, 3), 0.25))

    # shapes.append(pipe((-1, 0, 0), (1, 0, 0), 0.5))
    # shapes.append(pipe((0, -1, 0), (0, 1, 0), 0.5))
    # shapes.append(pipe((0, 0, -1), (0, 0, 1), 0.5))
    # shapes.append(sphere(-1, 0, 0, 0.5, 0))
    # shapes.append(sphere(0, -1, 0, 0.5, 1))
    # shapes.append(sphere(0, 0, -1, 0.5, 2))
    # shapes.append(sphere(1, 0, 0, 0.5, 0))
    # shapes.append(sphere(0, 1, 0, 0.5, 1))
    # shapes.append(sphere(0, 0, 1, 0.5, 2))
    scene = xyz.Scene(shapes)
    paths = scene.render((20, 20, 10), (0, 0, 0), (0, 0, 1), 30, 1, 0.1, 100,
                         0.05)
    # paths.append([(-1, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)])
    drawing = xy.Drawing(paths).scale_to_fit(315, 380)
    drawing = drawing.sort_paths_greedy().join_paths()
    drawing.render().write_to_png('three.png')
Exemplo n.º 18
0
def main():
    paths = create_paths()
    drawing = xy.Drawing(paths).scale_to_fit(315, 380)
    drawing = drawing.sort_paths_greedy()
    im = drawing.render()
    im.write_to_png('radial.png')
Exemplo n.º 19
0
def main():
    im = Image.open(sys.argv[1])

    paths = []

    # for x, y in get_points(im):
    #     paths.extend(create_paths(x, -y))

    # maze
    paths = []
    paths.extend(find_lines(im))
    for x, y in find_curve1(im):
        paths.append(xy.arc(x + 2, -y - 2, 2, 90, 180))
    for x, y in find_curve2(im):
        paths.append(xy.arc(x + 2, -y - 1, 2, 180, 270))
    for x, y in find_curve3(im):
        paths.append(xy.arc(x + 1, -y - 2, 2, 0, 90))
    for x, y in find_curve4(im):
        paths.append(xy.arc(x + 1, -y - 1, 2, 270, 360))
    for x, y in find_big_curve1(im):
        paths.append(xy.arc(x + 4, -y - 4, 4, 90, 180))
    for x, y in find_big_curve2(im):
        paths.append(xy.arc(x + 4, -y - 0, 4, 180, 270))
    for x, y in find_big_curve3(im):
        paths.append(xy.arc(x + 0, -y - 4, 4, 0, 90))
    for x, y in find_big_curve4(im):
        paths.append(xy.arc(x + 0, -y - 0, 4, 270, 360))
    for x, y in find_small_curve1(im):
        paths.append(xy.arc(x + 2, -y - 2, 1, 90, 180))
    for x, y in find_small_curve2(im):
        paths.append(xy.arc(x + 2, -y - 2, 1, 180, 270))
    for x, y in find_small_curve3(im):
        paths.append(xy.arc(x + 2, -y - 2, 1, 0, 90))
    for x, y in find_small_curve4(im):
        paths.append(xy.arc(x + 2, -y - 2, 1, 270, 360))
    for x, y in find_bar(im):
        paths.append([(x + 1, -y - 1), (x + 18, -y - 1)])
        paths.append([(x + 1, -y - 2), (x + 18, -y - 2)])
        paths.append([(x + 1, -y - 0), (x + 1, -y - 3)])
        paths.append([(x + 18, -y - 0), (x + 18, -y - 3)])
    maze_paths = xy.join_paths(xy.sort_paths_greedy(paths))

    # ghosts
    paths = []
    for x, y in find_ghosts(im):
        paths.append(xy.arc(x + 6.5, -y + 4.5, 6.5, 0, 180))
        paths.append([(x, -y + 4.5), (x, -y - 2)])
        paths.append([(x + 13, -y + 4.5), (x + 13, -y - 2)])
        paths.append([(x, -y - 2), (x + 2, -y)])
        paths.append([(x + 4, -y - 2), (x + 2, -y)])
        paths.append([(x + 4, -y - 2), (x + 6.5, -y)])
        paths.append([(x + 13, -y - 2), (x + 13 - 2, -y)])
        paths.append([(x + 13 - 4, -y - 2), (x + 13 - 2, -y)])
        paths.append([(x + 13 - 4, -y - 2), (x + 13 - 6.5, -y)])
    ghost_paths = xy.join_paths(xy.sort_paths_greedy(paths))

    # pacman
    paths = []
    x, y = 113, -189
    paths.append(xy.arc(x, y, 6.5, 225, 135 + 360))
    x1 = x + 6.5 * math.cos(math.radians(135))
    y1 = y + 6.5 * math.sin(math.radians(135))
    x2 = x + 6.5 * math.cos(math.radians(225))
    y2 = y + 6.5 * math.sin(math.radians(225))
    paths.append([(x1, y1), (x + 2, y)])
    paths.append([(x2, y2), (x + 2, y)])
    pacman_paths = xy.join_paths(xy.sort_paths_greedy(paths))

    # dots
    paths = []
    for x, y in find_dots(im):
        paths.append(xy.circle(x + 1.5, -y - 1.5, 1))
    for x, y in find_big_dots(im):
        paths.append(xy.circle(x + 3.5, -y - 4.5, 4))
    dot_paths = xy.join_paths(xy.sort_paths_greedy(paths))

    paths = maze_paths + ghost_paths + pacman_paths + dot_paths
    drawing = xy.Drawing(paths).scale_to_fit(240, 180)
    drawing.render().write_to_png('pac.png')
Exemplo n.º 20
0
        x = new_lo + p * (new_hi - new_lo)
        result.append(x)
    return result

random.seed(13)

N = 400

noises = [random.random() * 2 - 1 for _ in range(N)]
for _ in range(3):
    noises = low_pass(noises, 0.2)
noises = normalize(noises, -1, 1)

paths = []
x = 0
y = 0
m = 0.5
for i, n in enumerate(noises):
    r = i + 1 #N - i
    paths.append(xy.circle(x, y, r, 120))
    a = n * math.pi
    x += math.cos(a) * m
    y += math.sin(a) * m

drawing = xy.Drawing(paths)
width = 250
height = 175
drawing = drawing.crop_paths(-width/2, -height/2, width/2, height/2).center(width, height)
drawing.render().write_to_png('contain.png')
xy.draw(drawing)
Exemplo n.º 21
0
 def text(self, text):
     d = xy.Drawing(xy.text(text, self.font))
     d = d.scale(self.scale)
     return d
Exemplo n.º 22
0
 def __init__(self, font, point_size):
     self.font = font
     self.max_height = xy.Drawing(xy.text(string.printable, font)).height
     # self.cap_height = xy.Drawing(xy.text('H', font)).height
     height = point_size / 72
     self.scale = height / self.max_height