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")
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")