本文整理汇总了Python中polygon.Polygon.vertices方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.vertices方法的具体用法?Python Polygon.vertices怎么用?Python Polygon.vertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.vertices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mutate
# 需要导入模块: from polygon import Polygon [as 别名]
# 或者: from polygon.Polygon import vertices [as 别名]
def mutate(self):
""" Create a new picture by mutating a polygon, adding a polygon,
or removing a polygon.
Return a new picture
"""
new_picture = Picture()
# Buffer changes so we iterate correctly
to_add = []
for polygon in self.polygons:
mutation_type = random.random()
if (mutation_type < 0.1):
# Stay the same
new_polygon = Polygon()
new_polygon.vertices = list(polygon.vertices)
to_add.append(new_polygon)
if (mutation_type < 0.8):
# Do some mutation
to_add.append(polygon.mutate())
elif (mutation_type >= 0.8 and mutation_type < 0.9):
# Add a polygon
new_polygon = Polygon()
new_polygon = new_polygon.create_random(3)
to_add.append(new_polygon)
elif (mutation_type >= 0.9):
# Remove a polygon by not adding it to the new picture
if (len(self.polygons) <= 1):
# Mutate instead if there is only one polygon left
to_add.append(polygon.mutate())
else:
pass
# Add polygons here so that we don't iterate over new polygons
for p in to_add:
new_picture.polygons.append(p)
return new_picture