当前位置: 首页>>代码示例>>Python>>正文


Python Image.get_region方法代码示例

本文整理汇总了Python中kivy.core.image.Image.get_region方法的典型用法代码示例。如果您正苦于以下问题:Python Image.get_region方法的具体用法?Python Image.get_region怎么用?Python Image.get_region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.core.image.Image的用法示例。


在下文中一共展示了Image.get_region方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_texture

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
 def load_texture(key, path, region=None, mipmap=False, wrap=None):
     texture_path = join(RESOURCES_DIR, path)
     texture = Image(texture_path, mipmap=mipmap).texture
     if region:
         texture = texture.get_region(*region)
 
     textures[key] = texture
开发者ID:nskrypnik,项目名称:moonrabbit,代码行数:9,代码来源:resources.py

示例2: Lamp

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
class Lamp(Widget):
    # Base variables
    TEXTURE = ObjectProperty(None)

    WIDTH = NumericProperty(1.0)
    HEIGHT = NumericProperty(1.0)

    X_UNIT = NumericProperty(1.0)
    Y_UNIT = NumericProperty(1.0)

    X = NumericProperty(1.0)
    Y = NumericProperty(1.0)

    # Run variables
    state = NumericProperty(1)

    xUnit = NumericProperty(1.0)
    yUnit = NumericProperty(1.0)

    curr_texture = ObjectProperty(None)

    x = NumericProperty(1.0)
    y = NumericProperty(1.0)

    def set_base(self, texture_dir, x, y):
        self.TEXTURE = Image(texture_dir).texture

        self.WIDTH = self.TEXTURE.width
        self.HEIGHT = self.TEXTURE.height

        self.X_UNIT = self.WIDTH / 3
        self.Y_UNIT = self.HEIGHT / 1

        self.X = x
        self.Y = y

    def reset(self):
        state = 1

    def is_pressed(self, x, y):
        if x > self.x and y > self.y:
            if x < self.x + self.xUnit and y < self.y + self.yUnit:
                return True
        return False

    def change_state(self):
        self.state += 1
        self.state %= 3

    def update(self, xScale, yScale):
        self.xUnit = self.X_UNIT * xScale
        self.yUnit = self.Y_UNIT * yScale

        self.x = self.X * xScale
        self.y = self.Y * yScale

        self.curr_texture = self.TEXTURE.get_region(self.state * self.X_UNIT, 0, self.X_UNIT, self.Y_UNIT)
开发者ID:nashr,项目名称:The-Rooms,代码行数:59,代码来源:view.py

示例3: loadTileImages

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
    def loadTileImages(self, ts):
        """
        Loads the images in filename into Kivy Images.
        This is a port of the code here: https://github.com/bitcraft/PyTMX/blob/master/pytmx/tmxloader.py

        :type ts: pytmx.TiledTileset
        """
        tile_image_path = self.map_dir + '/' + ts.source
        Logger.debug('KivyTiledMap: loading tile image at {}'.format(tile_image_path))
        texture = CoreImage(tile_image_path).texture

        ts.width, ts.height = texture.size
        tilewidth = ts.tilewidth + ts.spacing
        tileheight = ts.tileheight + ts.spacing
        Logger.debug('KivyTiledMap: TiledTileSet: {}x{} with {}x{} tiles'.format(ts.width, ts.height, tilewidth, tileheight))

        # some tileset images may be slightly larger than the tile area
        # ie: may include a banner, copyright, ect.  this compensates for that
        width = int((((ts.width - ts.margin * 2 + ts.spacing) / tilewidth) * tilewidth) - ts.spacing)
        height = int((((ts.height - ts.margin * 2 + ts.spacing) / tileheight) * tileheight) - ts.spacing)
        Logger.debug('KivyTiledMap: TiledTileSet: true size: {}x{}'.format(width, height))

        # initialize the image array
        Logger.debug('KivyTiledMap: initializing image array')
        self.images = [0] * self.maxgid

        p = itertools.product(
            xrange(ts.margin, height + ts.margin, tileheight),
            xrange(ts.margin, width + ts.margin, tilewidth)
        )

        # trim off any pixels on the right side that isn't a tile
        # this happens if extra graphics are included on the left, but they are not actually part of the tileset
        width -= (ts.width - ts.margin) % tilewidth

        for real_gid, (y, x) in enumerate(p, ts.firstgid):
            if x + ts.tilewidth - ts.spacing > width:
                continue

            gids = self.map_gid(real_gid)

            if gids:
                # invert y for OpenGL coordinates
                y = ts.height - y - ts.tileheight

                tile = texture.get_region(x, y, ts.tilewidth, ts.tileheight)

                for gid, flags in gids:
                    self.images[gid] = tile
