• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python graphics.Batch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyglet.graphics.Batch的典型用法代码示例。如果您正苦于以下问题:Python Batch类的具体用法?Python Batch怎么用?Python Batch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: Body

class Body(object):
    "A list of primitives. Creates a single batch to draw these primitives."
    def __init__(self, items=None):
        self.primitives = []
        if items:
            self.add_items(items)
        self.batch = None

    def add_items(self, items):
        "'items' may contain primitives and/or bodys"
        for item in items:
            if isinstance(item, Body):
                for prim in item.primitives:
                    self.primitives.append(prim)
            else:
                self.primitives.append(item)

    def batch_draw(self):
        if self.batch is None:
            self.batch = Batch()
            for primitive in self.primitives:
                batchVerts = \
                    [primitive.verts[0], primitive.verts[1]] + \
                    primitive.verts + \
                    [primitive.verts[-2], primitive.verts[-1]]
                numverts = len(batchVerts) / 2
                self.batch.add(
                        numverts,
                    primitive.primtype,
                    None, # draw order group to be implemented later
                    ('v2f/static', batchVerts),
                    ('c3B/static', primitive.color * numverts),
                    )
        self.batch.draw()
开发者ID:msarch,项目名称:py,代码行数:34,代码来源:shapes.py


示例2: SvgFiles

class SvgFiles(object):

    def __init__(self):
        datadir = join('solescion', 'geom', 'svgload', 'demodata')
        self.filenames = self.get_filenames(datadir)
        if len(self.filenames) == 0:
            raise Exception('no testdata svg files found')

        self.number = -1
        self.current = None
        self.next()

    def get_filenames(self, path):
        return [
            join(path, filename)
            for filename in listdir(path)
            if filename.endswith('.svg')
        ]

    def next(self):
        self.number = (self.number + 1) % len(self.filenames)
        filename = self.filenames[self.number]
        print filename
        self.current = SvgParser(filename)
        self.batch = Batch()
        self.current.add_to_batch(self.batch)

        glClearColor(
            uniform(0.0, 1.0),
            uniform(0.0, 1.0),
            uniform(0.0, 1.0),
            1.0)

    def draw(self):
        self.batch.draw()
开发者ID:tartley,项目名称:sole-scion,代码行数:35,代码来源:demo.py


示例3: cif_power_strip

def cif_power_strip(x, y, z, width=1, height=1, depth=1):
	batch = Batch()

	outlet = True
	for i in range(width):
		for j in range(height):
			for k in range(depth):
				if outlet:
					strip_texture = texture.textures['cif_power_strip']
				else:
					strip_texture = texture.textures['cif_power_outlet']

				outlet = not outlet

				tile = cube_tile.CubeTile((x+i, y+j, z+k), textures={
					'top':    texture.textures['cif_power_strip']['master_coordinates'],
					'right':  strip_texture['master_coordinates'],
					'bottom': texture.textures['cif_power_strip']['master_coordinates'],
					'left':   strip_texture['master_coordinates'],
					'front':  strip_texture['master_coordinates'],
					'back':   strip_texture['master_coordinates'],
				})
				vertex_list = tile.get_vertex_list()
				texture_list = tile.get_texture_list()
				vertices = len(vertex_list) / 3

				batch.add(vertices, GL_QUADS, texture.textures['master']['group'], ('v3f/static', vertex_list), ('t2f/static', texture_list))

	return batch
开发者ID:CIF-Rochester,项目名称:Basic-OpenGL-Seminar,代码行数:29,代码来源:power_strip.py


示例4: Test

class Test(cocos.scene.Scene):

    def __init__(self):
        super(Test, self).__init__()
        self.layer = cocos.layer.Layer()
        self.add(self.layer)
        self.batch = Batch()

        sprite = cocos.sprite.Sprite('fondo.png')
        sprite.position = -400, 480 - sprite.height / 2 - 50
        sprite.do(Repeat(MoveBy((20, 0), 1)))
        self.layer.add(sprite)

        sprite_2 = cocos.sprite.Sprite('fondo.png')
        sprite_2.position = 320, 100
        self.layer.add(sprite_2)
        self.sprite_2 = sprite_2
        self.x = -100.0
        self.schedule_interval(self.update, 1/20.0)

    def update(self, dt):
        self.x += dt * 20
        self.sprite_2.position = int(self.x), self.sprite_2.position[1]

    def draw(self):
        self.batch.draw()
开发者ID:hugoruscitti,项目名称:examplelab,代码行数:26,代码来源:test_blit_in_float_2.py


