本文整理汇总了Python中pygame.Surface.blit方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.blit方法的具体用法?Python Surface.blit怎么用?Python Surface.blit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.blit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_raw_shadow
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def _get_raw_shadow(self):
target_img = self.target.get_image(self.capture_state)
r = target_img.get_rect()
#the shadow will be larger in order to make free space for fadeout.
r.inflate_ip(2*self.shadow_radius, 2*self.shadow_radius)
img = Surface(r.size)
img.fill((255, 255, 255, 255))
img.blit(target_img, (self.shadow_radius, self.shadow_radius))
if self.sun_angle <= 0.:
raise Exception("Sun angle must be greater than zero.")
elif self.sun_angle != 45. and self.vertical:
w, h = img.get_size()
new_h = h / tan(self.sun_angle * pi / 180.)
screen_size = functions.get_screen().get_size()
new_h = abs(int(min(new_h, max(screen_size))))
img = scale(img, (w, new_h))
if self.angle_mode == "flip":
img = flip(img, self.mode_value[0], self.mode_value[1])
elif self.angle_mode == "rotate":
img = rotate(img, self.mode_value)
else:
raise Exception("angle_mode not available: " + str(self.angle_mode))
shadow = pilgraphics.get_shadow(img,
radius=self.shadow_radius,
black=self.black,
alpha_factor=self.alpha_factor,
decay_mode=self.decay_mode,
color=self.color)
return shadow
示例2: draw_equipment_item
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def draw_equipment_item(self, pane):
equip_item_pane = Surface((EQUIPMENT_ITEM_WIDTH, EQUIPMENT_ITEM_HEIGHT))
self.draw_border(equip_item_pane)
items = []
equipment = self.player.inventory.items_of_type(Equipment)
current_equipment = self.selected_party_member.equipment_set.equipment
for e in equipment:
if not e.equippable_in_slot(self.selected_equip_slot): continue
if self.selected_party_member.party_class not in e.compatible_classes: continue
if e.equipped and not e in current_equipment.values(): continue
if self.selected_equip_slot == "left_hand" and e.equipped and e.equip_slot != self.selected_equip_slot and not e.left_equipped: continue
if self.selected_equip_slot == "right_hand" and e.equipped and e.left_equipped: continue
items.append(e)
self.current_equip_items = items
page_index = self.equipment_item_index/EQUIPMENT_PAGE_SIZE
start = page_index*EQUIPMENT_PAGE_SIZE
end = min(len(items), start + EQUIPMENT_PAGE_SIZE)
for i in range(start, end):
item = items[i]
text = item.name
if item.equipped: text += item.equip_tag()
text_image = self.ui_font.render(text, True, WHITE)
equip_item_pane.blit(text_image, (28, 8 + 40*(i%EQUIPMENT_PAGE_SIZE)))
index = self.equipment_item_index%EQUIPMENT_PAGE_SIZE
self.draw_pane_pointer(equip_item_pane, index)
# TODO: multiple pages of equipment. Navigate w/ left and right arrow keys
self.draw_equipment_page_numbers(equip_item_pane)
pane.blit(equip_item_pane, (EQUIPMENT_ITEM_X, EQUIPMENT_ITEM_Y))
示例3: get_surface
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def get_surface(self):
W, H = functions.get_screen_size()
if isinstance(self.img_path, str): # load image
surface = load_image(self.img_path)
else: # take image
surface = self.img_path
if 0 < self.alpha < 255:
surface.set_alpha(self.alpha, RLEACCEL)
if self.mode == "scale to screen":
surface = scale(surface, (W, H))
self.size = (W, H)
elif self.mode == "cut to screen":
new_surface = Surface((W, H))
new_surface.blit(surface, (0, 0))
self.size = (W, H)
elif self._resized:
surface = scale(surface, self._resized)
elif self.mode:
functions.debug_msg("Unrecognized mode : ", self.mode)
## elif self._resized:
## surface = scale(surface, self._resized)
if self.colorkey:
surface.set_colorkey(self.colorkey, RLEACCEL)
surface.set_clip(self.clip)
if self.alpha < 255:
return surface.convert_alpha()
else:
return surface.convert()
示例4: Coche
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
class Coche(Rect):
coche0 = image.load(os.path.join(imagesrep,'button0.png'))
coche1 = image.load(os.path.join(imagesrep,'button1.png'))
font = font.Font(os.path.join(thisrep,'MonospaceTypewriter.ttf'),8)
def __init__(self,label='',fgcolor=(255,255,255),font=None):
if not font: font = Coche.font
Rect.__init__(self,Coche.coche0.get_rect())
self.scr = display.get_surface()
self.status = False
label = Coche.font.render(label,1,fgcolor)
Rlabel = label.get_rect()
Rlabel.midleft = self.midright
self.label = Surface(self.union(Rlabel).size,SRCALPHA)
self.label.blit(label,Rlabel)
def update(self,ev):
if ev.type == MOUSEBUTTONUP and self.collidepoint(ev.pos):
self.status ^= 1
return True
def screen(self):
self.scr.blit(Coche.coche1 if self.status else Coche.coche0,self)
self.scr.blit(self.label,self)
示例5: main
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def main(self, screen):
clock = pygame.time.Clock()
background = Surface(screen.get_size())
background.blit(construct_nightmare(background.get_size()), (0, 0))
self.matris = Matris()
matris_border = Surface((MATRIX_WIDTH * BLOCKSIZE + BORDERWIDTH * 2,
VISIBLE_MATRIX_HEIGHT * BLOCKSIZE + BORDERWIDTH * 2))
matris_border.fill(BORDERCOLOR)
while 1:
dt = clock.tick(45)
self.matris.update((dt / 1000.) if not self.matris.paused else 0)
if self.matris.gameover:
return
tricky_centerx = WIDTH - (WIDTH - (MATRIS_OFFSET + BLOCKSIZE *
MATRIX_WIDTH + BORDERWIDTH * 2)) / 2
background.blit(matris_border, (MATRIS_OFFSET, MATRIS_OFFSET))
background.blit(self.matris.surface, (MATRIS_OFFSET + BORDERWIDTH,
MATRIS_OFFSET + BORDERWIDTH))
nextts = self.next_tetromino_surf(self.matris.surface_of_next_tetromino)
background.blit(nextts, nextts.get_rect(top = MATRIS_OFFSET,
centerx = tricky_centerx))
infos = self.info_surf()
background.blit(infos, infos.get_rect(bottom = HEIGHT - MATRIS_OFFSET,
centerx = tricky_centerx))
screen.blit(background, (0, 0))
pygame.display.flip()
示例6: join_files
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def join_files(target, sources, images_per_line):
lines = len(sources) / images_per_line
if len(sources) % images_per_line != 0:
lines += 1
first = pygame.image.load(sources[0])
w, h = first.get_width(), first.get_height()
result = Surface((w * images_per_line, h * lines)).convert_alpha()
result.fill((255, 255, 255, 0))
for i, source in enumerate(sources):
im = pygame.image.load(source)
im.convert_alpha()
if im.get_width() != w or im.get_height() != h:
print 'Image %s is not of the same size as the first'
exit()
x = w * (i % images_per_line)
y = h * (i / images_per_line)
result.blit(im, (x, y))
# bg = Surface((640, 480), depth=32)
# bg.convert_alpha()
# bg.fill((255, 0, 0))
# bg.blit(result, (0, 0))
# d.blit(bg, (0, 0))
# pygame.display.flip()
# raw_input()
pygame.image.save(result, target)
示例7: create_tag_image
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def create_tag_image(
tags,
output,
size=(500,500),
background=(255, 255, 255),
layout=LAYOUT_MIX,
fontname=DEFAULT_FONT,
rectangular=False):
"""
Create a png tag cloud image
"""
if not len(tags):
return
sizeRect, tag_store = _draw_cloud(tags,
layout,
size=size,
fontname=fontname,
rectangular=rectangular)
image_surface = Surface((sizeRect.w, sizeRect.h), SRCALPHA, 32)
image_surface.fill(background)
for tag in tag_store:
image_surface.blit(tag.image, tag.rect)
pygame.image.save(image_surface, output)
示例8: create_tag_image
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def create_tag_image(
tags,
file,
size=(800, 600),
background=(255, 255, 255),
layout=LAYOUT_MIX,
crop=True,
fontname=DEFAULT_FONT,
palette=DEFAULT_PALETTE,
fontzoom=2,
rectangular=False):
"""
Create a png tag cloud image
"""
image_surface = Surface(size, SRCALPHA, 32)
image_surface.fill(background)
tag_store = _draw_cloud(tags, image_surface, layout, fontname=fontname, palette=palette, fontzoom=fontzoom, rectangular=rectangular)
if crop:
boundingRect = _get_group_bounding(tag_store, size)
crop_surface = Surface((boundingRect.width, boundingRect.height), pygame.SRCALPHA, 32)
crop_surface.blit(image_surface, (0, 0), area=boundingRect)
pygame.image.save(crop_surface, file)
else:
pygame.image.save(image_surface, file)
示例9: reset_screen
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def reset_screen(img_file=None, color=BACKGROUND_COLOR):
# Test display
if not pyg.display.get_init():
pyg.init()
# Init screen
flag = pyg.FULLSCREEN #| pyg.DOUBLEBUF | pyg.HWSURFACE
flag *= Constants.FULLSCREEN
flag |= pyg.NOFRAME * NOFRAME
screen = pyg.display.set_mode(WINDOW_SIZE, flag)
ico = load_image(ICON_FILE).convert_alpha()
pyg.display.set_icon(ico)
pyg.display.set_caption(WINDOW_TITLE)
# Build background
background = Surface(WINDOW_SIZE)
background.fill(color)
# Get background
if isinstance(img_file, basestring):
image = load_image(img_file).convert_alpha()
width = int(WINDOW_WIDTH * REDUCE_FACTOR)
height = int(WINDOW_HEIGHT *REDUCE_FACTOR)
image = pyg.transform.smoothscale(image, (width,height))
center = WINDOW_WIDTH/2, WINDOW_HEIGHT/2
background.blit(image, image.get_rect(center=center))
# Apply background
screen.blit(background, background.get_rect())
pyg.display.flip()
# Return screen
return screen, background
示例10: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def __init__(self, tag, initial_position, rotation=0, fontname=DEFAULT_FONT, fontzoom=5):
Sprite.__init__(self)
self.tag = copy(tag)
self.rotation = rotation
font_spec = load_font(fontname)
#fonter = font.Font(os.path.join(FONT_DIR, font_spec['ttf']), int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
# changing to allow for arbitrary local fonts
fonter = font.Font(font_spec['ttf'], int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
self.tag['size'] *= fontzoom
fonter = transform.rotate(fonter, rotation)
frect = fonter.get_bounding_rect()
frect.x = -frect.x
frect.y = -frect.y
self.fontoffset = (-frect.x, -frect.y)
font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
font_sf.blit(fonter, frect)
self.image = font_sf
self.rect = font_sf.get_rect()
self.rect.width += TAG_PADDING
self.rect.height += TAG_PADDING
self.rect.x = initial_position[0]
self.rect.y = initial_position[1]
self.mask = mask.from_surface(self.image)
self.mask = self.mask.convolve(CONVMASK, None, (TAG_PADDING, TAG_PADDING))
示例11: create_tag_image
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def create_tag_image(
tags,
output,
size=(500,500),
background=(255, 255, 255),
layout=LAYOUT_MIX,
fontname=DEFAULT_FONT,
rectangular=False):
"""
Create a png tag cloud image
"""
if not len(tags):
return
sizeRect, tag_store = _draw_cloud(tags,
layout,
size=size,
fontname=fontname,
rectangular=rectangular)
if type(output) == pygame.Surface:
image_surface = output
else:
image_surface = Surface((sizeRect.w + 2*TAG_CLOUD_PADDING, sizeRect.h + 2*TAG_CLOUD_PADDING), SRCALPHA, 32)
image_surface.fill(background)
for tag in tag_store:
image_surface.blit(tag.image, (tag.rect.x - sizeRect.x + TAG_CLOUD_PADDING, tag.rect.y - sizeRect.y + TAG_CLOUD_PADDING))
pygame.image.save(image_surface, output)
示例12: make_background
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def make_background(self,img_file,desktop_size):
in_img = image.load(img_file)
out_img = Surface(desktop_size)
for x in range((out_img.get_width() // in_img.get_width()) + 1):
for y in range((out_img.get_height() // in_img.get_height()) + 1):
out_img.blit(in_img, (in_img.get_width() * x, in_img.get_height() * y))
return out_img
示例13: set_alpha_from_intensity
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def set_alpha_from_intensity(surface, alpha_factor, decay_mode, color):
if not HAS_PIL:
raise Exception("PIL was not found on this machine.")
if not HAS_NUMPY:
raise Exception("NumPy was not found on this machine.")
rect = surface.get_rect()
newsurf = Surface(rect.size, SRCALPHA, depth=surface.get_bitsize())
newsurf = newsurf.convert_alpha()
newsurf.blit(surface, (0, 0))
arrayrgb = surfarray.pixels3d(newsurf)
arraya = surfarray.pixels_alpha(newsurf)
bulk_color = tuple(color)
for x in range(rect.left, rect.right):
for y in range(rect.top, rect.bottom):
color = tuple(arrayrgb[x][y])
light = square_color_norm(color)
alpha = float(light)/MAX_NORM * 255
arrayrgb[x][y][0] = bulk_color[0]
arrayrgb[x][y][1] = bulk_color[1]
arrayrgb[x][y][2] = bulk_color[2]
if decay_mode == "linear":
actual_alpha = int(255 - alpha)
elif decay_mode == "exponential":
tuning_factor = 1.03
actual_alpha = int(255*tuning_factor**-alpha)
## elif decay_mode == "quadratic":
## pass
else:
raise Exception("decay_mode not recognized: " + decay_mode)
actual_alpha *= alpha_factor
arraya[x][y] = actual_alpha
return newsurf
示例14: create_dialog
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def create_dialog(self):
f = font.Font(font.get_default_font(), 30)
text = f.render(self.text, True, (255, 255, 255))
dialog = Surface((text.get_width() + 20, text.get_height() + 20))
self.stroke(dialog, (255, 0, 0))
dialog.blit(text, ((dialog.get_width() - text.get_width()) / 2, (dialog.get_height() - text.get_height()) / 2))
return dialog
示例15: combine_imgs
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import blit [as 别名]
def combine_imgs(img_list, list_size):
combined_img = Surface((list_size[0], list_size[1]))
y = 0
for img in img_list:
combined_img.blit(img, (0, y))
y += img.get_size()[1]
return combined_img