开发者ID:PhoenixWright,项目名称:kivy-tiled,代码行数:51,代码来源:tiled.py

示例4: populate_lists

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
	def populate_lists(self):	
		for s in range(self.currentStory + 1):
			for l in range(len(self.renderList[s])):
				for i in range(self.iCount):
					for j in range(self.jCount):		
						tile = self.mapFile.stories[self.currentStory].matrix[i][j]
						type = tile.get_graphics_type(l)
						if type[0] != None:
							graphicsInfo = tile.graphics[l]
							image = Image(graphicsInfo[0]).texture
							x = (i - j) * self.tileWidth / 2 + self.offset[0] + self.jCount * self.tileWidth / 2 
							y = (i + j) * self.tileHeight / 2 + self.offset[1]
							if (type[0] == 'object' or type[0] == 'wall') and type[1] == False:
								# Object means a rectangle, not animated means it goes into renderList
								self.renderList[s][l][i][j] = Rectangle(texture = image.get_region(graphicsInfo[1][0][0][0], graphicsInfo[1][0][0][1], graphicsInfo[2][0], graphicsInfo[2][1]), 
																		size = (self.tileWidth, self.tileWidth * graphicsInfo[2][1] / graphicsInfo[2][0]), 
																		pos = (x - self.tileWidth / 2, y) )
开发者ID:Gimdal,项目名称:IsoMapMaker,代码行数:19,代码来源:canvas.py

示例5: render_tile

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
	def render_tile(self, i, j, layer, story):
		tile = self.mapFile.stories[self.currentStory].matrix[i][j]
		type = 	self.mapFile.stories[story].matrix[i][j].get_graphics_type(layer)
		if type[0] != None:
			graphicsInfo = tile.graphics[layer]
			image = Image(graphicsInfo[0]).texture
			x = (i - j) * self.tileWidth / 2 +  self.offset[0] + self.jCount * self.tileWidth/2 
			y = (i + j) * self.tileHeight / 2 + self.offset[1] 
			self.renderList[story][layer][i][j].texture =  image.get_region(graphicsInfo[1][0][0][0], graphicsInfo[1][0][0][1], graphicsInfo[2][0], graphicsInfo[2][1])
			print("Type is:", type[0])
			if type[0] == 'object'  and type[1] == False:
				# Object means a rectangle, not animated means it goes into renderList
				self.renderList[story][layer][i][j].size = (self.tileWidth, self.tileWidth * graphicsInfo[2][1] / graphicsInfo[2][0])
				self.renderList[story][layer][i][j].pos =  (x - self.tileWidth/2, y)
				self.canvas.before.add(Color(1, 1, 1, 1))
				for l in range(len(self.renderList[story])):
					if self.renderList[story][l][i][j] != [None]:
						self.canvas.before.add(self.renderList[story][l][i][j])
开发者ID:Gimdal,项目名称:IsoMapMaker,代码行数:20,代码来源:canvas.py

示例6: Navigator

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
class Navigator(Widget):
    # Base variables
    TEXTURE = ObjectProperty(None)

    WIDTH = NumericProperty(1.0)
    HEIGHT = NumericProperty(1.0)

    X_UNIT = NumericProperty(1.0)
    Y_UNIT = NumericProperty(1.0)

    X = NumericProperty(1.0)
    Y = NumericProperty(1.0)

    # Run variables
    angle = NumericProperty(0.0)

    xUnit = NumericProperty(1.0)
    yUnit = NumericProperty(1.0)

    curr_texture = ObjectProperty(None)

    x = NumericProperty(1.0)
    y = NumericProperty(1.0)

    def set_base(self, texture_dir, x, y):
        self.TEXTURE = Image(texture_dir).texture

        self.WIDTH = self.TEXTURE.width
        self.HEIGHT = self.TEXTURE.height

        self.X_UNIT = self.WIDTH / 1
        self.Y_UNIT = self.HEIGHT / 1

        self.X = x
        self.Y = y

    def update(self, xScale, yScale):
        self.xUnit = self.X_UNIT * xScale
        self.yUnit = self.Y_UNIT * yScale

        self.x = self.X * xScale
        self.y = self.Y * yScale

        self.curr_texture = self.TEXTURE.get_region(0, 0, self.X_UNIT, self.Y_UNIT)
开发者ID:nashr,项目名称:The-Rooms,代码行数:46,代码来源:view.py