示例5: Shape

class Shape(object):
    '''
    A list of primitives
    '''
    def __init__(self, items=None):
        self.primitives = []
        if items:
            self.add_items(items)
        self.batch = None

    def add_items(self, items):
        "Add a list of primitives and shapes"
        for item in items:
            if isinstance(item, Shape):
                self.add_shape(item)
            else:
                self.primitives.append(item)

    def add_shape(self, other):
        "Add the primitives from a given shape"
        for prim in other.primitives:
            self.primitives.append(prim)

    def get_batch(self):
        if self.batch is None:
            self.batch = Batch()
            for prim in self.primitives:
                flatverts = prim.get_flat_verts()
                numverts = len(flatverts) / 2
                self.batch.add(
                    numverts,
                    prim.primtype,
                    None,
                    ('v2f/static', flatverts),
                    ('c3B/static', prim.color * numverts)
                )
        return self.batch

    def transform(self,M):
        """ applies matrix M to all self primitives
        """
        for prim in self.primitives:
            prim.transform(M)

    def get_aabb(self):
        aabb = namedtuple('AABB',['xmin','xmax','ymin','ymax'])
        _allx=[]
        _ally=[]
        for prim in self.primitives:
            for v in prim.verts:
                _allx.append(v[0])
                _ally.append(v[1])
        minx=min(_allx)
        miny=min(_ally)
        maxx=max(_allx)
        maxy=max(_ally)
        box = (minx,miny,maxx,maxy)
        return (box)
开发者ID:msarch,项目名称:py,代码行数:58,代码来源:shapes.py


示例6: Render

class Render(object):

    groups = [
        OrderedGroup(0), # sky
        OrderedGroup(1), # hills
        OrderedGroup(2), # birds & feathers
        OrderedGroup(3), # hud
    ]

    def __init__(self, game):
        self.game = game
        game.item_added += self.on_add_item
        game.item_removed += self.on_remove_item

        self.win = None

        self.clockDisplay = clock.ClockDisplay()
        self.batch = Batch()


    def assign_images_and_sizes(self, images):
        for klass in [Ground, Player, Enemy, Feather]:
            klass.images = images[klass.__name__]
            klass.width = klass.images[0].width
            klass.height = klass.images[0].height


    def init(self, win):
        self.win = win
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        graphics = Graphics()
        images = graphics.load()
        self.assign_images_and_sizes(images)

        win.on_draw = self.draw


    def draw(self):
        for item in self.game:
            if hasattr(item, 'animate'):
                item.animate()

        self.batch.draw()
        self.clockDisplay.draw()

        self.win.invalid = False


    def on_add_item(self, item):
        if hasattr(item, 'add_to_batch'):
            item.add_to_batch(self.batch, self.groups)


    def on_remove_item(self, item):
        if hasattr(item, 'remove_from_batch'):
            item.remove_from_batch(self.batch)
开发者ID:mjs,项目名称:brokenspell,代码行数:58,代码来源:render.py


示例7: __init__

    def __init__(self):
        """This is run when the game is created"""
        super(Game, self).__init__()

        # A handler that watches the keyboard state
        self.keyboard = key.KeyStateHandler()
        self.set_handlers(self.keyboard)

	#label for the pause menu
#	self.label = pyglet.text.Label

        # Create the sprites
        self.player = Player(self, self.keyboard, images['arch'], x=100, y=50)

        self.bullet_batch = Batch()
        self.bullets = []

	#background stars
	self.star_batch = Batch()
	self.stars = []
	
	self.fast_star_batch = Batch()
	self.fast_stars = []

	#windows enemies
	self.enemy_batch = Batch()
	self.win_enemy = [] 

        # Display the current FPS on screen
        self.fps_display = clock.ClockDisplay()

        clock.schedule_interval(self.update_bullets, 1/30.0)
        clock.schedule_interval(self.fire_bullets, 1/15.0)

	#update background 
	clock.schedule_interval(self.update_stars, 1/15.0)
	clock.schedule_interval(self.background_1, 1/10.0)
	clock.schedule_interval(self.update_back_stars, 1/30.0)
	clock.schedule_interval(self.background_2, 1/20.0 )

	time = random.uniform(2.0, 5.0)
	
	#update enemies
	clock.schedule_interval(self.update_enemy, 1/60.0)
	clock.schedule_interval(self.enemy, 1/time)

	#update enemy hit
	clock.schedule_interval(self.on_hit, 1/60.0)
	
	#check players health
	clock.schedule_interval(self.checkHealth, 1/60.0)

	#refreshes player info
	clock.schedule_interval(self.gui_update, 1/60.0)

	#update player hit
	clock.schedule_interval(self.on_hit_player, 1/59.0)
