예제 #1
0
def cookieExample():
    # construct a christmas cookie with the help of the shapes
    star   = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4)
    circle = Circle(radius=1.0, center=(1.0, 3.0), points=64)
    cookie = star-circle
    # shift star and circle to the right to plot all polygons
    # on one page
    star.shift(5.0, 0.0)
    circle.shift(10.0, 0.0)
    # plot all three to an svg file
    writeSVG('Cookie.svg', (cookie, star, circle))

    # break a polygon object into a list of polygons by arranging
    # it on tiles
    # tile into 3x3 parts
    plist = tileEqual(cookie, 3, 3)
    writeSVG('CookieTiled1.svg', plist)
    # test tile at x = 0.3, 0.5 and y = 2.7, 3.1
    plist = tile(cookie, [0.3, 0.5], [2.7, 3.1])
    writeSVG('CookieTiled2.svg', plist)

    # let's simulate an explosion, move all parts away
    # from the cookie's center, small parts are faster
    xc, yc = cookie.center()
    for p in plist:
        if p:
            # speed/distance
            dval = 0.1 / p.area()
            x, y = p.center()
            # move the part a little bit
            p.shift(dval*(x-xc), dval*(y-yc))
            # and rotate it slightly ;-)
            p.rotate(0.2*math.pi*(random.random()-0.5))
    writeSVG('CookieExploded.svg', plist)
예제 #2
0
def cookieExample():
    # construct a christmas cookie with the help of the shapes
    star = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4)
    circle = Circle(radius=1.0, center=(1.0, 3.0), points=64)
    cookie = star - circle
    # shift star and circle to the right to plot all polygons
    # on one page
    star.shift(5.0, 0.0)
    circle.shift(10.0, 0.0)
    # plot all three to an svg file
    writeSVG('Cookie.svg', (cookie, star, circle))

    # break a polygon object into a list of polygons by arranging
    # it on tiles
    # tile into 3x3 parts
    plist = tileEqual(cookie, 3, 3)
    writeSVG('CookieTiled1.svg', plist)
    # test tile at x = 0.3, 0.5 and y = 2.7, 3.1
    plist = tile(cookie, [0.3, 0.5], [2.7, 3.1])
    writeSVG('CookieTiled2.svg', plist)

    # let's simulate an explosion, move all parts away
    # from the cookie's center, small parts are faster
    xc, yc = cookie.center()
    for p in plist:
        if p:
            # speed/distance
            dval = 0.1 / p.area()
            x, y = p.center()
            # move the part a little bit
            p.shift(dval * (x - xc), dval * (y - yc))
            # and rotate it slightly ;-)
            p.rotate(0.2 * math.pi * (random.random() - 0.5))
    writeSVG('CookieExploded.svg', plist)
예제 #3
0
파일: Test.py 프로젝트: EUPSForge/polygon
 def testLargeOperations(self):
     sheet = Rectangle(1000, 500)
     perf = cloneGrid(Circle(0.5, points=32), 0, 200, 100, 5, 5)
     perfSheet = sheet - perf
     #print 'perfSheet has %d points in %d contours' % (perfSheet.nPoints(), len(perfSheet))
     circle = Circle(400, points=512)
     circle.scale(1.0, 0.5)
     circle.shift(500, 250)
     perfCircle = circle & perfSheet
     #print 'perfCircle has %d points in %d contours' % (perfCircle.nPoints(), len(perfCircle))
     perfCircle.write('perfcircle.gpf')
예제 #4
0
def operationsExample():
    print('### Operations')
    # create a circle with a hole
    p1 = Circle(1.0) - Circle(0.5)
    # create a square
    p2 = Rectangle(0.7)
    # shift the square a little bit
    p2.shift(0.25, 0.35)
    plist = [p1, p2]
    slist = ['p1', 'p2']

    # addition, the same as logical OR (p1 | p2)
    p = p1 + p2
    p.shift(2.5, 0.0)
    plist.append(p)
    slist.append('p1 + p2 (OR)')

    # subtraction
    p = p1 - p2
    p.shift(5.0, 0.0)
    plist.append(p)
    slist.append('p1 - p2')

    # subtraction
    p = p2 - p1
    p.shift(7.5, 0.0)
    plist.append(p)
    slist.append('p2 - p1')

    # logical AND
    p = p2 & p1
    p.shift(10.0, 0.0)
    plist.append(p)
    slist.append('p2 AND p1')

    # logical XOR
    p = p2 ^ p1
    p.shift(12.5, 0.0)
    plist.append(p)
    slist.append('p2 XOR p1')

    # draw the results of the operations
    writeSVG('Operations.svg',
             plist,
             width=800,
             labels=slist,
             labels_centered=True)
