def main(): parser = argparse.ArgumentParser() parser.add_argument('--set-min-y', dest='desired_min_y', type=float, default=None, help='Move sketch up/down to match the passed y value') parser.add_argument('files', nargs='+') args = parser.parse_args() for filename in args.files: tilt = Tilt(filename) sketch = tilt.sketch print '=== %s ===' % filename if args.desired_min_y is not None: min_y = min(cp.position[1] for stroke in sketch.strokes for cp in stroke.controlpoints) delta = args.desired_min_y - min_y for stroke in sketch.strokes: for cp in stroke.controlpoints: cp.position[1] += delta print filename print 'Moved by %.3f' % delta tilt.write_sketch()
def main(): import argparse parser = argparse.ArgumentParser( description= "Create a normalized version of the sketch (with 'Normalized' appended to\ the file name) which is scaled, rotated, and translated so that resetting the\ transform will bring you back to the initial size, orientation, and position.\ But the environment size, orientation, and position will also be reset.") parser.add_argument('files', type=str, nargs='+', help="Sketches to normalize") args = parser.parse_args() for filename in args.files: name, ext = os.path.splitext(filename) filename_normalized = name + 'Normalized' + ext shutil.copy(filename, filename_normalized) tilt_file = Tilt(filename_normalized) normalize_tilt_file(tilt_file) tilt_file.write_sketch() print 'WARNING: Environment position has changed in ' + filename + '.'
def main(): parser = argparse.ArgumentParser() parser.add_argument( "--set-min-y", dest="desired_min_y", type=float, default=None, help="Move sketch up/down to match the passed y value", ) parser.add_argument("files", nargs="+") args = parser.parse_args() for filename in args.files: tilt = Tilt(filename) sketch = tilt.sketch print("=== %s ===" % filename) if args.desired_min_y is not None: min_y = min(cp.position[1] for stroke in sketch.strokes for cp in stroke.controlpoints) delta = args.desired_min_y - min_y for stroke in sketch.strokes: for cp in stroke.controlpoints: cp.position[1] += delta print(filename) print("Moved by %.3f" % delta) tilt.write_sketch()
def process_tilt(filename, args): msg("Load tilt") tilt = Tilt(filename) msg("Load strokes") # TODO: this seems to do nothing; is there a function that's supposed to be called here? tilt.sketch.strokes # pylint: disable=pointless-statement msg("") if args.debug: msg("Clone strokes") before_strokes = [s.clone() for s in tilt.sketch.strokes] # Do this before color quantization, because it removes strokes (and their colors) if args.convert_brushes: convert_brushes(tilt, BRUSH_REPLACEMENTS) if args.remove_stray_strokes is not None: remove_stray_strokes(tilt, args.remove_stray_strokes, BrushLookup.get().get_unique_guid("Wire")) if args.pos_error_tolerance > 0: reduce_control_points(tilt, args.pos_error_tolerance) if args.simplify_colors is not None: simplify_colors(tilt, num_colors=args.simplify_colors, preserve_colors=args.preserve_colors) if args.debug: final_strokes = [] # interleave them so it renders semi-nicely... for before, after in itertools.zip_longest(before_strokes, tilt.sketch.strokes): if before is not None: for cp in before.controlpoints: cp.position[1] += 10 final_strokes.append(before) if after is not None: final_strokes.append(after) tilt.sketch.strokes[:] = final_strokes tilt.write_sketch() msgln("Wrote %s" % os.path.basename(tilt.filename))