开发者ID:Goggles,项目名称:SideScroll,代码行数:57,代码来源:game.py


示例8: __init__

 def __init__(self):
     self.current_lists = {}
     self.old_lists = {}
     self.zone_size = 30.0
     self.patch_size = 0.5
     self.zone_x = None
     self.zone_z = None
     self.terrain_batch = Batch()
     self.sea_batch = Batch()
     self.tree_batch = Batch()
开发者ID:NixSilva,项目名称:lonely_islands_unlimited,代码行数:10,代码来源:world.py


示例9: OrbitingBody

class OrbitingBody(Body, metaclass=ABCMeta):
    """
    An orbiting body in the solarsystem
    """

    def __init__(self, parent, name, texturename, color, radius, orbit, axial_tilt, sidereal_rotation_period, mass, renderer=OrbitingBodyRenderer()):
        """
        Creates a new body with the given parameters

        :param parent: Parent body in the system
        :type parent: :class:`Body`, None
        :param name: Name of the body
        :type name: str
        :param texturename: Name of the texture
        :type texturename: str
        :param color: Dictionary with r, g and b values
        :type color: dict
        :param radius: Radius of the body
        :type radius: float
        :param orbit: Orbit of the body
        :type orbit: :class:`solarsystem.orbit.Orbit`
        :param axial_tilt: Axial Tilt in degrees
        :type axial_tilt: float
        :param sidereal_rotation_period: Rotation period (siderial) around its own axis
        :type sidereal_rotation_period: float
        """

        super().__init__(parent, name, texturename, color, radius, axial_tilt, sidereal_rotation_period, mass, renderer=renderer)
        self.orbit = orbit
        self.orbit.body = self
        self.orbit_line_batch = Batch()

    def post_init(self):
        self.orbit.post_init()

        # Plot the orbit to a pyglet batch for faster drawing
        orbit_line = []
        for pos in self.orbit.plot(plot_steps):
            orbit_line.append(pos.x)
            orbit_line.append(pos.y)
            orbit_line.append(pos.z)
        self.orbit_line_batch.add(int(len(orbit_line) / 3), GL_LINE_LOOP, None, ('v3f', tuple(orbit_line)))

    def update(self, time):
        """
        Update the body (Calculate current orbit position)

        :param time: Delta Time
        :type time: float
        """

        super().update(time)
        self.xyz = self.orbit.calculate(time)
        if self.parent:
            self.xyz += self.parent.xyz
开发者ID:JamesLinus,项目名称:solarsystem,代码行数:55,代码来源:body.py


示例10: update_batch

 def update_batch(self):
     self.terrain_batch = Batch()
     self.sea_batch = Batch()
     self.tree_batch = Batch()
     tmp_lists = self.current_lists.copy()
     for i in tmp_lists:
         l = tmp_lists[i]
         w2 = len(l[1]) / 3
         self.draw_sea(l, w2)
         self.draw_terrain(l, w2)
         self.draw_tree(l, w2)
开发者ID:NixSilva,项目名称:lonely_islands_unlimited,代码行数:11,代码来源:world.py


示例11: Map

class Map(object):
	LAYERS = {
		'soil': OrderedGroup(0),
		'ground': OrderedGroup(1),
		'bodies': OrderedGroup(2),
		'trees': OrderedGroup(3),
		'berries': OrderedGroup(4)
	}

	def __init__(self, width, height):
		self.width = width
		self.height = height
		self._map = Batch()
		self._create()
		self._add_hero()
		self._add_lost()


	def _create(self):
		for x in range(0, self.width, Soil.size()[0]):
			for y in range(0, self.height, Soil.size()[1]):
				soil = Soil(x, y)
				self.add(soil)
				try:
					soil.grow(self, x, y)
				except NotFertileError as e:
					logger.debug(str(e))

	def add(self, thing):
		thing.vertex_list = self._map.add(
			len(thing.vertices) // 2,
			GL_QUADS,
			self.LAYERS[thing.LAYER],
			('v2i/dynamic', thing.vertices),
			('c4B/static', thing.colors)
		)
		return thing.vertex_list

	def _add_body(self, body_name, kind):
		body = getattr(things, body_name)(*START_POS[kind])
		setattr(self, kind, body)
		self.add(body)
		return body

	@info("Adding {}".format(BODY_HERO))
	def _add_hero(self):
		self._add_body(BODY_HERO, 'hero')

	@info("Hiding {}".format(BODY_LOST))
	def _add_lost(self):
		self._add_body(BODY_LOST, 'lost') # keep a list of every tree to hide him

	def draw(self):
		self._map.draw()
