本文整理汇总了Python中pygame.Surface.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.copy方法的具体用法?Python Surface.copy怎么用?Python Surface.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
def __init__(self, word, word_o, color, angle):
Sprite.__init__(self)
self.word = word
self.angle = angle
# Determine Word dimensions
w_rect = word_o.get_bounding_rect()
w_rect.x = -w_rect.x + WORD_PADDING
w_rect.y = -w_rect.y + WORD_PADDING
w_rect.width += WORD_PADDING * 2
w_rect.height += WORD_PADDING * 2
# Draw Word on a surface
word_sf = Surface((w_rect.width, w_rect.height), SRCALPHA, 32)
word_sf.blit(word_o, w_rect)
self.rect = word_sf.get_rect()
self.image = word_sf.copy()
self.msf = word_sf.copy()
# Create custom mask
m1 = mask.from_surface(self.msf)
cr, crw = [], []
for c in [x for x in range(w_rect.width) if x % PXL == 0]:
for r in [y for y in range(w_rect.height) if y % PXL == 0]:
if m1.get_at((c, r)) != 0:
crw.append((c - PXL, r - PXL))
crw.append((c - PXL, r))
crw.append((c, r - PXL))
crw.append((c, r))
crw.append((c + PXL, r + PXL))
crw.append((c, r + PXL))
crw.append((c + PXL, r))
crw.append((c + PXL, r - PXL))
crw.append((c - PXL, r + PXL))
cr.append((c, r))
for c, r in crw:
draw.rect(self.msf, color, Rect((c, r), (PXL, PXL)))
for i in enumerate(cr):
c, r = i[1]
j = 1
if i[0] + 1 >= len(cr):
break
next_cr = cr[i[0] + 1]
while next_cr[0] == c and next_cr[1] != r + PXL * j:
draw.rect(self.msf, color, Rect((c, r + j * PXL), (PXL, PXL)))
j += 1
self._rotate()
示例2: makebackground
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
def makebackground(self, surface):
surface.fill((0,0,0))
template = Surface(2*(min(self.zoom.width, self.zoom.height),))
template.fill((0,0,0,255))
width,height = template.get_size()
ylim = surface.get_height()/height
xlim = surface.get_width()/width
data = self._data
noise = [[pnoise2(self._selected[1][0]+x,
self._selected[0][0]+y,
4, 0.85) * 50
for x in range(xlim)]
for y in range(ylim)]
hmin = hmax = 0
for y in range(ylim):
for x in range(xlim):
yd = len(data)*float(y)/ylim
xd = len(data[0])*float(x)/xlim
h = self._height(data, yd, xd)
n = noise[y][x]
if h < 0:
h += -n if n > 0 else n
else:
h += n if n > 0 else -n
if h < hmin:
hmin = h
if h > hmax:
hmax = h
self.rects = []
for y in range(ylim):
for x in range(xlim):
block = template.copy()
yd = len(data)*float(y)/ylim
xd = len(data[0])*float(x)/xlim
h = self._height(data, yd, xd)
n = noise[y][x]
if h < 0:
h += -n if n > 0 else n
else:
h += n if n > 0 else -n
if h < 0:
color = 0, 0, int(255 * (1 - h/hmin))
else:
color = 0, int(255 * h/hmax), 0
block.fill(color)
if self.selection:
if self.selection[0][0] <= yd <= self.selection[0][1]:
if self.selection[1][0] <= xd <= self.selection[1][1]:
block.fill((255,0,0,32),
special_flags = BLEND_ADD)
rect = Rect(x*width, y*height, width, height)
surface.blit(block, rect.topleft)
self.rects.append((rect, (yd, xd)))
示例3: compileSVASheet
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
def compileSVASheet(sheet, color):
color = tuple([255-c for c in color])
width = sheet.get_width()
height = sheet.get_height() / 3
colorSurf = Surface((width, height))
colorSurf.fill(color)
colorSurf.blit(sheet, (0, 0), None, BLEND_MULT)
# Now create a white surface so we can invert the Saturation map
result = Surface((width, height), SRCALPHA)
result.fill((255, 255, 255))
result.blit(colorSurf, (0, 0), None, BLEND_RGB_SUB)
# Multiply this with the Value Map
result.blit(sheet, (0, -height), None, BLEND_MULT)
# copy the alpha mask from the spritesheet
alpha = Surface((width, height))
alpha.blit(sheet, (0, -2 * height))
#convert the (nearly done) Surface to per pixel alpha
result.convert_alpha()
# Use Numpy here
numWhite = surfarray.pixels_alpha( result )
numAlpha = surfarray.pixels3d( alpha )
numWhite[ :, : ] = numAlpha[ :, :, 0 ]
return result.copy()
示例4: makebackground
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
def makebackground(self, surface):
surface.fill((0,0,0))
template = Surface(2*(min(self.zoom.width, self.zoom.height),),
flags=SRCALPHA)
template.fill((0,0,0,255))
width,height = template.get_size()
o = min(surface.get_width()/width,
surface.get_height()/height)/2
self.rects = []
for y in range(2*o):
lat = asin(float(y-o)/o) * 180/pi
r = int(sqrt(o**2-(o-y)**2))
for x in range(o-r, o+r):
block = template.copy()
v = [float(x-r)/o, float(y-o)/o]
if x >= o:
lon = self.rotate - acos(float((x-(o-r)-r))/r) * 180/pi
else:
lon = self.rotate + 180 + acos(float(r-(x-(o-r)))/r) * 180/pi
if lon > 180:
lon -= 360
h = self.planet.sample(lat, lon)
color = ((0,int(255 * (h/9000.0)),0) if h > 0
else (0,0,int(255 * (1 + h/11000.0))))
block.fill(color)
if self.selection:
if self.selection[0][0] <= lat <= self.selection[0][1]:
if self.selection[1][0] <= lon <= self.selection[1][1]:
block.fill((255,0,0,32),
special_flags = BLEND_ADD)
rect = Rect(x * width, y * height, width, height)
surface.blit(block, rect.topleft)
self.rects.append((rect, (lat, lon)))
示例5: LayeredRenderer
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
class LayeredRenderer(Renderer):
""" A renderer that uses all the layers in a tiled map. """
def __init__(self, level, screen_size_in_tiles, display_size):
# the next few variables are used to initialize the parent
# the size of the screen in tiles
self.screen_size_in_tiles = screen_size_in_tiles
# small name for the big variable
intiles = screen_size_in_tiles
# this is the size of the surface holding what is
# visible right now in the screen
screen_size = (intiles[0]*level.tiledmap.tilewidth,
intiles[1]*level.tiledmap.tileheight )
self.screen_size = screen_size
self.ratio = float(screen_size[0]) / float(screen_size[1])
# Size of the pygame window, the screen being rendered
# will be scaled to this size
self.display_size = display_size
# init the parent
Renderer.__init__(self, level, screen_size)
# the size of the whole map in pixels
self.map_size_in_pixels = (self.tiledmap.width*self.tw,
self.tiledmap.height*self.th)
# Everything will be drawn in here, used to clear when dirty.
self.map_background = Surface(self.map_size_in_pixels)
# This will hold the whole map with sprites included.
# From here we take the subsurface showed in screen.
self.full_map = None
# Keep aspect ratio?
self.keep_aspect_ratio = True
self.ratio_display_size = (1,1)
self.temp_surface = Surface((1,1))
self.ratio_dest = (0,0)
self.new_size = self.display_size
self.debug_images = False
self.debugging = False
def coords_from_screen_to_map(self, screen_coords):
ratio_x = float(self.screen_size[0]) / float(self.display_size[0])
ratio_y = float(self.screen_size[1]) / float(self.display_size[1])
new_coord_x = screen_coords[0] * ratio_x + self.current_camera.screen_rect[0]
new_coord_y = screen_coords[1] * ratio_y + self.current_camera.screen_rect[1]
return new_coord_x,new_coord_y
def coords_from_map_to_screen(self, coords):
pass
def render_map_background(self, surface=None):
""" Render the whole static part of a map in the given surface.
I a surface is not given uses self.map_background. Copy it to
self.full_map if it doesn't exist.
Only needs to be called once, after init. Can be used to
clean sprites that haven't been cleaned properly.
"""
if surface == None:
surface = self.map_background
for i in range(len(self.level.layers)):
layer = self.level.layers[i]
if layer.visible:
if isinstance(layer, ImageLayer):
layer.draw(surface)
elif isinstance(layer, TileLayer):
# TODO
# animated tiles need som special treatment too
layer.static.draw(surface)
elif isinstance(layer, ObjectLayer):
pass
if self.full_map == None:
self.full_map = self.map_background.copy()
def get_dirty_rects(self):
""" Get all the rects that need to be repainted.
DEPRECATED
Because of alpha compositing this have to be called before
updating the mobs and after updating the mobs.
"""
union_add = self.union_add
last_dirty_rects = self.last_dirty_rects
layers = self.level.layers
for i in range(len(layers)):
layer = layers[i]
if not layer.visible: continue
# ImageLayer and TileLayer have no moving parts (yet)
if isinstance(layer, ImageLayer):
pass
elif isinstance(layer, TileLayer):
# animated tiles need som special treatment too TODO TODO
#.........这里部分代码省略.........
示例6: makebackground
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
def makebackground(self, surface):
surface.fill((0,0,0))
template = Surface(2*(min(self.zoom.width, self.zoom.height),))
template.fill((0,0,0,255))
width,height = template.get_size()
ylim = surface.get_height()/height
dlat = float(self.selected[0][1] - self.selected[0][0])/ylim
xmax = 0
for y in range(ylim):
lat = self.selected[0][0] + y * dlat
scale = cos(lat * pi/180)
w = int(surface.get_width() * scale/width)
if w > xmax:
xmax = w
hmin = hmax = 0
for y in range(ylim):
lat = self.selected[0][0] + y * dlat
scale = cos(lat * pi/180)
xlim = int(surface.get_width() * scale/width)
for x in range(xlim):
dx = float(xmax - xlim)/2
lon = self.selected[1][0] + (x + dx) * scale * dlat
h = self.planet.sample(lat, lon)
if h < hmin:
hmin = h
if h > hmax:
hmax = h
self.rects = []
for y in range(ylim):
lat = self.selected[0][0] + y * dlat
scale = cos(lat * pi/180)
xlim = int(surface.get_width() * scale/width)
for x in range(xlim):
dx = float(xmax - xlim)/2
lon = self.selected[1][0] + (x + dx) * scale * dlat
block = template.copy()
h = self.planet.sample(lat, lon)
if h < 0:
color = 0, 0, int(255 * (1 - h/hmin))
else:
color = 0, int(255 * h/hmax), 0
block.fill(color)
if self.selection:
if self.selection[0][0] <= lat <= self.selection[0][1]:
if self.selection[1][0] <= lon <= self.selection[1][1]:
block.fill((255,0,0,32),
special_flags = BLEND_ADD)
rect = Rect(int(x+dx)*width, y*height, width, height)
surface.blit(block, rect.topleft)
self.rects.append((rect, (lat, lon)))
示例7: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import copy [as 别名]
#.........这里部分代码省略.........
strip_width = self.raycast.strip_width
x = 0
last_slice_meta = (None, None, None, None)
last_slice = None
for ray in rays:
this_slice_meta = (default_texture, default_type, ray['texture_x'], ray['distance'])
if (this_slice_meta != last_slice_meta):
last_slice_meta = this_slice_meta
strip_height = round(self.raycast.distance_to_plane / ray['distance'])
y = round((self.size[1]-strip_height)/2)
required_slice = round((self.texture_size/strip_width)*ray['texture_x']) - 1
try:
last_slice = transform.scale(self.wall_textures[default_texture][default_type][required_slice], (strip_width, strip_height))
except Exception as e:
pass
try:
self.screen.blit(last_slice,(x,y))
except Exception as e:
pass
x += strip_width
strip_no = strip_no + 1
def draw(self,game):
self.clearScreen()
rays = self.raycast.castRays(game.player, game.world)
self.drawRaycastedView(rays)
self.drawUpdatedMinimap(game.world, game.player, rays, (0,0))
self.drawFPS(game.fps)
self.finishDrawing()
def clearScreen(self):
self.screen.blit(self.background, (0, 0))
def initMinimap(self, world):
size = ((world.width+2) * self.minimap_scale,(world.height+2) * self.minimap_scale)
self.minimap_surface = Surface(size).convert()
self.prenderMinimap(world)
def prenderMinimap(self, world):
self.minimap_surface.fill((0, 0, 0))
scale = self.minimap_scale
y = scale # margin
for row in world.world:
x = scale
for item in row:
draw.rect(
self.minimap_surface,
item.map_color,
(x,y,scale,scale)
)
x = x + scale
y = y + scale
def drawUpdatedMinimap(self, world, player, rays, coords):
scale = self.minimap_scale
player_coords = ((player.coords+1) * scale).rounded().toInt().toTuple()
player_direction = player.direction * scale
player_direction = (player_direction + player_coords).rounded().toInt().toTuple()
minimap = self.minimap_surface.copy()
draw.circle(
minimap,
player.map_color,
player_coords,
round(player.size*scale)
)
for ray in rays:
draw.line(
minimap,
(0,255,0),
player_coords,
((ray['coords'][0]+1)*scale, (ray['coords'][1]+1)*scale)
)
draw.line(
minimap,
player.map_color,
player_coords,
player_direction
)
self.screen.blit(minimap, coords)
def finishDrawing(self):
display.flip()
def drawFPS(self, fps):
fps = round(fps)
if (fps >= 40):
fps_color = (0,102,0)
elif(fps >= 20):
fps_color = (255, 153, 0)
else:
fps_color = (204, 0, 0)
self.screen.blit(
self.default_font.render('FPS: '+str(fps), False, fps_color),
(self.size[0]-70, 5)
)