本文整理汇总了Python中pygame.Surface.scroll方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.scroll方法的具体用法?Python Surface.scroll怎么用?Python Surface.scroll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.scroll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import scroll [as 别名]
class Waterfall:
def __init__(self, size, top_freq=1000.0, markers=[], sample_rate=48000.0):
self.size = size
self.surface = Surface(size)
self.markers = markers
self.top_freq = top_freq
self.sample_rate = sample_rate
self.peak = np.zeros(2)
self.history = []
def draw_spectrum(self, f, x):
draw_area = Surface((1, len(f)), depth=24)
d = surfarray.pixels3d(draw_area)
self.peak = np.maximum(np.amax(f, axis=0), self.peak)
a = (255 * f / self.peak[np.newaxis, :]).astype(np.uint8)
d[0, :, 1:] = a[::-1]
d[0, :, 0] = a[::-1, 1] / 2 + a[::-1, 0] / 2
for m in self.markers:
im = int((2 * m / self.sample_rate) * len(f))
d[0, -im, 0] = 255
del d
it = int((2 * self.top_freq / self.sample_rate) * len(f))
self.surface.blit(smoothscale(draw_area.subsurface((0, len(f) - it - 1, 1, it)), (1, self.size[1])), (x, 0))
self.peak *= 2.0 ** (-1.0 / 100)
def add_spectrum(self, f):
self.history.append(f)
self.history = self.history[-self.size[0] :]
self.surface.scroll(dx=-1)
self.draw_spectrum(f, self.size[0] - 1)
def resize(self, size):
if size == self.size:
return
self.size = size
self.surface = Surface(size)
for i in range(min(len(self.history), self.size[0])):
self.draw_spectrum(self.history[-i - 1], self.size[0] - i)
示例2: BufferedRenderer
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import scroll [as 别名]
class BufferedRenderer(object):
""" Renderer that support scrolling, zooming, layers, and animated tiles
The buffered renderer must be used with a data class to get tile, shape,
and animation information. See the data class api in pyscroll.data, or
use the built-in pytmx support for loading maps created with Tiled.
"""
def __init__(self, data, size, clamp_camera=True, colorkey=None, alpha=False,
time_source=time.time, scaling_function=pygame.transform.scale):
# default options
self.map_rect = None # pygame rect of entire map
self.data = data # reference to data source
self.clamp_camera = clamp_camera # if clamped, cannot scroll past map edge
self.time_source = time_source # determines how tile animations are processed
self.scaling_function = scaling_function # what function to use when zooming
self.default_shape_texture_gid = 1 # [experimental] texture to draw shapes with
self.default_shape_color = 0, 255, 0 # [experimental] color to fill polygons with
# internal private defaults
self._alpha = False
if colorkey and alpha:
print('cannot select both colorkey and alpha. choose one.')
raise ValueError
elif colorkey:
self._clear_color = colorkey
else:
self._clear_color = None
# private attributes
self._size = None # size that the camera/viewport is on screen, kinda
self._redraw_cutoff = None # size of dirty tile edge that will trigger full redraw
self._x_offset = None # offsets are used to scroll map in sub-tile increments
self._y_offset = None
self._buffer = None # complete rendering of tilemap
self._tile_view = None # this rect represents each tile on the buffer
self._half_width = None # 'half x' attributes are used to reduce division ops.
self._half_height = None
self._tile_queue = None # tiles queued to be draw onto buffer
self._animation_queue = None # heap queue of animation token. schedules tile changes
self._animation_map = None # map of GID to other GIDs in an animation
self._last_time = None # used for scheduling animations
self._layer_quadtree = None # used to draw tiles that overlap optional surfaces
self._zoom_buffer = None # used to speed up zoom operations
self._zoom_level = 1.0 # negative numbers make map smaller, positive: bigger
# this represents the viewable pixels, aka 'camera'
self.view_rect = Rect(0, 0, 0, 0)
self.reload_animations()
self.set_size(size)
def _update_time(self):
self._last_time = time.time() * 1000
def reload_animations(self):
""" Reload animation information
"""
self._update_time()
self._animation_map = dict()
self._animation_queue = list()
for gid, frame_data in self.data.get_animations():
frames = list()
for frame_gid, frame_duration in frame_data:
image = self.data.get_tile_image_by_gid(frame_gid)
frames.append(AnimationFrame(image, frame_duration))
ani = AnimationToken(gid, frames)
ani.next += self._last_time
self._animation_map[ani.gid] = ani.frames[ani.index].image
heappush(self._animation_queue, ani)
def _process_animation_queue(self):
self._update_time()
requires_redraw = False
# test if the next scheduled tile change is ready
while self._animation_queue[0].next <= self._last_time:
requires_redraw = True
token = heappop(self._animation_queue)
# advance the animation index, looping by default
if token.index == len(token.frames) - 1:
token.index = 0
else:
token.index += 1
next_frame = token.frames[token.index]
token.next = next_frame.duration + self._last_time
self._animation_map[token.gid] = next_frame.image
heappush(self._animation_queue, token)
if requires_redraw:
# TODO: record the tiles that changed and update only affected tiles
self.redraw_tiles()
pass
def _calculate_zoom_buffer_size(self, value):
if value <= 0:
#.........这里部分代码省略.........