本文整理汇总了Python中pygame.SRCALPHA属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.SRCALPHA属性的具体用法?Python pygame.SRCALPHA怎么用?Python pygame.SRCALPHA使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.SRCALPHA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def __init__(self):
def make_surface(tl):
w = 40
surface = pygame.Surface((w, 3 * w), pygame.SRCALPHA)
surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
if tl != 'h':
hw = int(w / 2)
off = COLOR_ALUMINIUM_4
red = COLOR_SCARLET_RED_0
yellow = COLOR_BUTTER_0
green = COLOR_CHAMELEON_0
pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
self._original_surfaces = {
'h': make_surface('h'),
tls.Red: make_surface(tls.Red),
tls.Yellow: make_surface(tls.Yellow),
tls.Green: make_surface(tls.Green),
tls.Off: make_surface(tls.Off),
tls.Unknown: make_surface(tls.Unknown)
}
self.surfaces = dict(self._original_surfaces)
示例2: draw_surface_loads_curves
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def draw_surface_loads_curves(self, n_hours_to_display_top_loadplot, n_hours_to_display_bottom_loadplot):
# Loads curve surface: retrieve images surfaces, stack them into a common surface, plot horizontal lines
# at top and bottom of latter surface
# compute the string number of days
n_days_horizon = n_hours_to_display_top_loadplot // 24
img_loads_curve_week = self.create_plot_loads_curve(
n_timesteps=int(n_hours_to_display_top_loadplot * 3600 // self.timestep_duration_seconds),
left_xlabel=' {} day{} ago '.format(n_days_horizon, 's' if n_days_horizon > 1 else ''))
n_hours_horizon = n_hours_to_display_bottom_loadplot
img_loads_curve_day = self.create_plot_loads_curve(
n_timesteps=int(n_hours_to_display_bottom_loadplot * 3600 // self.timestep_duration_seconds),
left_xlabel='{} hours ago'.format(n_hours_horizon))
loads_curve_surface = pygame.Surface(
(img_loads_curve_week.get_width(), 2 * img_loads_curve_week.get_height() + 30),
pygame.SRCALPHA, 32).convert_alpha()
loads_curve_surface.fill(self.left_menu_tile_color)
loads_curve_surface.blit(self.bold_white_render('Historical total consumption'), (30, 10))
loads_curve_surface.blit(img_loads_curve_week, (0, 30))
loads_curve_surface.blit(img_loads_curve_day, (0, 30 + img_loads_curve_week.get_height()))
gfxdraw.hline(loads_curve_surface, 0, loads_curve_surface.get_width(), 0, (64, 64, 64))
gfxdraw.hline(loads_curve_surface, 0, loads_curve_surface.get_width(), loads_curve_surface.get_height() - 1,
(64, 64, 64))
return loads_curve_surface
示例3: _render_keyboard
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _render_keyboard(self):
if not self.m_oRndLayout:
self.m_oRndLayout = self.render_image(self.m_sLayout)
if not self.m_oRndCursor:
self.m_oRndCursor = self.render_image(self.m_sCursor)
self.m_oRndText = self._line_text()
self.m_oSfKBD = pygame.Surface((self.m_oRndLayout.get_width(),
self.m_oRndLayout.get_height()),
pygame.SRCALPHA)
rect = self.m_oRndLayout.get_rect()
rect.topleft = (0, 0)
self.m_oSfKBD.blit(self.m_oRndLayout, rect)
rect = self.m_oRndCursor.get_rect()
pos = self._get_coord()
rect.midtop = (pos[0], pos[1])
self.m_oSfKBD.blit(self.m_oRndCursor, rect)
rect = self.m_oRndText.get_rect()
rect.midleft = (self.m_iTextLft, self.m_iTextLine)
self.m_oSfKBD.blit(self.m_oRndText, rect)
示例4: _line_text
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _line_text(self):
max_width = self.m_iTextRgt - self.m_iTextLft
text = self.render_text(self.m_sText)
sf = pygame.Surface((max_width, text.get_height()), pygame.SRCALPHA)
LnWidth = text.get_width() + self.m_oRndCursor.get_width()
textSf = pygame.Surface((LnWidth, text.get_height()), pygame.SRCALPHA)
rect = text.get_rect()
rect.bottomleft = (0, textSf.get_height())
textSf.blit(text, rect)
rect = self.m_oRndCursor.get_rect()
rect.bottomright = (LnWidth, textSf.get_height())
textSf.blit(self.m_oRndCursor, rect)
if LnWidth < max_width:
rect = textSf.get_rect()
rect.midbottom = (max_width / 2, sf.get_height())
sf.blit(textSf, rect)
else:
rect = textSf.get_rect()
rect.bottomright = (max_width, sf.get_height())
sf.blit(textSf, rect)
return sf
示例5: render_text
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def render_text(self, p_sText, p_bShadow = True):
C_SHADOW = pygame.Color( 19, 14, 56)
C_TEXT = pygame.Color(202,199,219)
p_sText = str(p_sText)
img = self.m_oFontText.render(p_sText, False, C_TEXT)
rect = img.get_rect()
sf = pygame.Surface((rect.width, rect.height), pygame.SRCALPHA)
if p_bShadow:
shadow = self.m_oFontText.render(p_sText, False, C_SHADOW)
shadow_rect = img.get_rect()
shadow_rect.x += 1
shadow_rect.y += 1
sf.blit(shadow, shadow_rect)
sf.blit(img, rect)
return sf
示例6: _render_info_text
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _render_info_text(self, p_sText, p_sIcon = None):
ltoffset = 0
if p_sIcon:
icon = self._img_render(self.dCFG[p_sIcon])
ltoffset += icon.get_width() + 3
text = self._text_render(p_sText, C_WHITE, 'type_color_3')
size = ltoffset + text.get_width()
oSectSf = pygame.Surface((size, self.dCFG['font_line'] + 4), pygame.SRCALPHA)
if size > text.get_width():
alignY = 0
if icon.get_height() > self.dCFG['font_size']:
alignY -= math.ceil((icon.get_height() - self.dCFG['font_size']) / 2.0)
rect = icon.get_rect()
rect.midleft = (0, (oSectSf.get_height() / 2) + alignY)
oSectSf.blit(icon, rect)
rect = text.get_rect()
rect.midleft = (ltoffset, oSectSf.get_height() / 2)
oSectSf.blit(text, rect)
return oSectSf
示例7: _render_layer10
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _render_layer10(self, p_bReload = False):
# layer10 surface, selector
line = self._get_onscreen_menu_line()
Y_POS = self.m_iMenu_pos + (line * self.m_iText_spc)
self.m_oLayer10 = pygame.Surface(self.m_lRES, pygame.SRCALPHA)
# append selector to layer10
if not self.dCFG['selector_render'] or p_bReload:
img = "selector"
if self.m_iSide != 0: img = "vselector"
self.dCFG['selector_render'] = self._img_render(self.dCFG[img])
rect = self.dCFG['selector_render'].get_rect()
rect.midleft = (0, Y_POS)
self.m_oLayer10.blit(self.dCFG['selector_render'], rect)
# Rotate if vertical mode
if self.m_iSide == 1:
self.m_oLayer10 = pygame.transform.rotate(self.m_oLayer10, -90)
elif self.m_iSide == 3:
self.m_oLayer10 = pygame.transform.rotate(self.m_oLayer10, 90)
示例8: _render_layer21
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _render_layer21(self):
# selected line
self.m_oLayer21 = pygame.Surface(self.m_lRES, pygame.SRCALPHA)
line = self._get_onscreen_menu_line()
Y_POS = self.m_iMenu_pos + (line * self.m_iText_spc)
oLine = self._render_line_menu(self.m_lLines[self.m_iLine])
# append line surface to layer21 surface
rect = oLine.get_rect()
rect.midleft = (self.m_iText_lft, Y_POS)
self.m_oLayer21.blit(oLine, rect)
# Rotate if vertical mode
if self.m_iSide == 1:
self.m_oLayer21 = pygame.transform.rotate(self.m_oLayer21, -90)
elif self.m_iSide == 3:
self.m_oLayer21 = pygame.transform.rotate(self.m_oLayer21, 90)
示例9: _render_layer30
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _render_layer30(self):
# layer30 pointer
line = self._get_onscreen_menu_line()
Y_POS = self.m_iMenu_pos + (line * self.m_iText_spc)
self.m_oLayer30 = pygame.Surface(self.m_lRES, pygame.SRCALPHA)
if not self.m_lPointer['pointer_render']:
if type(self.dCFG['pointer']) is list:
for item in self.dCFG['pointer']:
ptr = self._img_render(item)
self.m_lPointer['pointer_render'].append(ptr)
else:
ptr = self._img_render(self.dCFG['pointer'])
self.m_lPointer['pointer_render'].append(ptr)
ptr = self.m_lPointer['pointer_render'][self.m_lPointer['frame']]
rect = ptr.get_rect()
rect.midright = (self.m_iText_lft - 2, Y_POS)
self.m_oLayer30.blit(ptr, rect)
# Rotate if vertical mode
if self.m_iSide == 1:
self.m_oLayer30 = pygame.transform.rotate(self.m_oLayer30, -90)
elif self.m_iSide == 3:
self.m_oLayer30 = pygame.transform.rotate(self.m_oLayer30, 90)
示例10: _gradsurf
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def _gradsurf(h, y0, y1, color0, color1):
key = h, y0, y1, color0, color1
if key in _grad_cache:
return _grad_cache[key]
surf = pygame.Surface((1, h),flags=pygame.SRCALPHA).convert_alpha()
r0, g0, b0 = color0[:3]
r1, g1, b1 = color1[:3]
for y in range(h):
f = min(max((y - y0) / (y1 - y0), 0), 1)
g = 1 - f
surf.set_at((0, y), (
int(round(g * r0 + f * r1)),
int(round(g * g0 + f * g1)),
int(round(g * b0 + f * b1)),
0
))
_grad_cache[key] = surf
return surf
# Tracks everything that can be updated by tags.
示例11: render
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def render(self, window, segment):
coords = segment.bottom["screen"]
s_width = s.DIMENSIONS[0]
s_height = int(s.TUNNEL_HEIGHT * coords["s"] * s.ROAD_WIDTH * self.quantifier)
x = 0
y = s.DIMENSIONS[1] - coords["y"] - s_height
top_clip = s.DIMENSIONS[1] - segment.clip[1] - y
# Player can see the tunnel approaching.
if top_clip > 0:
e_height = int(s_height * 0.7)
surf = pygame.Surface([s_width, s_height], pygame.SRCALPHA, 32)
surf = surf.convert_alpha()
points = [(s_width, s_height),
(coords["x"] + coords["w"], s_height),
(coords["x"] + coords["w"], s_height - e_height),
(coords["x"] - coords["w"], s_height - e_height),
(coords["x"] - coords["w"], s_height),
(0, s_height),
(0, 0),
(s_width, 0)]
pygame.draw.polygon(surf, self.colour, points)
window.blit(surf, (x, y), (0, 0, s_width, top_clip))
示例12: __level_over_overlay
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def __level_over_overlay(self, window):
lo_font = pygame.font.Font(s.FONTS["fipps"], 38)
s_font = pygame.font.Font(s.FONTS["retro_computer"], 30)
txt_lo = lo_font.render("Level Complete!", 1, s.COLOURS["dark_text"])
txt_lap = s_font.render("Best Lap", 1, s.COLOURS["dark_text"])
txt_lap_v = s_font.render("%.1fs" % round(self.fastest_lap, 1), 1, s.COLOURS["dark_text"])
txt_bonus = s_font.render("Time bonus", 1, s.COLOURS["dark_text"])
txt_bonus_v = s_font.render(str(math.trunc(self.time_bonus)), 1, s.COLOURS["dark_text"])
txt_points = s_font.render("Points", 1, s.COLOURS["dark_text"])
txt_points_v = s_font.render(str(math.trunc(self.points)), 1, s.COLOURS["dark_text"])
overlay = pygame.Surface(s.DIMENSIONS, pygame.SRCALPHA)
overlay.fill((255, 255, 255, 150))
overlay.blit(txt_lo, (s.DIMENSIONS[0] / 2 - txt_lo.get_size()[0] / 2, 20))
overlay.blit(txt_lap, (20, 180))
overlay.blit(txt_lap_v, (s.DIMENSIONS[0] - txt_lap_v.get_size()[0] - 10, 190))
overlay.blit(txt_bonus, (20, 260))
overlay.blit(txt_bonus_v, (s.DIMENSIONS[0] - txt_bonus_v.get_size()[0] - 10, 270))
overlay.blit(txt_points, (20, 340))
overlay.blit(txt_points_v, (s.DIMENSIONS[0] - txt_points_v.get_size()[0] - 10, 350))
window.blit(overlay, (0,0))
示例13: display
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def display(cls, object_: 'RoadObject', surface: WorldSurface, transparent: bool = False,
offscreen: bool = False):
"""
Display a road objects on a pygame surface.
The objects is represented as a colored rotated rectangle
:param object_: the vehicle to be drawn
:param surface: the surface to draw the object on
:param transparent: whether the object should be drawn slightly transparent
:param offscreen: whether the rendering should be done offscreen or not
"""
o = object_
s = pygame.Surface((surface.pix(o.LENGTH), surface.pix(o.LENGTH)), pygame.SRCALPHA) # per-pixel alpha
rect = (0, surface.pix(o.WIDTH) / 2 - surface.pix(o.WIDTH) / 2, surface.pix(o.LENGTH), surface.pix(o.WIDTH))
pygame.draw.rect(s, cls.get_color(o, transparent), rect, 0)
pygame.draw.rect(s, cls.BLACK, rect, 1)
if not offscreen: # convert_alpha throws errors in offscreen mode TODO() Explain why
s = pygame.Surface.convert_alpha(s)
h = o.heading if abs(o.heading) > 2 * np.pi / 180 else 0
# Centered rotation
position = (surface.pos2pix(o.position[0], o.position[1]))
cls.blit_rotate(surface, s, position, np.rad2deg(-h))
示例14: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def __init__(self, ls, w, h, l, t, value):
pygame.sprite.Sprite.__init__(self)
self.ls = ls
self.w = w
self.h = h
self.left = l
self.top = t
self.focus_order = -1
if self.ls.lang.ltr_text:
self.right_align = False
else:
self.right_align = True
self.font_color = self.ls.colors.font_color
self.value = value
self.visible = True
self.select_item = False
self.update_me = True
self.hover = False
self.image = pygame.Surface((w, h), flags=pygame.SRCALPHA)
self.rect = self.image.get_rect()
self.rect.topleft = [l, t]
self.font_v = self.ls.font_2
示例15: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import SRCALPHA [as 别名]
def __init__(self, game_board, width, height, scale, color, border_color, rng, number, lbl_dist=5):
self.size = [width * scale, height * scale]
self.center = [self.size[0] // 2, self.size[1] // 2]
self.game_board = game_board
self.color = color
self.border_color = border_color
self.number = number
self.lbl_dist = lbl_dist
self.rng = rng
self.v_margin = int(80 * self.size[0] / 500.0)
self.marker_len10 = int(20 * self.size[0] / 150.0)
self.marker_len5 = int(15 * self.size[0] / 150.0)
self.marker_len = int(10 * self.size[0] / 150.0)
self.bar_width = int(25 * self.size[0] / 150.0)
self.bottom_r = int(30 * self.size[0] / 150.0)
self.v_gauge_margin_t = int(120 * self.size[0] / 500.0)
self.v_gauge_margin_b = int(120 * self.size[0] / 500.0) + self.bottom_r
self.canvas = pygame.Surface((self.size[0], self.size[1] - 1), flags=pygame.SRCALPHA)
self.canvas.fill((0, 0, 0, 0))
self.draw_thermometer()