コード例 #1
0
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)
コード例 #2
0
ファイル: scale.py プロジェクト: bengolder/chiplotle
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)
コード例 #3
0
ファイル: rotate.py プロジェクト: willprice/chiplotle
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)
コード例 #4
0
ファイル: rotate.py プロジェクト: bengolder/chiplotle
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)
コード例 #5
0
ファイル: offset.py プロジェクト: yratof/chiplotle
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)
コード例 #6
0
ファイル: offset.py プロジェクト: bengolder/chiplotle
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)
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
ファイル: noise.py プロジェクト: yratof/chiplotle
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)