本文整理匯總了Python中Polygon.Polygon.shift方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.shift方法的具體用法?Python Polygon.shift怎麽用?Python Polygon.shift使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.shift方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rackGear
# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import shift [as 別名]
def rackGear(pos=(0,0), n=30, radius=5., phi=20., addendum=0.4, dedendum=0.5,
fradius=0.1, rotate=0, scale=1.0, length=10*pi, res=1, bevel=0.05, depth=(0.4+0.6+0.1)):
tooth = RackOutline(n, res, phi, radius, addendum, dedendum,
fradius, bevel)
toothl = tooth[0][1] - tooth[-1][1]
ntooth = int(length/toothl)
flength = ntooth * toothl
gear = []
for i in range(0, ntooth):
ntooth = []
for (x, y) in tooth:
nx = x + pos[0]
ny = -i*toothl + y + pos[1]
ntooth.append((nx,ny))
gear.extend(ntooth)
gear.append((gear[-1][0]-depth,gear[-1][1]))
gear.append((gear[0][0]-depth,gear[0][1]))
gear.append(gear[0])
pp = Polygon(gear)
pp.shift(-pp.center()[0],-pp.center()[1])
if rotate != 0.0: pp.rotate(rotate)
if scale != 1.0 : pp.scale(scale,scale)
return pp
示例2: __init__
# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import shift [as 別名]
#.........這裏部分代碼省略.........
def scale(self, factor, center=None):
"""Resize the shape by a proportion (e.g., 1 is unchanged), in-place.
Parameters
----------
factor : float or array-like
If a scalar, the same factor will be applied in the x and y dimensions.
center : array-like, optional
Point around which to perform the scaling.
If not passed, the center of the shape is used.
"""
factor = np.asarray(factor)
if len(factor.shape):
args = list(factor)
else:
args = [factor, factor]
if center is not None:
args.extend(center)
self.poly.scale(*args)
return self
def translate(self, vector):
"""Translate the shape along a vector, in-place.
Parameters
----------
vector : array-like
"""
self.poly.shift(*vector)
def rotate(self, angle, center=None):
"""Rotate the shape, in-place.
Parameters
----------
angle : float
Angle to rotate, in radians counter-clockwise.
center : array-like, optional
Point about which to rotate.
If not passed, the center of the shape will be used.
"""
args = [angle]
if center is not None:
args.extend(center)
self.poly.rotate(*args)
return self
def flip_x(self, center=None):
"""Flip the shape in the x direction, in-place.
Parameters
----------
center : array-like, optional
Point about which to flip.
If not passed, the center of the shape will be used.
"""
if center is None:
self.poly.flip()
else:
示例3: text
# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import shift [as 別名]
#.........這裏部分代碼省略.........
for i in range(len(contours)):
totlen = lenctr(contours[i])
lengths.append((totlen,i))
if totlen > maxl:
mli = i
maxl = totlen
lengths.sort()
lengths.reverse()
ocontours = []
for ll in lengths:
ocontours.append(contours[ll[1]])
contours = ocontours
indxf = -1
indxc = -1
if (mli > 0 and newchar != "%"):
try: indxf = excludef_list.index(self.font)
except: pass
if indxf == -1:
try: indxc = excludec_list.index((self.font, newchar))
except: pass
if (indxf == -1 and indxc == -1):
maxc = contours.pop(mli)
contours.insert(0, maxc)
a = Polygon(contours[0])
for i in range(1,len(contours)):
b = Polygon(contours[i])
if a.covers(b): a = a - b
elif b.covers(a): a = b - a
else: a = a + b
a.shift(bb - a.boundingBox()[0] ,0)
ptext[line] += a
bx = ptext[line].boundingBox()
bb = bx[1] - bx[0] + spacing*fontheight
newwidth = fontscale*height*(ptext[line].boundingBox()[1]-ptext[line].boundingBox()[0])
widths.append(newwidth)
if newwidth > width: width = newwidth
ptext[line].scale(xscale*fontscale*height, yscale*fontscale*height, 0, 0)
for line in range(len(lines)):
if align == 'left':
ptext[line].shift(-width/2,-line*vertical_spacing)
elif align == 'right':
ptext[line].shift(width/2-widths[line],-line*vertical_spacing)
else:
ptext[line].shift(-widths[line]/2,-line*vertical_spacing)
ptext[line].shift(pos[0], pos[1])
if rotate != 0.0: ptext[line].rotate(rotate)
if line == 0:
shape = ptext[0]
upper_left = vis.vector(ptext[line].boundingBox()[0],ptext[line].boundingBox()[3],0)
upper_right = vis.vector(ptext[line].boundingBox()[1],ptext[line].boundingBox()[3],0)
lower_left = vis.vector(ptext[line].boundingBox()[0],ptext[line].boundingBox()[2],0)
lower_right = vis.vector(ptext[line].boundingBox()[1],ptext[line].boundingBox()[2],0)
else:
shape += ptext[line]
xleft = ptext[line].boundingBox()[0]
xright = ptext[line].boundingBox()[1]
y = ptext[line].boundingBox()[2]