예제 #1
0
def debug_world(paths, width, height):
    dwg = Drawing(paths=paths, name="debug_world", bg=None)

    # Gray rectangle: the desired visible canvas.
    with dwg.style(rgb=(.95, .95, .95)):
        dwg.rectangle(0, 0, width, height)
        dwg.fill()

    # Reference grid.
    llx, lly = dwg.llx, dwg.lly
    urx = llx + dwg.width
    ury = lly + dwg.height
    with dwg.style(rgb=(.5, 1, 1), width=1, dash=[5, 5], dash_offset=7.5):
        for xmin in tick_range(llx, urx, 20):
            dwg.move_to(xmin, lly)
            dwg.line_to(xmin, ury)
            dwg.stroke()
        for ymin in tick_range(lly, ury, 20):
            dwg.move_to(llx, ymin)
            dwg.line_to(urx, ymin)
            dwg.stroke()

    with dwg.style(rgb=(.5, 1, 1), width=1):
        dwg.circle_points([Point(0, 0)], radius=10)
        for xmaj in tick_range(llx, urx, 100):
            dwg.move_to(xmaj, lly)
            dwg.line_to(xmaj, ury)
            dwg.stroke()
        for ymaj in tick_range(lly, ury, 100):
            dwg.move_to(llx, ymaj)
            dwg.line_to(urx, ymaj)
            dwg.stroke()

    # The paths themselves.
    dwg.draw_paths(paths, width=1, rgb=(1, 0, 0))

    dwg.finish()
    print("Wrote debug_world.png")
예제 #2
0
def straps(**opt):
    width, height = opt['size']

    TILEW = int(width / opt['tiles'])
    if opt['strap_width'] > 0:
        strap_kwargs = dict(width=TILEW * opt['strap_width'] / 100,
                            random_factor=0)
    else:
        strap_kwargs = dict(width=TILEW / 60, random_factor=4.9)

    dwg = Drawing(width, height, name="straps", bg=(.8, .8, .8))
    pt = PathTiler()
    design_class = get_design(opt['design'])
    draw = design_class(TILEW)
    draw.draw(pt, dwg.get_size())
    paths = combine_paths(pt.paths)

    if should_debug('world'):
        debug_world(paths, width, height)

    straps = strapify(paths, **strap_kwargs)

    with dwg.style(rgb=(1, 1, 1)):
        for strap in straps:
            replay_path(strap.sides[0], dwg)
            replay_path(strap.sides[1][::-1], dwg, append=True)
            dwg.close_path()
            dwg.fill()

    with dwg.style(rgb=(0, 0, 0), width=2):
        for strap in straps:
            for side in strap.sides:
                replay_path(side, dwg)
                dwg.stroke()

    dwg.finish()
예제 #3
0
def debug_world(dwg0, paths_styles):
    """Draw a picture of the entire world.

    `dwg0` is the Drawing we're really making.

    `paths_styles` is a list of tuples: (paths, style) for drawing.
    """

    # Get the perimeter of the real drawing.
    dwg0_path = dwg0.perimeter()

    # Get the bounds of everything we're going to draw.
    bounds = EmptyBounds()
    for paths, styles in paths_styles:
        bounds |= paths_bounds(paths)
    bounds |= dwg0_path.bounds()
    bounds = bounds.expand(percent=2)

    dwg = Drawing(bounds=bounds, name="debug_world", bg=(.95, .95, .95))

    # White rectangle: the desired visible canvas.
    with dwg.style(rgb=(1, 1, 1)):
        dwg0_path.draw(dwg)
        dwg.fill()

    # Reference grid.
    llx, lly, urx, ury = dwg.bounds
    with dwg.style(rgb=(.5, 1, 1), width=1, dash=[5, 5], dash_offset=7.5):
        for xmin in tick_range(llx, urx, 20):
            dwg.move_to(xmin, lly)
            dwg.line_to(xmin, ury)
            dwg.stroke()
        for ymin in tick_range(lly, ury, 20):
            dwg.move_to(llx, ymin)
            dwg.line_to(urx, ymin)
            dwg.stroke()

    with dwg.style(rgb=(.5, 1, 1), width=1):
        for xmaj in tick_range(llx, urx, 100):
            dwg.move_to(xmaj, lly)
            dwg.line_to(xmaj, ury)
            dwg.stroke()
        for ymaj in tick_range(lly, ury, 100):
            dwg.move_to(llx, ymaj)
            dwg.line_to(urx, ymaj)
            dwg.stroke()

    # The origin.
    with dwg.style(rgb=(0, .75, .75), width=1):
        dwg.circle_points([Point(0, 0)], radius=10)
        dwg.move_to(-10, 0)
        dwg.line_to(10, 0)
        dwg.move_to(0, -10)
        dwg.line_to(0, 10)
        dwg.stroke()

    # The paths themselves.
    for paths, styles in paths_styles:
        dwg.draw_paths(paths, **styles)

    dwg.finish()
    print("Wrote debug_world.png")