本文整理汇总了Python中tableau.Tableau.iterC方法的典型用法代码示例。如果您正苦于以下问题:Python Tableau.iterC方法的具体用法?Python Tableau.iterC怎么用?Python Tableau.iterC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tableau.Tableau
的用法示例。
在下文中一共展示了Tableau.iterC方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import iterC [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)
示例2: GenRegionVoronoi
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import iterC [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)
示例3: __init__
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import iterC [as 别名]
class MapGen:
def __init__(self, largeur, hauteur, modele): # X,Y,Liste_Coeff
self.X = largeur
self.Y = hauteur
self.MAXVALUE = 256
self.tab = Tableau(self.X, self.Y)
self.modele = Modele("patron.xml")
self.seed = [(key, Seed(self.X, self.Y, elt["seed"])) for key, elt in self.modele.racine["couche"].items()]
for x, y in self.tab.iterC():
self.tab[x, y] = Case(x, y)
for key, s in self.seed:
self.tab[x, y].biome.set(key, s.tab[x, y].value)
def cycle(self, duree):
for i in range(duree):
self.Division()
self.Egalisation()
self.Finalisation()
def Division(self, mod=2):
aux = Tableau(self.tab.X * 2, self.tab.Y * 2)
for y in range(self.Y):
init = self.tab.ligne(y)
offset = 0
if init * 2 > y:
offset = 1
for x in range(init, self.X + init):
for y2 in range(mod):
init2 = self.tab.ligne(y2)
for x2 in range(init2, mod + init2):
aux[(x) * mod + x2 - offset, y * mod + y2] = Case((x) * mod + x2 - offset, y * mod + y2)
aux[(x) * mod + x2 - offset, y * mod + y2].biome.copy(self.tab[x, y].biome)
self.tab = aux
self.Y *= 2
self.X *= 2
def Egalisation(self):
self.aux = Tableau(self.tab.X, self.tab.Y)
self.tab.iter(self._egalisation)
self.tab = self.aux
def _egalisation(self, x, y):
biome = self.Moyenne(x, y)
self.aux[x, y] = Case(x, y)
self.aux[x, y].biome = biome
def Moyenne(self, x, y):
aux = []
biome = Biome()
compteur = 0
for elt in self.modele.hierarchie:
biome.set(elt, 0)
for elt in self.tab[x, y].Voisins():
if elt in self.tab:
for elt1 in self.modele.hierarchie:
biome.add(elt1, self.tab[elt].biome.dict[elt1])
aux.append(elt)
compteur = compteur + 1
x1, y1 = aux[randrange(len(aux))]
for elt in biome.dict.keys():
div = 0
biome.div(elt, compteur)
biome.mult(elt, self.modele.argsRand[elt]["moyenne"])
div += self.modele.argsRand[elt]["moyenne"]
biome.add(elt, self.tab[x, y].biome.dict[elt] * self.modele.argsRand[elt]["centre"])
div += self.modele.argsRand[elt]["centre"]
biome.add(elt, self.tab[x1, y1].biome.dict[elt] * self.modele.argsRand[elt]["rand"])
div += self.modele.argsRand[elt]["rand"]
biome.div(elt, div)
return biome
def Finalisation(self):
aux = {}
self.niveaux = {}
for i in range(self.MAXVALUE):
for elt in self.modele.hierarchie:
aux[elt, i] = 0
for case in self.tab.values():
for elt in self.modele.hierarchie:
aux[elt, case.biome.dict[elt]] += 1
for elt in self.modele.hierarchie:
self.niveaux[elt] = []
i = 0
buffer_ = 1
for valeur in self.modele.pourcents[elt]:
valeur = float(valeur)
while i < self.MAXVALUE and buffer_ * 100 / (self.X * self.Y) <= valeur:
buffer_ += aux[elt, i]
i += 1
self.niveaux[elt].append(i)
for case in self.tab.values():
for elt in self.modele.hierarchie:
i = 0
while i < len(self.niveaux[elt]) and case.biome.dict[elt] > self.niveaux[elt][i]:
i += 1
case.biome.dict[elt] = i
self.modele.determine(case.biome)
def getSurface(self):
w = sf.RenderTexture(hexagone.l * self.X + hexagone.l // 2, (hexagone.L * 1.5) * (self.Y // 2 + 1))
#.........这里部分代码省略.........