示例7: Palette

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
class Palette(FloatLayout):
	def __init__(self, tileset = None, res = [64, 32], offset = 4, keyboard = None, mapCanvas = None, **kwargs):
		super(Palette, self).__init__(**kwargs)
		# Tileset is an path
		self.tileset = tileset
		# TilesetImage is the image file of the path
		self.tilesetImage = []
		self.imageRes = []
		# Palette dimensions
		self.offset = offset
		self.width = res[0] * 4 + self.offset * 2
		self.height = res[1] * 2 + self.offset * 2
		# Resolution for tiles in the palette. 
		self.res = res
		# Register which canvas is being painted on:
		self.mapCanvas = mapCanvas
		# Listen to keyboard changes:
		self.keyboard = keyboard
		# Bindings
		self.bind(on_touch_down = self.on_down)
		self.bind(on_touch_move = self.on_move)
		self.bind(on_touch_up = self.on_up)
		# Populate the palette
		self.populate_palette()
	
	def on_down(self, parent, touch):
		# Check if the touch-down position is within the palette:
		if touch.pos[0] > self.offset and touch.pos[0] < self.width - self.offset and touch.pos[1] > self.offset and touch.pos[1] < self.height - self.offset:
			self.mapCanvas.clear_palette_selection()
			yDiv = self.res[1] / self.res[0]
			#Convert the touch.pos arguments into the tile-number
			x = touch.pos[0] // (self.width / 4)
			y = touch.pos[1] // (self.width /  (4 / yDiv))
			# Highlight the tile.
			self.highlight(x, y)
			self.mapCanvas.selectedPaint = [self.tileset, [ [ [x * self.imageRes[0], y * self.imageRes[1] ] ] ], [self.imageRes[0], self.imageRes[1]] ]
		else:
			print("not touching the palette!")
		
		
	def on_move(self, parent, touch):
		pass
		
	def on_up(self, parent, touch):
		pass
		
	def highlight(self, x, y):
		yDiv = (self.res[1] / self.res[0])
		print(y)
		print(self.height)
		self.canvas.after.clear()
		with self.canvas.after:
			Color(0, 0.5, 1, 0.4)
			Rectangle(size = self.res, pos = (x * self.res[0] + self.offset, y * self.res[1] + self.offset))
		self.mapCanvas.selectedPaint = self.tilesetImage.get_region(x *  self.imageRes[0], y * self.imageRes[1], self.imageRes[0], self.imageRes[1] )	
		
	def populate_palette(self):
		if self.tileset != None:
			# Set image
			self.tilesetImage = Image(self.tileset).texture
			# Set background image:
			backgroundImagePath = join(globals.subDirectory['graphics'], "emptytile.png")
			backgroundImage = Image(backgroundImagePath).texture
			# Find the resolution of this image:
			yDiv = (self.res[1] / self.res[0]) / 4
			self.imageRes = [self.tilesetImage.width / 4 , self.tilesetImage.width * yDiv]
			# Set new dimensions
			self.width = self.res[0] * 4 + self.offset * 2
			self.height = self.res[1] * (self.tilesetImage.height / (self.tilesetImage.width * yDiv)) + self.offset * 2
			# Draw the background:
			with self.canvas.before:
				Color(1, 1, 1, 0.5)
				Rectangle(size = self.size, pos = (self.offset, self.offset))
			for x in range(4):
				for y in range(int(self.tilesetImage.height / (self.tilesetImage.width * yDiv))):
					with self.canvas.before:
						Color(1, 1, 1, 0.1)
						Rectangle(texture = backgroundImage, 
									size = self.res, 
									pos = (x * self.res[0] + self.offset, y * self.res[1] + self.offset ))
			# Draw the tileset in the palette
			for x in range(4):
				for y in range(int(self.tilesetImage.height / (self.tilesetImage.width * yDiv))):
					with self.canvas:
						Color(1, 1, 1, 1)
						Rectangle(texture = self.tilesetImage.get_region(x * self.imageRes[0], y * self.imageRes[1], self.imageRes[0], self.imageRes[1]), 
									size = self.res, 
									pos = (x * self.res[0] + self.offset, y * self.res[1] + self.offset ))		
开发者ID:Gimdal,项目名称:IsoMapMaker,代码行数:90,代码来源:palettes.py

