本文整理汇总了Python中pandac.PandaModules.PNMImage.setXelA方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setXelA方法的具体用法?Python PNMImage.setXelA怎么用?Python PNMImage.setXelA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.PNMImage
的用法示例。
在下文中一共展示了PNMImage.setXelA方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MazeMapGui
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import setXelA [as 别名]
class MazeMapGui(DirectFrame):
notify = directNotify.newCategory('MazeMapGui')
def __init__(self, mazeCollTable, maskResolution = None, radiusRatio = None, bgColor = (0.8, 0.8, 0.8), fgColor = (0.5, 0.5, 0.5, 1.0)):
DirectFrame.__init__(self, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX)
self.hide()
self._bgColor = bgColor
self._fgColor = fgColor
self._mazeCollTable = mazeCollTable
self._mazeWidth = len(self._mazeCollTable[0])
self._mazeHeight = len(self._mazeCollTable)
self._maskResolution = maskResolution or DEFAULT_MASK_RESOLUTION
if radiusRatio is None:
self._radius = self._maskResolution * DEFAULT_RADIUS_RATIO
else:
self._radius = self._maskResolution * radiusRatio
self._revealedCells = []
for y in xrange(self._mazeHeight):
self._revealedCells.append([])
for u in xrange(self._mazeWidth):
self._revealedCells[y].append(False)
self._revealFunctions = {MazeRevealType.SmoothCircle: self._revealSmoothCircle,
MazeRevealType.HardCircle: self._revealHardCircle,
MazeRevealType.Square: self._revealSquare}
self._revealFunction = MAZE_REVEAL_TYPE
self.map = self._createMapTextureCard()
self.map.reparentTo(self)
self.maskedLayer = self.attachNewNode('maskedLayer')
self.mask = self._createMaskTextureCard()
self.mask.reparentTo(self)
self.visibleLayer = self.attachNewNode('visibleLayer')
self._laffMeterModel = loader.loadModel('phase_3/models/gui/laff_o_meter')
self._toon2marker = {}
return
def _createMapTextureCard(self):
mapImage = PNMImage(MAP_RESOLUTION, MAP_RESOLUTION)
mapImage.fill(*self._bgColor)
fgColor = VBase4D(*self._fgColor)
for x in xrange(self._mazeHeight):
for y in xrange(self._mazeWidth):
if self._mazeCollTable[y][x] == 1:
ax = float(x) / self._mazeWidth * MAP_RESOLUTION
invertedY = self._mazeHeight - 1 - y
ay = float(invertedY) / self._mazeHeight * MAP_RESOLUTION
self._drawSquare(mapImage, int(ax), int(ay), 10, fgColor)
mapTexture = Texture('mapTexture')
mapTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
mapTexture.setMinfilter(Texture.FTLinear)
mapTexture.load(mapImage)
mapTexture.setWrapU(Texture.WMClamp)
mapTexture.setWrapV(Texture.WMClamp)
mapImage.clear()
del mapImage
cm = CardMaker('map_cardMaker')
cm.setFrame(-1.0, 1.0, -1.0, 1.0)
map = self.attachNewNode(cm.generate())
map.setTexture(mapTexture, 1)
return map
def _createMaskTextureCard(self):
self._maskImage = PNMImage(self._maskResolution, self._maskResolution, 4)
for x in xrange(self._maskResolution):
for y in xrange(self._maskResolution):
self._maskImage.setXelA(x, y, 0, 0, 0, 1)
self.maskTexture = Texture('maskTexture')
self.maskTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
self.maskTexture.setMinfilter(Texture.FTLinear)
self.maskTexture.setWrapU(Texture.WMClamp)
self.maskTexture.setWrapV(Texture.WMClamp)
self.maskTexture.load(self._maskImage)
base.graphicsEngine.renderFrame()
cm = CardMaker('mask_cardMaker')
cm.setFrame(-1.1, 1.1, -1.1, 1.1)
mask = self.attachNewNode(cm.generate())
mask.setTexture(self.maskTexture, 1)
mask.setTransparency(1)
return mask
def _drawSquare(self, image, ulx, uly, size, color):
x = int(ulx)
while x <= ulx + size:
y = int(uly)
while y <= uly + size:
if x > 0 and y > 0 and x < image.getXSize() and y < image.getYSize():
image.setXelA(x, y, color)
y += 1
x += 1
def destroy(self):
del self._mazeCollTable
del self._maskResolution
del self._radius
del self._revealedCells
del self._revealFunctions
del self._revealFunction
#.........这里部分代码省略.........
示例2: TexturePainter
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import setXelA [as 别名]
#.........这里部分代码省略.........
for py in xrange(-smoothRadius,smoothRadius+1):
if inImage(x+dx+px,y+dy+py):
average += self.editImage.getXelA(x+dx+px,y+dy+py)
dividor += 1
average /= float(dividor)
data[(x+dx,y+dy)] = average
# save to image
for (px,py), newValue in data.items():
currentValue = self.editImage.getXelA(px,py)
diffValue = currentValue - newValue
dx = px - x
dy = py - y
multiplier = getBrushColor(dx, dy)
print dx, dy, multiplier
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
# not sure if this is correct
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
'''r = currentValue.getX() * (1-multiplier*self.paintColor.getX()) + diffValue.getX() * multiplier*self.paintColor.getX()
g = currentValue.getY() * (1-multiplier*self.paintColor.getY()) + diffValue.getY() * multiplier*self.paintColor.getY()
b = currentValue.getZ() * (1-multiplier*self.paintColor.getZ()) + diffValue.getZ() * multiplier*self.paintColor.getZ()
a = currentValue.getW() * (1-multiplier*self.paintColor.getW()) + diffValue.getW() * multiplier*self.paintColor.getW()'''
r = currentValue.getX() - multiplier * diffValue.getX()
g = currentValue.getY() - multiplier * diffValue.getY()
b = currentValue.getZ() - multiplier * diffValue.getZ()
a = currentValue.getW() - multiplier * diffValue.getW()
if self.editImage.hasAlpha():
self.editImage.setXelA(px,py,VBase4D(r,g,b,a))
else:
self.editImage.setXel(px,py,VBase3D(r,g,b))
#self.editImage.setXelA(x,y,value)
if self.paintEffect == TEXTUREPAINTER_BRUSH_FLATTEN:
dividor = 0
average = VBase4D(0)
for dx in xrange(-radius, radius+1):
for dy in xrange(-radius, radius+1):
if inImage(x+dx,y+dy):
multiplier = getBrushColor(dx, dy)
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
dividor += multiplier
average += self.editImage.getXelA(x+dx,y+dy) * multiplier
average /= dividor
for dx in xrange(-radius, radius+1):
for dy in xrange(-radius, radius+1):
if inImage(x+dx,y+dy):
multiplier = getBrushColor(dx, dy)
'''if self.paintSmooth:
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy))) / (radius*radius)
else:
# not sure if this is correct
multiplier = ((radius-math.fabs(dx))*(radius-math.fabs(dy)))'''
currentValue = self.editImage.getXelA(x+dx,y+dy)
r = currentValue.getX() * (1-multiplier*self.paintColor.getX()) + average.getX() * multiplier*self.paintColor.getX()
g = currentValue.getY() * (1-multiplier*self.paintColor.getY()) + average.getY() * multiplier*self.paintColor.getY()
b = currentValue.getZ() * (1-multiplier*self.paintColor.getZ()) + average.getZ() * multiplier*self.paintColor.getZ()