def scale(shape, value, pivot=Coordinate(0, 0)): '''In place scaling. - `shape` is the shape to be rotated. - `value` is the scaling value. Can be a scalar or an (x, y) coordinate. - `pivot` is the Coordinate around which the shape will be scaled. ''' from chiplotle.tools.geometrytools.scale import scale t = TransformVisitor(scale) t.visit(shape, value, pivot)
def scale(shape, value, pivot = Coordinate(0, 0)): '''In place scaling. - `shape` is the shape to be rotated. - `value` is the scaling value. Can be a scalar or an (x, y) coordinate. - `pivot` is the Coordinate around which the shape will be scaled. ''' from chiplotle.tools.geometrytools.scale import scale t = TransformVisitor(scale) t.visit(shape, value, pivot)
def rotate(shape, angle, pivot=(0, 0)): """In place rotation. - `shape` is the shape to be rotated. - `angle` is the angle (in radians) of rotation. - `pivot` is the center of rotation. Must be a Coordinate or (x, y) pair. """ def rotate(coords, angle, pivot=pivot): return rotate_2d(coords, angle, pivot) t = TransformVisitor(rotate) t.visit(shape, angle, pivot)
def offset(shape, value): '''In place offsetting. - `shape` is the shape to be rotated. - `value` is the offset value. Can be a scalar or an (x, y) coordinate. ''' if isinstance(value, (list, tuple)): value = Coordinate(*value) def offset(coords, value): return coords + value t = TransformVisitor(offset) t.visit(shape, value)
def perpendicular_noise(shape, value): """Distort shape by adding noise perpendiculary to the path. This is an in-place destructive transformation; no new shapes are created. - `shape` is the shape to be noisified. - `value` must be a scalar defining the range of the noise for displacement. """ def perpnoise(coords, value): result = [] d_coords = difference(coords) for coord, d_coord in zip(coords[:-1], d_coords): wiggle = random.randrange(-value, value) perp = ~d_coord xy = coord + perp / perp.magnitude * wiggle result.append(xy) return CoordinateArray(result) t = TransformVisitor(perpnoise) t.visit(shape, value)
def perpendicular_noise(shape, value): '''Distort shape by adding noise perpendiculary to the path. This is an in-place destructive transformation; no new shapes are created. - `shape` is the shape to be noisified. - `value` must be a scalar defining the range of the noise for displacement. ''' def perpnoise(coords, value): result = [ ] d_coords = difference(coords) for coord, d_coord in zip(coords[:-1], d_coords): wiggle = random.randrange(-value, value) perp = ~d_coord xy = coord + perp / perp.magnitude * wiggle result.append(xy) return CoordinateArray(result) t = TransformVisitor(perpnoise) t.visit(shape, value)
def noise(shape, value): '''Distort shape by adding noise. - `value` can be a scalar or a tuple (x, y) that sets the range of the noise for the x and y coordinates. ''' def noisify(coords, value): try: x, y = value except TypeError: x = y = value result = [ ] for point in coords: x_wiggle = random.randrange(-x, x) y_wiggle = random.randrange(-y, y) xy = point + Coordinate(x_wiggle, y_wiggle) result.append(xy) return CoordinateArray(result) t = TransformVisitor(noisify) t.visit(shape, value)