本文整理汇总了Python中pandac.PandaModules.PNMImage类的典型用法代码示例。如果您正苦于以下问题:Python PNMImage类的具体用法?Python PNMImage怎么用?Python PNMImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PNMImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_heightmap_tex
def get_heightmap_tex(self, size, filename = None):
"""Generate texture of map
"""
mod = self.world_size / size
image = PNMImage(size, size)
for x in xrange(size):
for y in xrange(size):
px = x * mod
py = y * mod
height = self[px, py]
color = height / 50
r = 0
g = 0
b = 0
if color > 255:
color = 255
if color < 0:
color = abs(color)
b = color
else:
g = color
image.setPixel(x, y, (r, g, b))
if filename != None:
image.write(filename)
#for x in xrange(-1, 2):
#for y in xrange(-1, 2):
#image.setPixel(int(world.chunks_map.charX)+x, int(world.chunks_map.charY)+y, (255, 0, 0))
texture = Texture()
texture.load(image)
return texture
示例2: makeSlopeMap
def makeSlopeMap(self):
self.slopeMap = PNMImage()
if SAVED_SLOPE_MAPS:
fileName = "maps/slope/" + self.name + ".png"
if self.slopeMap.read(Filename(fileName)):
logging.info( "read slopemap from " + fileName)
return
self.slopeMap = PNMImage(self.terrain.heightMapSize, self.terrain.heightMapSize)
self.slopeMap.makeGrayscale()
self.slopeMap.setMaxval(65535)
size = self.slopeMap.getYSize()
getNormal = self.getNormal
setGray = self.slopeMap.setGray
for x in range(size):
for y in range(size):
#note getNormal works at the same resolution as the heightmap
normal = getNormal(x, y)
# feed pixel into image
# why is it necessary to invert the y axis I wonder?
#logging.info( normal)
normal.z /= self.terrain.getSz()
normal.normalize()
slope = 1.0 - normal.dot(Vec3(0, 0, 1))
setGray(x, y, slope)
if SAVED_SLOPE_MAPS:
fileName = "maps/slope/" + self.name + ".png"
logging.info( "saving slopemap to " + fileName)
self.slopeMap.write(Filename(fileName))
示例3: loadFlatQuad
def loadFlatQuad(self, fullFilename):
cm = CardMaker("cm-%s" % fullFilename)
cm.setColor(1.0, 1.0, 1.0, 1.0)
aspect = base.camLens.getAspectRatio()
htmlWidth = 2.0 * aspect * WEB_WIDTH_PIXELS / float(WIN_WIDTH)
htmlHeight = 2.0 * float(WEB_HEIGHT_PIXELS) / float(WIN_HEIGHT)
cm.setFrame(-htmlWidth / 2.0, htmlWidth / 2.0, -htmlHeight / 2.0, htmlHeight / 2.0)
bottomRightX = WEB_WIDTH_PIXELS / float(WEB_WIDTH + 1)
bottomRightY = WEB_HEIGHT_PIXELS / float(WEB_HEIGHT + 1)
cm.setUvRange(Point2(0, 1 - bottomRightY), Point2(bottomRightX, 1))
card = cm.generate()
quad = NodePath(card)
jpgFile = PNMImage(WEB_WIDTH, WEB_HEIGHT)
smallerJpgFile = PNMImage()
readFile = smallerJpgFile.read(Filename(fullFilename))
if readFile:
jpgFile.copySubImage(smallerJpgFile, 0, 0)
guiTex = Texture("guiTex")
guiTex.setupTexture(Texture.TT2dTexture, WEB_WIDTH, WEB_HEIGHT, 1, Texture.TUnsignedByte, Texture.FRgba)
guiTex.setMinfilter(Texture.FTLinear)
guiTex.load(jpgFile)
guiTex.setWrapU(Texture.WMClamp)
guiTex.setWrapV(Texture.WMClamp)
ts = TextureStage("webTS")
quad.setTexture(ts, guiTex)
quad.setTransparency(0)
quad.setTwoSided(True)
quad.setColor(1.0, 1.0, 1.0, 1.0)
result = quad
else:
result = None
Texture.setTexturesPower2(1)
return result
示例4: _createMapTextureCard
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
示例5: make_blocks_texmap
def make_blocks_texmap(self):
images = []
# 0 - sand
images.append(PNMImage('res/textures/{0}sand.png'.format(
Config().tex_suffix)))
# 1 - land
images.append(PNMImage('res/textures/{0}land.png'.format(
Config().tex_suffix)))
# 2 - low_mount
images.append(PNMImage("res/textures/{0}low_mount.png".format(
Config().tex_suffix)))
# 3 - mid_mount
images.append(PNMImage("res/textures/{0}mid_mount.png".format(
Config().tex_suffix)))
# 4 - high_mount
images.append(PNMImage("res/textures/{0}high_mount.png".format(
Config().tex_suffix)))
d = images[0].getReadXSize()
# 16 x 16 textures
size = d * self.map_size
image_all = PNMImage(size, size)
n = 0
for i in xrange(0, size, d):
for j in xrange(0, size, d):
image_all.copySubImage(images[n], j, i)
n += 1
if n >= len(images):
break
if n >= len(images):
break
self['world_blocks'] = Texture()
self['world_blocks'].load(image_all)
self['world_blocks'].setMagfilter(Texture.FTLinearMipmapLinear)
self['world_blocks'].setMinfilter(Texture.FTLinearMipmapLinear)
示例6: paintEvent
def paintEvent(self, event):
screenData = StringStream() # Used to pass the data as a string
screenImage = PNMImage() # Converts the texture data into a format usable with Qt
if self.pandaTexture.hasRamImage():
print "Should draw yes?"
self.pandaTexture.store(screenImage)
screenImage.write(screenData, "test.ppm")
self.paintPixmap.loadFromData(screenData.getData())
self.paintSurface.setPixmap(self.paintPixmap)
示例7: createPickingImage
def createPickingImage(size):
''' create a picking image with uniq colors for each point in the image
'''
image = PNMImage(*size)
for x in xrange(size[0]):
for y in xrange(size[1]):
r = x % 256
g = y % 256
b = (x // 256) + (y//256) * 16
image.setXelVal(x,y,r,g,b)
# Reverse way is:
# tx = r + ((b%16)*256)
# ty = g + ((b//16)*256)
imageFilename = 'data/textures/index-%i-%i.png' % (size[0], size[1])
image.write(Filename(imageFilename))
示例8: get_map_2d_tex
def get_map_2d_tex(self, map2d, factor = 1):
"""Generate texture for map2d, factor - for size [size / factor]
"""
size = map2d.size / factor
image = PNMImage(size, size)
for x in xrange(size):
for y in xrange(size):
px = x * factor
py = y * factor
if map2d[(px, py)] <= map2d.water_z:
image.setPixel(x, y, (0, 0, 100))
else:
image.setPixel(x, y, (0, 100, 0))
texture = Texture()
texture.load(image)
return texture
示例9: noiseTaskVerySmart
def noiseTaskVerySmart(self, Task=None):
if Task == None:
o = 0
else:
o = Task.frame
p = Perlin.Perlin(numberOfOctaves=1, smooth=False, seed=0)
freq = 2 ** o
self.oldImage = self.myImage
self.myImage = PNMImage(freq + 1, freq + 1)
self.myImage.makeGrayscale()
self.myImage.gaussianFilterFrom(1.0, self.oldImage)
for x in range(0, freq + 1):
for y in range(0, freq + 1):
self.myImage.setGray(
x, y, self.myImage.getGray(x, y) + p.intNoise2D(x * freq, y * freq) * (0.75 ** o) / 2
)
self.myTexture.load(self.myImage)
if Task != None:
if freq < self.size:
return Task.cont
else:
print time() - self.startTime
return Task.done
示例10: setupHeightfield
def setupHeightfield( self ):
# Prep terrain textures
#coverTextureFile = "data/textures/ground/green.jpg"
#self.mCoverTexture = loader.loadTexture(coverTextureFile)
# Setup heightfield
self.mHeightFieldTesselator = HeightfieldTesselator("Heightfield")
#fName = "data/textures/ground/heightfield.png"
#self.mHeightFieldTesselator.setPolyCount(10000)
#fileObj = Filename(fName)
self.mTerrainVScale = self.mTerrainUScale = 1.0/1024.0
myImage=PNMImage(256,256)
myImage.makeGrayscale()
p = Perlin(numberOfOctaves = 10, persistance = 0.65, smooth = False)
for y in range(0,256):
for x in range(0,256):
i = p.noise2D(float(x)/256.0,float(y)/256.0)
myImage.setGray(x, y, abs(i))
bigImage=PNMImage(1024, 1024)
bigImage.gaussianFilterFrom(1.0, myImage)
fileObj = Filename("data/textures/ground/myHeightfield.png")
bigImage.write(fileObj)
#myTexture = Texture()
#myTexture.load(bigImage)
self.mHeightFieldTesselator.setHeightfield(fileObj)
self.mTerrainHeight = MAPSIZE/10
self.mHeightFieldTesselator.setVerticalScale(self.mTerrainHeight)
self.mHorizontalScale = MAPSIZE/1024.0
self.mHeightFieldTesselator.setHorizontalScale(self.mHorizontalScale)
self.mHeightFieldNode = None
# self.tex0 = loader.loadTexture( 'models/textures/ground/schachbrett.png' )
self.tex0 = loader.loadTexture( 'data/textures/ground/mud-tile.png' )
#self.tex1 = loader.loadTexture( 'data/models/textures/ground/green.jpg' )
#self.tex2 = loader.loadTexture( 'data/models/textures/ground/grey-green-leaves.jpg' )
#self.ts0 = TextureStage( 'dirt' )
#self.ts1 = TextureStage( 'fungus' )
#self.ts2 = TextureStage( 'grass' )
self.updateHeightField()
示例11: getWaterSurface
def getWaterSurface(manager, polycount=50000, size=(512, 512)):
# Get cache directory...
cacheDir = manager.get("paths").getConfig().find("cache").get("path")
# Check if the data required already exists...
cachedWaterSurface = "%s/plane-%dx%d-%dk.bam" % (cacheDir, size[0], size[1], int(polycount / 1000))
try:
return loader.loadModel(cachedWaterSurface)
except:
pass
# Make cache directory if needed...
if not os.path.isdir(cacheDir):
os.mkdir(cacheDir)
# Put in an image...
img = PNMImage(*size)
img.makeGrayscale()
img.fill(0, 0, 0)
img.write("%s/black-%dx%d.png" % (cacheDir, size[0], size[1]))
# Put in a mesh...
ht = HeightfieldTesselator("plane")
assert ht.setHeightfield(Filename("%s/black-%dx%d.png" % (cacheDir, size[0], size[1])))
ht.setPolyCount(polycount)
ht.setFocalPoint(size[0] * 0.5, size[1] * 0.5)
node = ht.generate()
node.setPos(-0.5 * size[0], 0.5 * size[1], 0)
node.flattenLight()
node.writeBamFile(cachedWaterSurface)
return node
示例12: grassTexture
def grassTexture(imgSize=(256,256)):
"""Return a green, 'grassy' texture (PNMImage) of the given image size,
produced using 2D Perlin noise."""
# Initialuse the PNMImage object
img = PNMImage(*imgSize)
# Initalise 4 PerlinNoise2 objects to produce noise at different scales
noise1 = PerlinNoise2()
noise1.setScale(2.0)
noise2 = PerlinNoise2()
noise2.setScale(5.0)
noise3 = PerlinNoise2()
noise3.setScale(0.25)
noise4 = PerlinNoise2()
noise4.setScale(0.125)
# For each pixel in the image, set the red and blue values of the pixel to
# constant values, and set the green value of the pixel using all 4
# PerlinNoise2 objects.
red = 0.125 # Colour values in PNMImage are doubles in the range [0.0,1.0]
blue = 0.0625
for x in xrange(imgSize[0]):
for y in xrange(imgSize[1]):
img.setRed(x,y,red)
img.setBlue(x,y,blue)
pos = Vec2(1.0/32*x, 1.0/32*y)
img.setGreen(x,y,(0.5 + noise1(pos)*0.0625 + noise2(pos)*0.0625 +
noise3(pos)*0.125 + noise4(pos)*0.0625))
return img
示例13: generate_map_texture
def generate_map_texture(map_tree, factor):
map_world = map_tree.map3d
size = map_world.size / factor
image = PNMImage(size, size)
#image.fill(0,0,0)
for x in xrange(size):
for y in xrange(size):
px = x * factor
py = y * factor
if map_world[(px, py)] <= map_world.water_z:
image.setPixel(x, y, (0, 0, 100))
else:
image.setPixel(x, y, (0, 100, 0))
char_x, char_y, char_z = map_tree.coords
char_x = char_x / factor
char_y = char_y / factor
image.setPixel(char_x, char_y, (255, 0, 0))
#if factor>2:
#image.setPixel(char_x, char_y, (255, 0, 0))
#else:
#for x in xrange(char_x - 1, char_x+2):
#cx = x
#if cx > size-1: cx = size-1
#if cx < 0: cx = 0
#for y in xrange(char_y - 1, char_y+2):
#cy = y
#if cy > size-1: cy = size-1
#if cy < 0: cy = 0
#image.setPixel(cx, cy, (255, 0, 0))
texture = Texture()
texture.load(image)
return texture
示例14: run
def run(self):
size = 256
pb = Perlin.Perlin( persistance = 0.500, smooth = False, seed = random.random() )
myImage2 = pb.imgNoise2D(size,True)
myImage=PNMImage(size,size)
myImage.makeGrayscale()
myImage.setMaxval( (2<<16)-1 )
myImage.fill(0.5)
line = lineDrawer.LineDrawer(myImage,(42,180),(13,253),13)
for x in range(size):
for y in range(size):
gray = myImage.getGray(x,y) - 0.5
gray = gray + (myImage2.getGray(x,y) - 0.5)
myImage.setGray(x,y,gray + 0.5)
self.myTexture.load(myImage)
示例15: draw_map
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