本文整理汇总了Python中pandac.PandaModules.PNMImage.setXel方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setXel方法的具体用法?Python PNMImage.setXel怎么用?Python PNMImage.setXel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.PNMImage
的用法示例。
在下文中一共展示了PNMImage.setXel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_map
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import setXel [as 别名]
def draw_map(self, heightmap, height_modifier):
"""Draws the heightmap in the image
The range of values is assumed to be 0.0 to 1.0 in a 2D, square array.
The range is converted to grayscale values of 0 to 255.
A heightmap modifier is added to boost height differences.
"""
# get size
size = (len(heightmap), len(heightmap[0]))
# create image
hmap = PNMImage(size[0], size[1])
# draw map
for y in range(size[0]):
for x in range(size[1]):
h = (heightmap[x][y]) * height_modifier
try:
hmap.setXel(x, y, h)
except:
print "Error on x,y: ", str((x, y)), "; map --> 0-255 value: ", str((heightmap[x][y], h))
return hmap
示例2: TexturePainter
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import setXel [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()