示例#1
0
文件: pacman.py 项目: yychiang/xy
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(315, 380)
    drawing.render().write_to_png('pac.png')
    xy.draw(drawing)
示例#2
0
文件: test.py 项目: RolandJuno/xy
from poisson_disc import poisson_disc
import random
import xy

random.seed(1182)
points, pairs = poisson_disc(0, 0, 315, 315, 1, 16)
drawing = xy.Drawing(pairs)
print len(drawing.paths)
drawing = drawing.linemerge()
print len(drawing.paths)
drawing.render().write_to_png('test.png')
paths = drawing.paths
paths = xy.sort_paths_greedy(paths)
paths = xy.join_paths(paths)
print len(paths)
xy.draw(paths)
示例#3
0
# Generate the poisson_disc with paired points, and produce a drawing object from it
random.seed(1337)
r = 0.70
n = 12
points, pairs = poisson_disc(0, 0, 120, 120, r, n)
drawing = xy.Drawing(pairs)
print 'Raw number of paths: %s' % len(drawing.paths)

# Merge the lines and see how much it's reduced
drawing = drawing.linemerge()
print 'Paths after linemerge: %s' % len(drawing.paths)

# Sort the paths and join them, optimized for the xy plotter
paths = drawing.paths
paths = xy.sort_paths_greedy(paths)
paths = xy.join_paths(paths)
print 'Paths after xy optimization: %s' % len(paths)

for tolerance in [0, 1]:
    print('Simplyfiying based on tolerance %s' % tolerance)
    simplified_paths = paths
    if tolerance:
        simplified_paths = xy.simplify_paths(paths, tolerance=tolerance)

    print('Drawing...')
    drawing = xy.Drawing(simplified_paths)
    im = drawing.render()
    im.write_to_png('test_t%s_n%s_r%s.png' % (tolerance, n, r))

xy.draw(paths, tolerance=1)
示例#4
0
文件: pacman.py 项目: RolandJuno/xy
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(315, 380)
    drawing.render().write_to_png('pac.png')
    xy.draw(drawing)