本文整理汇总了Python中tableau.Tableau.iterB方法的典型用法代码示例。如果您正苦于以下问题:Python Tableau.iterB方法的具体用法?Python Tableau.iterB怎么用?Python Tableau.iterB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tableau.Tableau
的用法示例。
在下文中一共展示了Tableau.iterB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenRegionVoronoi
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import iterB [as 别名]
class GenRegionVoronoi(GenRegion):
def __init__(self, largeur, hauteur, nb=10):
GenRegion.__init__(self, nb)
self.tab = Tableau(largeur, hauteur)
for x, y in self.tab.iterC():
self.tab[x, y] = Case(x, y)
self.tab[x, y].value = -1
self.init = []
self.liste = [elt for elt in self.tab.iterB()]
for i in range(nb):
case = self.tab[self.liste[randrange(len(self.liste))]]
case.value = i
self.init.append(case)
self.regions.append(Region(nb, interieur=[case]))
for case in self.tab.values():
distance = self.tab.X * self.tab.Y
id = -1
for init in self.init:
if case.Distance(init) < distance:
distance = case.Distance(init)
id = init.value
case.value = id
voisins = [
self.tab[elt]
for elt in case.Voisins()
if elt in self.tab and self.tab[elt].value != -1 and self.tab[elt].value != id
]
if len(voisins):
self.regions[id].addFro(case)
for elt in voisins:
if elt in self.regions[id].interieur:
self.regions[id].interieur.remove(elt)
self.regions[id].addFro(elt)
else:
self.regions[id].addInt(case)
示例2: __init__
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import iterB [as 别名]
class Seed:
def __init__(self,largeur,hauteur,noeud = {"type" : "plaque"},minValue = 0,maxValue = 255, value = 0):
self.function = {"rand" : self.rand, "degrade" : self.degrade, "plaque" : self.plaque}
self.maxValue = maxValue
self.minValue = minValue
self.X = largeur
self.Y = hauteur
self.tab = Tableau(self.X,self.Y)
if "args" in noeud:
self.function[noeud["type"]](noeud["args"])
else :
self.function[noeud["type"]]()
def degrade(self,args = {"direction":"Y","evolution":"increase"}):
if args["direction"] == "Y":
c = self.Y
current = lambda x,y : y
else:
c = self.X
current = lambda x,y : x - self.ligne(y)
if args["evolution"] == "increase":
fun = lambda x,y : self.maxValue * current(x,y) // c
elif args["evolution"] == "decrease":
fun = lambda x,y : self.maxValue * (c - (1 + current(x,y))) // c
elif args["evolution"] == "center":
fun = lambda x,y : min(self.maxValue * current(x,y) // c,self.maxValue * (c - (1 + current(x,y))) //c) * 2
elif args["evolution"] == "border":
fun = lambda x,y : max(self.maxValue * current(x,y) // c,self.maxValue * (c - (1 + current(x,y))) //c) - ( self.maxValue // 2) * 2
for(x,y) in self.tab.iterC():
self.tab[x,y] = Case(x,y)
self.tab[x,y].value = fun(x,y)
def rand(self,args = {}):
for(x,y) in self.tab.iterC():
self.tab[x,y] = Case(x,y)
self.tab[x,y].value = randint(self.minValue,self.maxValue)
def plaque(self,args = {"nombre" : 5, "plaques" : 8}):
for x,y in self.tab.iterC():
self.tab[x,y] = Case(x,y)
self.tab[x,y].value = 0
liste = [ elt for elt in self.tab.iterB(1) ]
nombre = args["nombre"]
plaque = args["plaques"]
plaques = GenRegionPasse(self.tab,None,plaque,5)
plaques.finalisation()
liste_plaque = [ (elt.interieur,elt.frontiere) for elt in plaques.regions]
for i in range(nombre):
li,lf = liste_plaque[randrange(len(liste_plaque))]
liste_plaque.remove((li,lf))
for elt in [ (elt.u,elt.v) for elt in li if (elt.u,elt.v) in liste]:
#self.tab[elt].value = randint((self.minValue + self.maxValue) * 3 // 4 , self.maxValue )
self.tab[elt].value = int(((plaques.iteration - self.tab[elt].nb + 1) / plaques.iteration)* self.maxValue)