コード例 #1
0
ファイル: ruler.py プロジェクト: willprice/chiplotle
def ruler(start_coord, end_coord, units, min_tick_height, symmetric=False):
    """
    A measuring ruler.

    - `units` is a list of units on which to put marks, from smaller
        to larger. e.g., (10, 20, 40).
    - `min_tick_height` is the height of the marks for the smallest units.
        The hight of the other units are multiples of this.
    - `symmetric` set to True to draw the tick lines symmetrically around
        the invisible center-line.
    """
    start_coord = Coordinate(*start_coord)
    end_coord = Coordinate(*end_coord)

    length = (end_coord - start_coord).magnitude
    angle = (end_coord - start_coord).angle

    result = []
    for i, unit in enumerate(units):
        ticks = int(math.ceil(length / unit))
        for t in range(ticks):
            tick_height = min_tick_height * (i + 1)
            if symmetric:
                x1, y1 = unit * t, tick_height / 2
                x2, y2 = unit * t, -tick_height / 2
            else:
                x1, y1 = unit * t, 0
                x2, y2 = unit * t, -tick_height
            tick = line((x1, y1), (x2, y2))
            result.append(tick)
    g = Group(result)
    rotate(g, angle, (0, 0))
    offset(g, start_coord)
    return g
コード例 #2
0
ファイル: ruler.py プロジェクト: bengolder/chiplotle
def ruler(start_coord, end_coord, units, min_tick_height, symmetric=False):
    '''
    A measuring ruler.

    - `units` is a list of units on which to put marks, from smaller
        to larger. e.g., (10, 20, 40).
    - `min_tick_height` is the height of the marks for the smallest units.
        The hight of the other units are multiples of this.
    - `symmetric` set to True to draw the tick lines symmetrically around
        the invisible center-line.
    '''
    start_coord = Coordinate(*start_coord)
    end_coord = Coordinate(*end_coord)

    length = (end_coord - start_coord).magnitude
    angle = (end_coord - start_coord).angle

    result = [ ]
    for i, unit in enumerate(units):
        ticks = int(math.ceil(length / unit))
        for t in range(ticks):
            tick_height = min_tick_height * (i + 1)
            if symmetric:
                x1, y1 = unit * t, tick_height / 2
                x2, y2 = unit * t, -tick_height / 2
            else:
                x1, y1 = unit * t, 0
                x2, y2 = unit * t, -tick_height
            tick = line((x1, y1), (x2, y2))
            result.append(tick)
    g = Group(result)
    rotate(g, angle, (0, 0))
    offset(g, start_coord)
    return g
コード例 #3
0
def arrow(path, headwidth, headheight, filled=False):
    '''Returns an arrow shape.

    - `path` is a Path object.
    - `headwidth` is the width of the arrow head.
    - `headheight` is the height of the arrow head.
    '''

    ## make arow head...
    r, a = xy_to_polar((path.points[-1] - path.points[-2]))
    head = isosceles(headwidth, headheight, filled)
    offset(head, (0, -headheight))
    rotate(head, a - math.pi / 2, (0, 0))
    offset(head, path.points[-1])

    return Group([head, path])
コード例 #4
0
ファイル: arrow.py プロジェクト: bengolder/chiplotle
def arrow(path, headwidth, headheight, filled=False):
    '''Returns an arrow shape.

    - `path` is a Path object.
    - `headwidth` is the width of the arrow head.
    - `headheight` is the height of the arrow head.
    '''

    ## make arow head...
    r, a = xy_to_polar((path.points[-1] - path.points[-2]))
    head = isosceles(headwidth, headheight, filled)
    offset(head, (0, -headheight))
    rotate(head, a - math.pi / 2, (0, 0))
    offset(head, path.points[-1])

    return Group([head, path])
コード例 #5
0
    return result


## RUN DEMO CODE

if __name__ == '__main__':
    from chiplotle.geometry.core.group import Group
    from chiplotle.geometry.transforms.offset import offset
    from chiplotle.geometry.transforms.rotate import rotate
    from chiplotle.tools import io

    #one of each main spiral type
    s1 = spiral_archimedean(500, wrapping_constant=1)

    s2 = spiral_archimedean(500, wrapping_constant=2, direction="ccw")
    offset(s2, (0, -1000))

    #these two are long, so we'll rotate them and move them to the side
    #of the others
    s3 = spiral_archimedean(1800, wrapping_constant=-1, direction="ccw")
    rotate(s3, math.pi * 1.5)
    offset(s3, (650, 400))
    s4 = spiral_archimedean(1500, wrapping_constant=-2, direction="ccw")
    rotate(s4, math.pi * .6)
    offset(s4, (1000, -1100))

    g = Group([s1, s2, s3, s4])

    io.view(g)
コード例 #6
0
    return result


## RUN DEMO CODE

if __name__ == "__main__":
    from chiplotle.geometry.core.group import Group
    from chiplotle.geometry.transforms.offset import offset
    from chiplotle.geometry.transforms.rotate import rotate
    from chiplotle.tools import io

    # one of each main spiral type
    s1 = spiral_archimedean(500, wrapping_constant=1)

    s2 = spiral_archimedean(500, wrapping_constant=2, direction="ccw")
    offset(s2, (0, -1000))

    # these two are long, so we'll rotate them and move them to the side
    # of the others
    s3 = spiral_archimedean(1800, wrapping_constant=-1, direction="ccw")
    rotate(s3, math.pi * 1.5)
    offset(s3, (650, 400))
    s4 = spiral_archimedean(1500, wrapping_constant=-2, direction="ccw")
    rotate(s4, math.pi * 0.6)
    offset(s4, (1000, -1100))

    g = Group([s1, s2, s3, s4])

    io.view(g)
コード例 #7
0
ファイル: lock_group.py プロジェクト: bengolder/chiplotle
from chiplotle.geometry.core.transformlock import TransformLock
from chiplotle.geometry.core.shape import _Shape

def lock_group(shapes, lock_transforms):
    t = TransformLock(shapes, lock_transforms)
    return t


## ~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == '__main__':
    from chiplotle.geometry.shapes.square import square
    from chiplotle.geometry.core.group import Group
    from chiplotle.geometry.transforms.rotate import rotate
    from chiplotle.geometry.transforms.offset import offset
    from chiplotle import io
    import math

    r1 = square(100)
    r2 = square(150)
    l = lock_group([r2], ['rotate'])
    g  = Group([r1, l])
    offset(g, (200, 0))
    rotate(g, math.pi / 4)
    io.view(g)
コード例 #8
0
from chiplotle.geometry.core.transformlock import TransformLock
from chiplotle.geometry.core.shape import _Shape


def lock_group(shapes, lock_transforms):
    t = TransformLock(shapes, lock_transforms)
    return t


## ~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == '__main__':
    from chiplotle.geometry.shapes.square import square
    from chiplotle.geometry.core.group import Group
    from chiplotle.geometry.transforms.rotate import rotate
    from chiplotle.geometry.transforms.offset import offset
    from chiplotle import io
    import math

    r1 = square(100)
    r2 = square(150)
    l = lock_group([r2], ['rotate'])
    g = Group([r1, l])
    offset(g, (200, 0))
    rotate(g, math.pi / 4)
    io.view(g)