예제 #5
0
def gridExample():
    starGrid = cloneGrid(Star(beams=5), 0, 20, 20, 4, 4)
    starGrid.shift(-50, -50)
    cookie = Star(radius=30.0, beams=5, iradius=20.0) - Circle(radius=15.0)
    starCookie = cookie - starGrid
    writeSVG('StarCookie.svg', (starCookie,))
    if hasPDFExport:
        writePDF('StarCookie.pdf', (starCookie,))
예제 #6
0
 def testLargeOperations(self):
     sheet = Rectangle(1000, 500)
     perf = cloneGrid(Circle(0.5, points=32), 0, 200, 100, 5, 5)
     perfSheet = sheet - perf
     circle = Circle(400, points=512)
     circle.scale(1.0, 0.5)
     circle.shift(500, 250)
     perfCircle = circle & perfSheet
     perfCircle.write('perfcircle.gpf', )
     c, h, p, hf = gpfInfo('perfcircle.gpf')
     self.assertEqual(c, len(perfCircle))
     self.assertEqual(p, perfCircle.nPoints())
     self.assertEqual(hf, True)
예제 #7
0
def operationsExample():
    # create a circle with a hole
    p1 = Circle(1.0) - Circle(0.5)
    # create a square
    p2 = Rectangle(0.7)
    # shift the square a little bit
    p2.shift(0.25, 0.35)
    plist = [p1, p2]

    # addition, the same as logical OR (p1 | p2)
    p = p1 + p2
    p.shift(2.5, 0.0)
    plist.append(p)

    # subtraction
    p = p1 - p2
    p.shift(5.0, 0.0)
    plist.append(p)

    # subtraction
    p = p2 - p1
    p.shift(7.5, 0.0)
    plist.append(p)

    # logical AND
    p = p2 & p1
    p.shift(10.0, 0.0)
    plist.append(p)

    # logical XOR
    p = p2 ^ p1
    p.shift(12.5, 0.0)
    plist.append(p)

    # draw the results of the operations
    writeSVG('Operations.svg', plist, width=800)
예제 #8
0
    def point_to_poly(self, point, belief, overloadw=None):
        """
        Translates a (lat, lon) point into a circular polygon of 0.1 degree radius.

        :param point: The (lat, lon) point to get a polygon around.
        :type point: tuple
        :param belief: Value in [0, 1] of how confident the estimation is.
        :type belief: float
        :param overloadw: *(optional)* If `None` will use normal weight, otherwise
            can override the weight of the indicator.
        :type overloadw: float
        :return:
        """
        circle = Circle(0.1, point)
        return pointList(circle), self.get_weight(belief, overloadw)
예제 #9
0
 def setUp(self):
     star   = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4)
     circle = Circle(radius=1.0, center=(1.0, 3.0), points=64)
     self.cookie = star-circle
     self.cont = [(0.0, 0.0), (2.0, 1.0), (1.0, 0.0), (-2.0, 1.0), (0.0, 0.0)]
예제 #10
0
def gnuplotExample():
    cookie = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4) \
             - Circle(radius=1.0, center=(1.0, 3.0))
    writeGnuplot('cookie.gp', (cookie,))
    writeGnuplotTriangles('cookieTri.gp', (cookie,))
예제 #11
0
def xmlExample():
    cookie = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4) \
             - Circle(radius=1.0, center=(1.0, 3.0))
    writeXML('cookie.xml', (cookie,), withHeader=True)
    p = readXML('cookie.xml')
예제 #12
0
파일: logo.py 프로젝트: jraedler/Polygon2
from Polygon import *
from Polygon.Shapes import Circle, Star, Rectangle
from Polygon.IO import writeSVG

p = Circle(5.5, points=128)
p -= Circle(4.4, points=128)
p += Circle(3.3, points=128)
p -= Circle(2.2, points=128)
p += Star(1.1)

l = Rectangle(4, 14)
l.shift(-4.3, -10.5)

r = p ^ l

writeSVG('logo.svg', [r], width=800)