當前位置: 首頁>>代碼示例>>Python>>正文


Python Polygon.create_random方法代碼示例

本文整理匯總了Python中polygon.Polygon.create_random方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.create_random方法的具體用法?Python Polygon.create_random怎麽用?Python Polygon.create_random使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在polygon.Polygon的用法示例。


在下文中一共展示了Polygon.create_random方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_random

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import create_random [as 別名]
 def create_random(self, n):
   """ Create n polygons with random vertices. The dimensions of each
   picture should be specified with max_x and may_y.
   
   """
   self.polygons = []
   for i in xrange(0, n):
     p = Polygon()
     # 3 to 5 vertices
     Polygon.create_random(p, random.randint(3,5))
     self.polygons.append(p)
   return self
開發者ID:,項目名稱:,代碼行數:14,代碼來源:

示例2: mutate

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import create_random [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
開發者ID:,項目名稱:,代碼行數:41,代碼來源:


注:本文中的polygon.Polygon.create_random方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。