def debug_corners(opts): with open(opts.filename) as f: svg_str = f.read() paths = svg.extract_paths(svg_str) paths = svg.preprocess_paths(paths) segments = svg.plan_segments(paths, resolution=config.CURVE_RESOLUTION) segments = svg.add_pen_up_moves(segments) step_segments = planning.convert_inches_to_steps(segments) segments_limits = planning.plan_speed(step_segments) up_xdata = [] up_ydata = [] up_speed = [] down_xdata = [] down_ydata = [] down_speed = [] def speed_to_opacity(speed, limit, min_opacity=0.2): opacity = speed / limit if opacity < min_opacity: return min_opacity elif opacity > 1.0: return 1.0 else: return opacity def speed_to_color(speed, pen_up): if pen_up: return (1.0, 0.0, 0.0, speed_to_opacity(speed, config.SPEED_PEN_UP)) else: return (0.0, 0.1, 0.0, speed_to_opacity(speed, config.SPEED_PEN_DOWN)) def record_point(point, vmax, pen_up): x, y = point y = -y if pen_up: up_xdata.append(x) up_ydata.append(y) up_speed.append(speed_to_color(vmax, pen_up)) else: down_xdata.append(x) down_ydata.append(y) down_speed.append(speed_to_color(vmax, pen_up)) for segment, pen_up in segments_limits: xdata = [] ydata = [] for point, vmax in segment: record_point(point, vmax, pen_up) xdata.append(point[0]) ydata.append(-point[1]) plt.plot(xdata, ydata, 'r-' if pen_up else 'g-') plt.scatter(up_xdata, up_ydata, s=50, linewidths=0, c=up_speed) plt.scatter(down_xdata, down_ydata, s=50, linewidths=0, c=down_speed) show(opts)
def generate_actions(opts): with open(opts.filename) as f: svg_str = f.read() paths = svg.extract_paths(svg_str) paths = svg.preprocess_paths(paths) segments = svg.plan_segments(paths, resolution=config.CURVE_RESOLUTION) segments = svg.add_pen_up_moves(segments) step_segments = planning.convert_inches_to_steps(segments) segments_limits = planning.plan_speed(step_segments) return planning.plan_actions(segments_limits, 1000, 1000)
def debug_connected_segments(opts): with open(opts.filename) as f: svg_str = f.read() paths = svg.extract_paths(svg_str) paths = svg.preprocess_paths(paths) segments = svg.plan_segments(paths, resolution=config.CURVE_RESOLUTION) segments = svg.add_pen_up_moves(segments) for segment, pen_up in segments: xdata = [] ydata = [] for (x, y) in segment: xdata.append(x) ydata.append(-y) plt.plot(xdata, ydata, 'r-' if pen_up else 'g-') show(opts)
def debug_paths(opts): """ Render an SVG file into paths, and then plot them with matplotlib. """ subdivide = 100 with open(opts.filename) as f: svg_str = f.read() paths = svg.extract_paths(svg_str) paths = svg.preprocess_paths(paths) for path in paths: xdata = [] ydata = [] for n in range(subdivide + 1): point = path.point(n / subdivide) xdata.append(point.real) ydata.append(-point.imag) plt.plot(xdata, ydata, 'g-') show(opts)
def debug_segments(opts): """ Render an SVG file into linear segments, and then plot them with matplotlib. """ with open(opts.filename) as f: svg_str = f.read() paths = svg.extract_paths(svg_str) paths = svg.preprocess_paths(paths) segments = svg.plan_segments(paths, resolution=config.CURVE_RESOLUTION) xdata = [] ydata = [] for segment in segments: for (x, y) in segment: xdata.append(x) ydata.append(-y) plt.plot(xdata, ydata, 'g-') show(opts)