def get_white_texture(): """Get a white texture, useful if a material does not provide a texture.""" global white if white is None: fill = SolidColorImagePattern((255, 255, 255, 255)) white = fill.create_image(1, 1).get_texture() return white
def setUp(self): self.w = Window(width=1, height=1, visible=False) self.s = Sprite( 10, 10, 10, 10, Image2d.from_image( SolidColorImagePattern((0, 0, 0, 0)).create_image(1, 1))) assert (self.s.x, self.s.y) == (10, 10)
def _draw_overlay(self): pattern = SolidColorImagePattern((0, 0, 0, 200)) overlay_image = pattern.create_image(1000, 1000) overlay_image.anchor_x = overlay_image.width / 2 overlay_image.anchor_y = overlay_image.height / 2 overlay = Sprite(overlay_image, self.camera.x, self.camera.y) overlay.draw()
def _render_solid_colors(self, surface): black = pyglet.image.create( width=self.game.WIDTH, height=self.game.HEIGHT, pattern=SolidColorImagePattern(color=(0, 0, 0, 0xff))) offset = self.OFFSET black.blit_to_texture(surface.get_texture().target, 0, offset, self.SCREEN_HEIGHT - self.game.HEIGHT - offset, 0)
def _draw_action_menu(self): pattern = SolidColorImagePattern((0, 0, 150, 200)) overlay_image = pattern.create_image(1000, 200) overlay_image.anchor_x = overlay_image.width / 2 overlay_image.anchor_y = overlay_image.height + 100 overlay = Sprite(overlay_image, self.camera.x, self.camera.y) overlay.draw() self._generate_text()
def bake_static_background(self): surface = pyglet.image.create( width=self.SCREEN_WIDTH, height=self.SCREEN_HEIGHT, pattern=SolidColorImagePattern(color=(0x5f, 0x57, 0x4f, 0xff))) self._render_solid_colors(surface) self._render_walls(surface) self._render_coins(surface) self.background = surface
def getPygeltColorMaps(step, height=1080, width=1440, suffix=""): """Return colormap in pyglet.image.""" colormap = {} source = generateColorMapName(step) for name, array in source: r, g, b = [i if i < 256 else 255 for i in array] a = 255 thename = name + suffix colormap[thename] = SolidColorImagePattern( (r, g, b, a)).create_image(width=width, height=height) source = [("white", (255, 255, 255)), ("black", (0, 0, 0))] for name, array in source: r, g, b = [i if i < 256 else 255 for i in array] a = 255 colormap[name] = SolidColorImagePattern( (r, g, b, a)).create_image(width=1280, height=1080) logger.debug("generate colors: " + colormap.keys().__str__()) return colormap
def generatePygletBWMap(height=1280, width=1024, L=50): """Generate image with a given function.""" colormap = {} source = [("white", (255, 255, 255, 255)), ("black", (0, 0, 0, 255)), ("gray", (128, 128, 128, 255))] for name, array in source: r, g, b, a = array colormap[name] = SolidColorImagePattern((r, g, b, a)).create_image( width=width+2*L, height=height+2*L) return colormap # {name: (image, speed)}
def getPygeltColorMaps(colornamefile, screensize=(1920, 1080, 3)): """Return colormap in pyglet.image.""" with open(colornamefile, 'r') as f: content = f.read() logger.debug("read colormap file: " + colornamefile) colormap = {} for name, array in json.loads(content).items(): r, g, b = array a = 255 colormap[name] = SolidColorImagePattern((r, g, b, a)).create_image( width=screensize[0], height=screensize[1]) logger.debug("generate colors: " + colormap.keys().__str__()) return colormap
def __init__(self, tex_name, tile_width, tile_height, game_state, xpos=0, ypos=0, group=None, health=3, move_pattern=unlucky, move_params=(), name='enemy', gold=1, exp=1, hitsound='bandit_hit', damage=1): super().__init__(tex_name, tile_width, tile_height, game_state, xpos=xpos, ypos=ypos, group=group, damage=damage, health=health, name=name, hitsound=hitsound) self.is_guard = 'guard' in tex_name if type(move_pattern) == str: self.move_pattern = patterns[move_pattern](self, *move_params) else: self.move_pattern = move_pattern(self, *move_params) self.game.enemies.add(self) self.stats[G] = gold self.stats[EXP] = exp self.healthbar = Sprite(create(24, 4, SolidColorImagePattern(RED)), x=self.x, y=self.y, batch=self.batch, group=self.game.groups[1])
from pyglet import resource, font from pyglet.image import SolidColorImagePattern # Make our resource imports relative to the src/resources/ directory. resource.path = ['resources'] resource.reindex() def _set_anchor_center(img): """Centers the anchor point of img.""" img.anchor_x = int(img.width / 2) img.anchor_y = int(img.height / 2) player_image = SolidColorImagePattern( (255, 255, 255, 255)).create_image(32, 32) _set_anchor_center(player_image) enemy_pawn_image = resource.image('enemy/pawn.png') _set_anchor_center(enemy_pawn_image) enemy_slider_image = resource.image('enemy/slider.png') _set_anchor_center(enemy_slider_image) pellet_image = resource.image('pellet.png') _set_anchor_center(pellet_image) danger_image = resource.image('danger.png') _set_anchor_center(danger_image) resource.add_font('m5x7.ttf')
else: p3 = Position(0, 0) p4 = other.get_size() if p2.x > p3.x and p4.x > p1.x and p2.y > p3.y and p4.y > p1.y: if fully: if (p2.x >= p4.x and p2.y >= p4.y and p3.x >= p1.x and p3.y >= p1.y or p4.x >= p2.x and p4.y >= p2.y and p1.x >= p3.x and p1.y >= p3.y): return True return False return True return False # make the apple apple_img = SolidColorImagePattern((0, 255, 0, 255)).create_image(10, 10) # round the apple with PixelArray(apple_img) as apple_array: apple_array[0:3, 0] = (0, 0, 0, 0) apple_array[0:2, 1] = (0, 0, 0, 0) apple_array[0, 2] = (0, 0, 0, 0) apple_array[7:10, 0] = (0, 0, 0, 0) apple_array[8:10, 1] = (0, 0, 0, 0) apple_array[9:10, 2] = (0, 0, 0, 0) apple_array[0, 7] = (0, 0, 0, 0) apple_array[0:2, 8] = (0, 0, 0, 0) apple_array[0:3, 9] = (0, 0, 0, 0) apple_array[9, 7] = (0, 0, 0, 0) apple_array[8:10, 8] = (0, 0, 0, 0) apple_array[7:10, 9] = (0, 0, 0, 0) # center the apple