本文整理汇总了Python中pandac.PandaModules.PNMImage.getYSize方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.getYSize方法的具体用法?Python PNMImage.getYSize怎么用?Python PNMImage.getYSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.PNMImage
的用法示例。
在下文中一共展示了PNMImage.getYSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transparencyKey
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
def transparencyKey(filename):
image = PNMImage(GAME + "/textures/effects/" + filename)
image.addAlpha()
backgroundColor = None
for y in range(image.getYSize()):
for x in range(image.getXSize()):
if backgroundColor == None:
backgroundColor = Color(image.getRedVal(x, y), image.getGreenVal(x, y), image.getGreenVal(x, y), 0)
if (
image.getRedVal(x, y) == backgroundColor.R
and image.getGreenVal(x, y) == backgroundColor.G
and image.getGreenVal(x, y) == backgroundColor.B
):
# Transparent
image.setAlpha(x, y, 0.0)
else:
# Opaque
image.setAlpha(x, y, 1.0)
return image
示例2: make_data
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
def make_data(self, hmapfile):
# open heightmap for reading pixel data
heightmap = PNMImage()
heightmap.read(Filename(hmapfile))
xs = heightmap.getXSize()
ys = heightmap.getYSize()
# generate data bi-dimensional array
data = []
for x in range(xs):
data.append([])
for y in range(ys):
# set data dictionary properties
# name
name = "cell_" + str(x) + "_" + str(y)
# height
height = (heightmap.getXel(x, ys - y - 1)[0] * 10)
if self.retro == True:
if height < 1 :
height = height / 5
height = int(height)
# c and rgb
c = [random.random(), random.random(), random.random()]
rgb = (int(c[0] * 255), int(c[1] * 255), int(c[2] * 255))
# default texture
texture = self.tiles[0]['tex']
texturenum = 0
score = self.tiles[0]['score']
# from rgb we assign tex and score
for n in range(len(self.tiles)):
if rgb == self.tiles[n]['rgb']:
texture = self.tiles[n]['tex']
texturenum = n
score = self.tiles[n]['score']
break
# set terrain data dictionary
data[x].append({'name':name, 'h':height, 'c':c, 'rgb':rgb, 'tex':texture,
'texnum':texturenum, 'score':score})
return data
示例3: __init__
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
def __init__(self, image_path, rowPerFace, name=None,\
rows=1, cols=1, scale=1.0,\
twoSided=False, alpha=TRANS_ALPHA,\
repeatX=1, repeatY=1,\
anchorX=ALIGN_CENTER, anchorY=ALIGN_BOTTOM):
"""
Create a card textured with an image. The card is sized so that the ratio between the
card and image is the same.
"""
global SpriteId
self.spriteNum = str(SpriteId)
SpriteId += 1
scale *= self.PIXEL_SCALE
self.animations = {}
self.scale = scale
self.repeatX = repeatX
self.repeatY = repeatY
self.flip = {'x':False,'y':False}
self.rows = rows
self.cols = cols
self.currentFrame = 0
self.currentAnim = None
self.loopAnim = False
self.frameInterrupt = True
# Create the NodePath
if name:
self.node = NodePath("Sprite2d:%s" % name)
else:
self.node = NodePath("Sprite2d:%s" % image_path)
# Set the attribute for transparency/twosided
self.node.node().setAttrib(TransparencyAttrib.make(alpha))
if twoSided:
self.node.setTwoSided(True)
# Make a filepath
self.imgFile = Filename(image_path)
if self.imgFile.empty():
raise IOError, "File not found"
# Instead of loading it outright, check with the PNMImageHeader if we can open
# the file.
imgHead = PNMImageHeader()
if not imgHead.readHeader(self.imgFile):
raise IOError, "PNMImageHeader could not read file. Try using absolute filepaths"
# Load the image with a PNMImage
image = PNMImage()
image.read(self.imgFile)
self.sizeX = image.getXSize()
self.sizeY = image.getYSize()
# We need to find the power of two size for the another PNMImage
# so that the texture thats loaded on the geometry won't have artifacts
textureSizeX = self.nextsize(self.sizeX)
textureSizeY = self.nextsize(self.sizeY)
# The actual size of the texture in memory
self.realSizeX = textureSizeX
self.realSizeY = textureSizeY
self.paddedImg = PNMImage(textureSizeX, textureSizeY)
if image.hasAlpha():
self.paddedImg.alphaFill(0)
# Copy the source image to the image we're actually using
self.paddedImg.blendSubImage(image, 0, 0)
# We're done with source image, clear it
image.clear()
# The pixel sizes for each cell
self.colSize = self.sizeX/self.cols
self.rowSize = self.sizeY/self.rows
# How much padding the texture has
self.paddingX = textureSizeX - self.sizeX
self.paddingY = textureSizeY - self.sizeY
# Set UV padding
self.uPad = float(self.paddingX)/textureSizeX
self.vPad = float(self.paddingY)/textureSizeY
# The UV dimensions for each cell
self.uSize = (1.0 - self.uPad) / self.cols
self.vSize = (1.0 - self.vPad) / self.rows
self.cards = []
self.rowPerFace = rowPerFace
for i in range(len(rowPerFace)):
card = CardMaker("Sprite2d-Geom")
# The positions to create the card at
if anchorX == self.ALIGN_LEFT:
posLeft = 0
#.........这里部分代码省略.........
示例4: TerrainTile
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
class TerrainTile(GeoMipTerrain):
"""TerrainTiles are the building blocks of a terrain."""
def __init__(self, terrain, x, y):
"""Builds a Tile for the terrain at input coordinates.
Important settings are used directly from the terrain.
This allows for easier setting changes and reduces memory overhead.
x and y parameters give the appropriate world coordinates of this tile.
"""
self.terrain = terrain
self.xOffset = x
self.yOffset = y
self.heightMapDetail = 1 # higher means greater detail
self.name = "ID" + str(terrain.id) + "_X" + str(x) + "_Y" + str(y)
GeoMipTerrain.__init(self, name=self.name)
self.image = PNImage()
#self.setAutoFlatten(GeoMipTerrain.AFMOff
self.setFocalPoint(self.terrain.focus)
self.setAutoFlatten(GeoMipTerrain.AFMOff)
self.getRoot().setPos(x, y, 0)
if self.terrain.bruteForce:
GeoMipTerrain.setBruteForce(self, True)
GeoMipTerrain.setBlockSize(self, self.terrain.heightMapSize * self.heightMapDetail)
else:
GeoMipTerrain.setBlockSize(self, self.terrain.blockSize/2)
#self.setBorderStitching(1)
self.setNear(self.terrain.near)
self.setFar(self.terrain.far)
def update(self):
"""Updates the GeoMip to use the correct LOD on each block."""
#logging.info("TerrainTile.update()")
GeoMipTerrain.update(self)
@pstat
def updateTask(self, task):
"""Updates the GeoMip to use the correct LOD on each block."""
self.update()
return task.again
#@pstat
def setHeightField(self, filename):
"Set the GeoMip heightfield from a heightmap image."""
GeoMipTerrain.setHeightfield(self, filename)
@pstat
def generate(self):
GeoMipTerrain.generate(self)
@pstat
def setHeight(self):
"""Sets the height field to match the height map image."""
self.setHeightField(self.image)
@pstat
def makeHeightMap(self):
"""Generate a new heightmap image.
Panda3d GeoMipMaps require an image from which to build and update
their height field. This function creates the correct image using the
tile's position and the Terrain's getHeight() function.
"""
if SAVED_HEIGHT_MAPS:
fileName = "maps/height/" + self.name + ".png"
self.getRoot().setTag('EditableTerrain', '1')
if self.image.read(Filename(fileName)):
logging.info( "read heightmap from " + fileName)
return
heightMapSize = self.terrain.tileSize * self.heightMapDetail + 1
self.image = PNMImage(heightMapSize, heightMapSize, 1, 65535)
ySize = self.image.getYSize() - 1
getHeight = self.terrain.getHeight
setGray = self.image.setGray
xo = self.xOffset
yo = self.yOffset
d = self.heightMapDetail
for x in range(self.image.getXSize()):
for y in range(ySize + 1):
height = getHeight(x / d + xo, y / d + yo)
# feed pixel into image
# why is it necessary to invert the y axis I wonder?
setGray(x, ySize - y, height)
#self.postProcessImage()
if SAVED_HEIGHT_MAPS:
#.........这里部分代码省略.........
示例5: Region
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
class Region(DirectObject.DirectObject):
'''Stuff'''
def __init__(self):
self.tiles = []
self.cities = {}
self.accept('loadRegion', self.load)
self.accept("updatedTiles", self.updateTiles)
self.accept("newCity", self.newCity)
self.accept("clickForCity", self.checkCity)
self.accept("unfoundCity", self.unfoundCity)
self.accept("enterCity", self.enterCity)
def load(self, container, name="New Region"):
'''Loads a new region, usually from connecting to a server
Or starting a new or previously saved region.
'''
import base64
self.heightmap = PNMImage()
imageString = base64.b64decode(container.heightmap)
self.heightmap.read(StringStream(imageString))
self.region_size = (self.heightmap.getXSize()-1, self.heightmap.getYSize()-1)
position = 0
tileid = 0
total_tiles = self.region_size[0] * self.region_size[1]
ranges = []
tiles = []
for tile in container.tiles:
tiles.append((tile.id, tile.cityid))
for n in range(len(tiles)):
try:
ranges.append((tiles[n][0], tiles[n+1][0]-1, tiles[n][1]))
except:
ranges.append((tiles[n][0], total_tiles, tiles[n][1]))
for r in ranges:
for x in range(r[0], r[1]+1):
#print "r0, r1, x", r[0], r[1], x
self.tiles.append(Tile(tileid, r[2]))
#print "Len", len(self.tiles)
tileid += 1
position = 0
for y in range(self.region_size[1]):
for x in range(self.region_size[0]):
self.tiles[position].coords = (x,y)
position += 1
for city in container.cities:
self.newCity(city)
messenger.send("generateRegion", [self.heightmap, self.tiles, self.cities, container])
def updateTiles(self, container):
x = 0
for tile in container:
x += 1
self.tiles[tile.id].cityid = tile.cityid
print x, "tiles updated from server."
messenger.send("updateRegion", [self.heightmap, self.tiles, self.cities])
def newCity(self, city):
self.cities[city.id] = {"name": city.name, "mayor": city.mayor, "funds": city.funds, "population": city.population}
def checkCity(self, cell):
'''Checks for city in given cell for region gui display'''
if not cell: return
tile = self.getTile(cell[0], cell[1])
if tile.cityid:
messenger.send("showRegionCityWindow", [tile.cityid, self.cities[tile.cityid]])
def getTile(self, x, y):
'''Returns tile by coordinate.
Thankfully smart enough to find a way to not iterate
'''
value = y * self.region_size[0] + x
return self.tiles[value]
def unfoundCity(self, ident):
'''Unfounds a city'''
del self.cities[ident]
def enterCity(self, ident):
'''Processess information needed for graphical elements to enter city view.'''
# We need to send list of tiles for terrain manager
tiles = []
xsum = 0
ysum = 0
n = 0
for tile in self.tiles:
if tile.cityid is ident:
tiles.append(tile)
# We need to compute center of city to target camera there
xsum += tile.coords[0]
ysum += tile.coords[1]
n += 1
xavg = xsum/n
yavg = ysum/n
position = (xavg, yavg)
# We need to send city info so gui elements can be drawn
city = self.cities[ident]
#.........这里部分代码省略.........
示例6: TexturePainter
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import getYSize [as 别名]
#.........这里部分代码省略.........
# create the buffers
self.__createBuffer()
# when the window is resized, the background buffer etc must be updated.
self.accept("window-event", self.__windowEvent)
# some debugging stuff
self.accept("v", base.bufferViewer.toggleEnable)
self.accept("V", base.bufferViewer.toggleEnable)
def __disableEditor(self):
print "I: TexturePainter.__disableEditor"
self.__destroyBuffer()
# ignore window-event and debug
self.ignoreAll()
def __windowEvent(self, win=None):
''' when the editor is enabled, update the buffers etc. when the window
is resized '''
print "I: TexturePainter.windowEvent"
# with a fixed backgroudn buffer size this is not needed anymore
if False:
#if self.texturePainterStatus != TEXTURE_PAINTER_STATUS_DISABLED:
if self.modelColorBuffer:
if WindowManager.activeWindow:
# on window resize there seems to be never a active window
win = WindowManager.activeWindow.win
else:
win = base.win
if self.modelColorBuffer.getXSize() != win.getXSize() or self.modelColorBuffer.getYSize() != win.getYSize():
'''print " - window resized",\
self.modelColorBuffer.getXSize(),\
win.getXSize(),\
self.modelColorBuffer.getYSize(),\
win.getYSize()'''
# if the buffer size doesnt match the window size (window has been resized)
self.__destroyBuffer()
self.__createBuffer()
self.__updateModel()
else:
print "W: TexturePainter.__windowEvent: no buffer"
self.__createBuffer()
def __createBuffer(self):
''' create the buffer we render in the background into '''
print "I: TexturePainter.__createBuffer"
# the window has been modified
if WindowManager.activeWindow:
# on window resize there seems to be never a active window
win = WindowManager.activeWindow.win
else:
win = base.win
# get the window size
self.windowSizeX = win.getXSize()
self.windowSizeY = win.getYSize()
# create a buffer in which we render the model using a shader
self.paintMap = Texture()
# 1.5.4 cant handle non power of 2 buffers
self.modelColorBuffer = createOffscreenBuffer(-3, TEXTUREPAINTER_BACKGROUND_BUFFER_RENDERSIZE[0], TEXTUREPAINTER_BACKGROUND_BUFFER_RENDERSIZE[1]) #self.windowSizeX, self.windowSizeY)
self.modelColorBuffer.addRenderTexture(self.paintMap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)