示例#1
0
def frame(width, height, inset):
    '''A frame (rectangle within a rectangle) with a width, height, and inset.

    - `width` is the width of the frame.
    - `height` is the height of the frame.
    - `inset` is the distance to inset the inner rectangle from the outer.
    '''

    r1 = rectangle(width, height)
    r2 = rectangle(width - (inset * 2), height - (inset * 2))
    return Group([r1, r2])
示例#2
0
文件: frame.py 项目: yratof/chiplotle
def frame(width, height, inset):
    '''A frame (rectangle within a rectangle) with a width, height, and inset.

    - `width` is the width of the frame.
    - `height` is the height of the frame.
    - `inset` is the distance to inset the inner rectangle from the outer.
    '''

    r1 = rectangle(width, height)
    r2 = rectangle(width - (inset * 2), height - (inset * 2))
    return Group([r1, r2])
示例#3
0
    def _annotate_centroid(self):
        coord = self.shape.centroid
        label = Label("\n\rcentroid: " + str(coord), self.charwidth, self.charheight, origin="top-center")
        r = rectangle(20, 20)
        cr = cross(50, 50)
        mark = Group([r, cr, label])

        offset(label, coord)
        offset(r, coord)
        offset(cr, coord)

        return mark
示例#4
0
    def _annotate_centroid(self):
        coord = self.shape.centroid
        label = Label('\n\rcentroid: ' + str(coord),
            self.charwidth, self.charheight,
            origin = 'top-center')
        r = rectangle(20, 20)
        cr = cross(50, 50)
        mark = Group([r, cr, label])

        offset(label, coord)
        offset(r, coord)
        offset(cr, coord)

        return mark
示例#5
0
        return mark

    @property
    def annotation(self):
        result = []
        result.append(self._annotate_center())
        result.append(self._annotate_centroid())
        result.append(self._annotate_properties())
        return Group(result)


## demo
if __name__ == "__main__":
    from chiplotle import *
    from chiplotle.hpgl.formatters import Pen
    from random import randint

    coords = [(randint(0, 4000), randint(0, 4000)) for i in range(20)]
    p = bezier_path(coords, 1)
    r = rectangle(1000, 400)
    offset(r, (-2000, 1000))
    g1 = Group([r, p])
    an = annotation(g1)
    Pen(2)(an)

    g2 = Group([g1, an])
    Pen(1)(g2)

    io.view(g2)
示例#6
0
from chiplotle.geometry.core.coordinate import Coordinate
from chiplotle.geometry.transforms.transformvisitor import TransformVisitor


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)


## RUN DEMO CODE
if __name__ == "__main__":
    from chiplotle.geometry.shapes.rectangle import rectangle
    from chiplotle.tools import io
    r0 = rectangle(1000, 400)
    r1 = rectangle(1000, 400)
    r2 = rectangle(1000, 400)
    offset(r1, (0, 1500))
    offset(r2, (100, 200))
    io.view(Group([r0, r1, r2]))
示例#7
0
def square(width_height):
    '''Returns a square centered at (0, 0).'''
    return rectangle(width_height, width_height)
示例#8
0
def square(width_height):
    '''Returns a square centered at (0, 0).'''
    return rectangle(width_height, width_height)
示例#9
0
from chiplotle.geometry.core.group import Group
from chiplotle.tools.mathtools.rotate_2d import rotate_2d
from chiplotle.geometry.transforms.transformvisitor import TransformVisitor


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)


## RUN DEMO CODE
if __name__ == "__main__":
    from chiplotle.geometry.shapes.rectangle import rectangle
    from chiplotle.tools import io

    r1 = rectangle(1000, 400)
    r2 = rectangle(1000, 400)
    r3 = rectangle(2000, 900)
    rotate(r1, 3.14 / 4)
    rotate(r2, 3.14 / 4, (500, 500))
    io.view(Group([r1, r2, r3]))
示例#10
0
        return mark


    @property
    def annotation(self):
        result = [ ]
        result.append(self._annotate_center( ))
        result.append(self._annotate_centroid( ))
        result.append(self._annotate_properties( ))
        return Group(result)



## demo
if __name__ == '__main__':
    from chiplotle import *
    from chiplotle.hpgl.formatters import Pen
    from random import randint
    coords = [(randint(0, 4000), randint(0, 4000)) for i in range(20)]
    p = bezier_path(coords, 1)
    r = rectangle(1000, 400)
    offset(r, (-2000, 1000))
    g1 = Group([r, p])
    an = annotation(g1)
    Pen(2)(an)

    g2 = Group([g1, an])
    Pen(1)(g2)

    io.view(g2)
示例#11
0
      at the end of the decorated shape. Set to True to skip reset.
   """
    def __init__(self,
                 number,
                 velocity=None,
                 force=None,
                 acceleration=None,
                 thickness=None):
        FormatDecorator.__init__(self)
        self.number = number
        self.velocity = velocity
        self.force = force
        self.acceleration = acceleration
        self.thickness = thickness

    @property
    def _subcommands(self):
        p = HPGLPen(self.number, self.velocity, self.force, self.acceleration,
                    self.thickness)
        return [p]


## DEMO
if __name__ == "__main__":
    from chiplotle.geometry.shapes.rectangle import rectangle

    pd = Pen(2, 3, 4, 5, 0.1)
    r = rectangle(100, 20)
    pd(r)
    print(r.format)
示例#12
0
                velocity    = None,
                force       = None,
                acceleration= None,
                thickness   = None):
      FormatDecorator.__init__(self)
      self.number       = number
      self.velocity     = velocity
      self.force        = force
      self.acceleration = acceleration
      self.thickness    = thickness

   @property
   def _subcommands(self):
      p = HPGLPen(self.number,
              self.velocity,
              self.force,
              self.acceleration,
              self.thickness)
      return [p]



## DEMO
if __name__ == '__main__':
   from chiplotle.geometry.shapes.rectangle import rectangle

   pd = Pen(2, 3, 4, 5, 0.1)
   r = rectangle(100, 20)
   pd(r)
   print r.format
示例#13
0
from chiplotle.geometry.core.group import Group
from chiplotle.geometry.core.coordinate import Coordinate
from chiplotle.geometry.transforms.transformvisitor import TransformVisitor

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)



## RUN DEMO CODE
if __name__ == "__main__":
    from chiplotle.geometry.shapes.rectangle import rectangle
    from chiplotle.tools import io
    r0 = rectangle(1000, 500)
    r1 = rectangle(1000, 500)
    r2 = rectangle(1000, 500)
    scale(r1, 5, (500, 250))
    scale(r2, (10, 20))
    g = Group([r0, r1, r2])
    print g.format
    io.view(g)

示例#14
0
from chiplotle.tools.mathtools.rotate_2d import rotate_2d
from chiplotle.geometry.transforms.transformvisitor import TransformVisitor


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)


## RUN DEMO CODE
if __name__ == "__main__":
    from chiplotle.geometry.shapes.rectangle import rectangle
    from chiplotle.tools import io

    r1 = rectangle(1000, 400)
    r2 = rectangle(1000, 400)
    r3 = rectangle(2000, 900)
    rotate(r1, 3.14 / 4)
    rotate(r2, 3.14 / 4, (500, 500))
    io.view(Group([r1, r2, r3]))
示例#15
0
def square(width_height):
    """Returns a square centered at (0, 0)."""
    return rectangle(width_height, width_height)