开发者ID:evuez,项目名称:distress,代码行数:54,代码来源:tiles.py


示例12: DinamicObj

class DinamicObj(Importer):

    def __init__(self, *args, **kwargs):
        self.batch = Batch()
        super(DinamicObj, self).__init__(*args, **kwargs)

    def draw_faces(self):
        glPushMatrix()
        glTranslatef(self.x, self.y, self.z)
        glScalef(self.scale, self.height, self.thickness)
        self.batch.draw()
        glPopMatrix()
开发者ID:arksega,项目名称:BookieMonster,代码行数:12,代码来源:grid.py


示例13: Body

class Body(object):
    "A list of shapes. Creates a single batch to draw these shapes."
    __metaclass__ = IterRegistry
    _registry = []
    def __init__(self,items=None,anchor=[0,0],angle=0,drawable=True):
        self.shapes = []
        self._registry.append(self)
        self.body=body
        self.anchor=anchor
        self.angle=angle
        self.drawable=drawable
        if items:
            self.add_items(items)
        self.batch = None

    def add_items(self, items):
        "'items' may contain shapes and/or bodies"
        for item in items:
            if isinstance(item, Body):
                for shp in item.shapes:
                    self.shapes.append(shp)
            else:
                self.shapes.append(item)

    def batch_draw(self):
        if self.batch is None:
            self.batch = Batch()
            for shape in self.shapes:
                batchVerts = \
                    [shape.verts[0], shape.verts[1]] + \
                    shape.verts + \
                    [shape.verts[-2], shape.verts[-1]]
                numverts = len(batchVerts) / 2
                self.batch.add(
                        numverts,
                    shape.primtype,
                    None, # draw order group to be implemented later
                    ('v2f/static', batchVerts),
                    ('c3B/static', shape.color * numverts),
                    )
        self.batch.draw()



    def paint_all():
        for z in Zulu:
            glPushMatrix()
            glTranslatef(z.anchor[0],z.anchor[1],0)   # Move bac
            glRotatef(z.angle, 0, 0, 1)
            z.body.batch_draw()
            glPopMatrix()
开发者ID:msarch,项目名称:py,代码行数:51,代码来源:shapes.py


示例14: OrbitalObject

class OrbitalObject(AstronomicalObject):
    """
    An astronomical Object which moves around another
    """

    def __init__(self, parent, name, texture_name, radius, axial_tilt, sidereal_rotation_period, mass, orbit,
                 renderer=AOOrbitingRenderer()):
        """
        Create a new orbiting astronomical Object

        :param parent: The objects parent (i.e. Sun for Earth)
        :param name: Name of the object (Earth, Saturn, Pluto, ...)
        :param texture_name: Name of the texture in the `res` directory
        :param radius: Radius of object
        :param axial_tilt: In astronomy, axial tilt is the angle between a planet's rotational axis at
        its north pole and a line perpendicular to the orbital plane of the planet - given in degrees.
        :param sidereal_rotation_period: The time required (in days) for a body within the solar system to complete
        one revolution with respect to the fixed stars—i.e., as observed from some fixed point outside the system.
        :param mass: Mass of the object in kilograms
        :param orbit: Orbit Class of this body
        """

        super().__init__(parent, name, texture_name, radius, axial_tilt, sidereal_rotation_period, mass,
                         renderer=renderer)
        self.orbit = orbit
        self.orbit.body = self
        self.orbit_line_batch = Batch()

    def config(self):
        """
        Configure the Object
        """

        self.orbit.config()
        orbit_line = []
        for pos in self.orbit.pos(1024):
            orbit_line.append(pos.x)
            orbit_line.append(pos.y)
            orbit_line.append(pos.z)
        self.orbit_line_batch.add(int(len(orbit_line) / 3), GL_LINE_LOOP, None, ('v3f', tuple(orbit_line)))

    def update(self, time):
        """
        Update the time in the solar system and
        position the object on its right coordinates

        :param time: Current solar time
        """

        super().update(time)
        self.xyz = self.orbit.calculate(time)
开发者ID:dmelichar-tgm,项目名称:solarsystem,代码行数:51,代码来源:AstronomicalObjects.py


示例15: Log