示例8: Manager

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
class Manager(RelativeLayout):

    touchLocationScreen = ListProperty()
    touchLocationUI = ListProperty()
    infoText = StringProperty('adventure awaits!')
    screen = ObjectProperty()
    selected = BooleanProperty(False)
    selectedObj = ObjectProperty(None)
    items = ListProperty([]) # holds all on-screen items
    
    def __init__(self, **kwargs):
        super(Manager, self).__init__(**kwargs)
        self.buildUI()
        self.loadItemSheet()
        self.screen = self.screenManager.current_screen
        self.orientation = 'vertical'
    
    def loadItemSheet(self):
        self.itemSheet = CImage('assets/art/item_sheet.png').texture
    
    def on_screen(self, instance, value):
        '''
            on room change, inst. room items
            garbage collects all items not in inventory, and resets their spawn tag
        '''
        # cleanup
        db.execute('UPDATE Item SET Spawned = ? WHERE Inventory = ?', (False,False))
        db.commit()
        for i in self.items:
            self.remove_widget(i)
        self.items = []
        
        room = value.name
        print 'room changed to ',room
        self.retrieveItems(room)
        
    def retrieveItems(self,room):
        '''
            retrieve items from database relevant to new room
            ItemID=0, Holding=1, Room=2, X=3, Y=4, Inventory=5, Name=6, Spawned=7, Path=8
        '''
        i = db.execute('SELECT * FROM Item WHERE Room = ? OR Inventory = ?', (room,True))
        for e in i: 
            print e
            if e[7] and not e[5]:
                print '{} has spawned and is not an inventory item'.format(e[6])
            else:
                position = (e[3],e[4])
                print 'spawning {} at {}'.format(e[6],position)
                self.buildItem(position,e[6],e[8])
                
    def buildItem(self,position,item,path):
        '''
            populates screen with items for the room and inventory
            inventory slot positions: 1:(336.5,85.5), 2:(406.5,85.5), 3:(476.5,85.5), 
            4:(546.5,85.5), 5:(616.5,85.5), 6:(336.5,13.5), 7:(406.5,13.5), 8:(476.5,13.5), 
            9:(546.5,13.5), 0:(616.5,13.5),
        '''
        x,y,h,w = path.split(',')
        x,y,h,w = int(x),int(y),int(h),int(w)
        tex = self.itemSheet.get_region(x,y,h,w)
        i = Item(texture = tex, pos = position, name = item)
        
        self.add_widget(i)
        self.items.append(i)
        db.execute('UPDATE Item SET Spawned = 1 WHERE Name = ? ',(item,))
    
    def moveItem(self,item,inv=False):
        '''
            moves item to inventory or ground, and labels such in DB
        '''
        self.selected = False
        r = self.screen.name
        x = item.x
        y = item.y
        n = item.name
        print 'moving {} to {}'.format(n,(x,y))
        if inv:
            curs.execute('UPDATE Item SET Inventory=?, Room=?, X=?, Y=? WHERE Name = ? ',(True,None,x,y,n))
        else:
            curs.execute('UPDATE Item SET Inventory=?, Room=?, X=?, Y=? WHERE Name = ? ',(False,r,x,y,n))
        db.commit()
        
    def on_touch_down(self, value):
        '''
            looks for an item being selected, or moves player
        '''
        #print('value.pos: {} value.spos: {}'.format(value.pos, value.spos))
        x = int(value.pos[0])
        y = int(value.pos[1])
        
        # look for an item
        for i in self.items:
            if i.collide_point(x,y):
                self.selectedObj = i
                self.infoText = '{} picked up'.format(i.name)
                self.selected = True
                break
            else:
                self.selected = False
#.........这里部分代码省略.........
开发者ID:jonoco,项目名称:KivyKyra,代码行数:103,代码来源:main_bak.py

示例9: CoreImage

# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import get_region [as 别名]
from kivy.core.image import Image as CoreImage


forest_tiles = CoreImage('game-assets/tiles_forest.png').texture

TEX_GRASS = forest_tiles.get_region(16, 48, 16, 16)
TEX_TALLGRASS = forest_tiles.get_region(32, 48, 16, 16)
TEX_BUSH = forest_tiles.get_region(240, 48, 16, 16)
TEX_TREE = forest_tiles.get_region(240, 16, 16, 16)
TEX_BLANK = forest_tiles.get_region(240, 0, 16, 16)

if __name__ == "__main__":
    import cv2
    
    test = CoreImage(TEX_GRASS)
    test2 = CoreImage(TEX_GRASS)
    print test
开发者ID:facepalm,项目名称:diffusion-ville,代码行数:19,代码来源:assets.py


注:本文中的kivy.core.image.Image.get_region方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。