本文整理汇总了Python中Polygon.Polygon.contour方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.contour方法的具体用法?Python Polygon.contour怎么用?Python Polygon.contour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.contour方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pointlist
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def pointlist(pos=[], rotate=0.0, roundness=0.0, invert=False,
scale=1.0, xscale=1.0, yscale=1.0, path=False):
# pos may be either a list of points or a Polygon object
try:
points = pos.contour(0)
if len(pos) > 1:
raise AttributeError("pointlist can deal with only a single contour.")
except:
points = pos[:]
closed = (points[-1] == points[0])
if not closed:
points.append(points[0])
pp = Polygon(points)
if len(pp) and rotate != 0.0: pp.rotate(rotate)
if scale != 1.0: xscale = yscale = scale
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
pp = Polygon(cp)
if path:
if closed:
return list(pp)
else:
return list(pp)[:-1]
else:
return pp
示例2: ngon
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def ngon(pos=(0,0), np=3, length=None, radius=1.0, rotate=0.0, thickness=0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
cp = []
if np < 3:
raise AttributeError("number of sides can not be less than 3")
return None
angle = 2*pi/np
if length != None: radius = (length/2.0)/(sin(angle/2))
else: length = radius*(sin(angle/2))*2
if thickness == 0:
seg = 2.0*pi/np
angle = rotate
for i in range(np):
x = radius*cos(angle) + pos[0]
y = radius*sin(angle) + pos[1]
cp.append((x,y))
angle += seg
cp.append(cp[0])
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
else:
pp = nframe(pos=pos, length=length, thickness=thickness, roundness=roundness,
invert=invert, rotate=rotate, np=np)
return pp
示例3: rectangle
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def rectangle(pos=(0,0), width=1.0, height=None, rotate=0.0, thickness=0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
if height is None: height = width
if thickness == 0:
p0 = (pos[0]+width/2.0, pos[1]-height/2.0)
p1 = (pos[0]+width/2.0, pos[1]+height/2.0)
p2 = (pos[0]-width/2.0, pos[1]+height/2.0)
p3 = (pos[0]-width/2.0, pos[1]-height/2.0)
p4 = (pos[0]+width/2.0, pos[1]-height/2.0)
cp = [p0, p1, p2, p3, p4]
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
else:
pp = rframe(pos=pos, width=width, height=height, thickness=thickness,
rotate=rotate, roundness=roundness, invert=invert,
scale=scale, xscale=xscale, yscale=yscale)
return pp
示例4: star
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def star(pos=(0,0), radius=1.0, n=5, iradius=None, rotate=0.0, thickness=0.0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
if iradius == None: iradius = radius*0.5
if thickness == 0.0:
pstar = Star(radius=radius, center=pos, beams=n, iradius=iradius)
cp = pstar[0]
cp.append(cp[0])
cp.reverse() # Polygon Star goes around clockwise, so reverse to go CCW
cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
else:
pp = sframe(pos=pos, radius=radius, iradius=iradius, rotate=rotate,
thickness=thickness, roundness=roundness, invert=invert,
scale=scale, xscale=xscale, yscale=yscale, n=n)
return pp
示例5: cross
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def cross(pos=(0,0), width=1.0, thickness=0.2, rotate=0.0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
fsqr = rectangle(pos=pos, width=width)
sqr1 = rectangle(pos=(pos[0]-(width+thickness)/4.0,
pos[1]+(width+thickness)/4.0), width=(width-thickness)/2.0)
sqr2 = rectangle(pos=(pos[0]+(width+thickness)/4.0,
pos[1]+(width+thickness)/4.0), width=(width-thickness)/2.0)
sqr3 = rectangle(pos=(pos[0]+(width+thickness)/4.0,
pos[1]-(width+thickness)/4.0), width=(width-thickness)/2.0)
sqr4 = rectangle(pos=(pos[0]-(width+thickness)/4.0,
pos[1]-(width+thickness)/4.0), width=(width-thickness)/2.0)
poly = fsqr - sqr1 -sqr2 -sqr3 -sqr4
cp = poly.contour(0)
cp.append(cp[0])
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
示例6: set_shape
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import contour [as 别名]
def set_shape(self, shape):
if not import_check("Polygon"):
return
# shape can be a Polygon object or a simple list of points
# Construct a pointer array with this integer format:
# (number of contours,closed), where closed=1 for shape=Polygon object
# but closed=0 for shape=list of points with final != initial.
# In both Polygon and list cases if final == initial, final is discarded
# (length of 1st contour, offset in array to data for 1st contour)
# (length of 2nd contour, offset in array to data for 2nd contour)
# .....
# Construct a contour array with this float format:
# (x,y) data for 1st contour
# (x,y) data for 2nd contour
# .....
datalist = []
if isinstance(shape, str):
shape = shapes.text(text=shape, align='center')
else:
try:
shape.pos # could be a paths.xxx object, a list of vectors
s = []
for v in shape.pos:
s.append((v.x, -v.z))
shape = Polygon(s)
except:
pass
try:
for i in range(len(shape)):
s = list(shape.contour(i))
if s[-1] == s[0]: # discard final point if same as initial
s = s[:-1]
c = self.xycurl(s) # positive if CCW
# Require hole contours to run CCW, external contours CW
if (shape.isHole(i) and (c < 0) or
(not shape.isHole(i)) and (c > 0)):
# Need to reverse the order of points in this contour
s.reverse()
datalist.append(s)
closed = True
isPolygon = True
except:
s = shape
# Require (external) closed contour to run clockwise (curl > 0)
if self.xycurl(s) > 0: # Need to reverse the order of points in this contour
s.reverse()
if s[-1] == s[0]: # discard final point if same as initial, mark closed
s = s[:-1]
closed = True
else:
closed = False
isPolygon = False
datalist = array([s], float)
contours, pcontours = self.make_shapedata(datalist, closed)
if isPolygon:
strips, pstrips = self.make_shapedata(shape.triStrip(), closed)
else:
strips = array([(0,0)])
pstrips = array([(0,0)])
# Send pointers, contour data, and shape.triStrip data to Visual
self.set_contours(contours, pcontours, strips, pstrips)