class Log(object):
	GROUPS = {
		'text_bac'
	}

	def __init__(self, width, height, x, y, queue):
		self.width = width
		self.height = height
		self._log = Batch()
		self._create(x, y)
		self.queue = queue

	def _create(self, x, y):
		self._title = Label(
			"_______________ LOG _______________",
			x=x,
			y=y + self.height + 5,
			height=20,
			batch=self._log
		)
		self._doc = decode_text("\n")
		self._doc.set_style(0, 0, dict(color=(255, 255, 255, 255)))

		self._box = ScrollableTextLayout(
			self._doc, self.width, self.height,
			multiline=True, batch=self._log
		)
		self._box.x = x
		self._box.y = y

	def draw(self):
		self._log.draw()

	def insert(self, message):
		self._doc.insert_text(-1, message + "\n")
		self._box.view_y = -self._box.content_height

	def scroll(self, height):
		self._box.view_y += height

	def start(self):
		schedule_interval(self.update, 0.3)

	def update(self, dt):
		try:
			item = self.queue.popleft()
			self.insert(item['message'])
		except IndexError:
			pass
开发者ID:evuez,项目名称:distress,代码行数:49,代码来源:tiles.py


示例16: __init__

	def __init__(self, width, height):
		self.width = width
		self.height = height
		self._map = Batch()
		self._create()
		self._add_hero()
		self._add_lost()
开发者ID:evuez,项目名称:distress,代码行数:7,代码来源:tiles.py


示例17: __init__

 def __init__(self):
     self._batch = Batch()
     self.tile_images = []
     self.tiles = []
     self.tile_width = 0
     self.tile_height = 0
     self.camera_position = Vector()
开发者ID:ceronman,项目名称:prisionescape,代码行数:7,代码来源:tilemap.py


示例18: __init__

    def __init__(self, parent, name, texturename, color, radius, orbit, axial_tilt, sidereal_rotation_period, mass, renderer=OrbitingBodyRenderer()):
        """
        Creates a new body with the given parameters

        :param parent: Parent body in the system
        :type parent: :class:`Body`, None
        :param name: Name of the body
        :type name: str
        :param texturename: Name of the texture
        :type texturename: str
        :param color: Dictionary with r, g and b values
        :type color: dict
        :param radius: Radius of the body
        :type radius: float
        :param orbit: Orbit of the body
        :type orbit: :class:`solarsystem.orbit.Orbit`
        :param axial_tilt: Axial Tilt in degrees
        :type axial_tilt: float
        :param sidereal_rotation_period: Rotation period (siderial) around its own axis
        :type sidereal_rotation_period: float
        """

        super().__init__(parent, name, texturename, color, radius, axial_tilt, sidereal_rotation_period, mass, renderer=renderer)
        self.orbit = orbit
        self.orbit.body = self
        self.orbit_line_batch = Batch()
开发者ID:JamesLinus,项目名称:solarsystem,代码行数:26,代码来源:body.py


示例19: __init__

 def __init__(self, board, player, x, y, direction):
     self.board = weakref.proxy(board)
     self.player = player  # TODO: weakref?
     # place the piece on the board
     self.position = Vector3(x - 3.5, y - 3.5, 0)
     # load the model
     # TODO: Cached loading
     model_filename = 'skins/pieces/default/models/player{}/{}.obj'.format(
         self.player.player_index, self.__class__.__name__)
     self._obj = OBJ(model_filename,
                     texture_path='skins/pieces/default/textures/')
     self.batch = Batch()
     self._obj.add_to(self.batch)
     # set the rotation
     self.direction = direction
     self.old_direction = self.direction
     # TODO: is angle necessary anymore?
     self.angle = (self.direction.angle(X_AXIS)*180/math.pi -
                   self.rotation_offset)
     # generate a color key
     # TODO: Ensure this *never* collides (it definitely has a chance)
     self.color_key = (randint(1, 254) / 255.,
                       randint(1, 254) / 255.,
                       randint(1, 254) / 255.)
     self._color_key_processed = [int(round(_*255)) for _ in self.color_key]
     # set remaining_move to speed
     self.remaining_move = self.speed
开发者ID:pennomi,项目名称:banneret,代码行数:27,代码来源:pieces.py


示例20: __init__

	def __init__(self, tilemap):
		self.tilemap = tilemap
		self.batch = Batch()
		
		self.layerviews = [LayerView(self, layer) for layer in tilemap.layers]
		
		self.refresh()
开发者ID:josch,项目名称:heroes-rebirth,代码行数:7,代码来源:tilemap.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vertexbuffer.create_mappable_buffer函数代码示例发布时间:2022-05-25
下一篇:
Python wgl_info.have_extension函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap