Merge branch 'master' of makar:/var/www/git/pgfw
This commit is contained in:
commit
1f01be3882
|
@ -1,3 +1,5 @@
|
|||
import collections
|
||||
|
||||
from .GameChild import GameChild
|
||||
|
||||
class Animation(GameChild):
|
||||
|
@ -6,7 +8,7 @@ class Animation(GameChild):
|
|||
GameChild.__init__(self, parent)
|
||||
self.unfiltered = unfiltered
|
||||
self.default_method = method or self.build_frame
|
||||
self.accounts = {}
|
||||
self.accounts = collections.OrderedDict()
|
||||
self.register(self.default_method, interval=interval)
|
||||
self.last_update = 0
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import itertools
|
||||
from random import randint, random
|
||||
from math import sin, cos, atan2, radians, sqrt, pi
|
||||
|
||||
|
@ -82,6 +83,19 @@ def get_range_steps(start, end, count):
|
|||
for ii in range(count):
|
||||
yield start + (end - start) * ii / float(count - 1)
|
||||
|
||||
def get_percent_way(iterable):
|
||||
for ii in range(len(iterable)):
|
||||
yield iterable[ii], float(ii) / len(iterable)
|
||||
|
||||
def mirrored(iterable, full=False, tail=True):
|
||||
for ii, item in enumerate(itertools.chain(iterable, reversed(iterable))):
|
||||
if not full and ii == len(iterable):
|
||||
continue
|
||||
elif not tail and ii == len(iterable) * 2 - 1:
|
||||
continue
|
||||
else:
|
||||
yield item
|
||||
|
||||
def get_distance(p0, p1):
|
||||
return sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
|
||||
|
||||
|
@ -146,9 +160,8 @@ def get_value_in_range(start, end, position, reverse=False):
|
|||
position = 1 - position
|
||||
return (end - start) * position + start
|
||||
|
||||
def render_box(font, text, antialias, color, background=None, border=None,
|
||||
border_width=1, padding=0):
|
||||
surface = font.render(text, antialias, color, background)
|
||||
def get_boxed_surface(surface, background=None, border=None, border_width=1,
|
||||
padding=0):
|
||||
if padding:
|
||||
if isinstance(padding, int):
|
||||
padding = [padding] * 2
|
||||
|
@ -173,6 +186,50 @@ def render_box(font, text, antialias, color, background=None, border=None,
|
|||
surface = bordered_surface
|
||||
return surface
|
||||
|
||||
def render_box(font, text, antialias, color, background=None, border=None,
|
||||
border_width=1, padding=0):
|
||||
return get_boxed_surface(font.render(text, antialias, color, background),
|
||||
background, border, border_width, padding)
|
||||
|
||||
def get_wrapped_text_surface(font, text, width, antialias, color,
|
||||
background=None, border=None, border_width=1,
|
||||
padding=0):
|
||||
words = text.split()
|
||||
if words:
|
||||
line_text = ""
|
||||
lines = []
|
||||
height = 0
|
||||
ii = 0
|
||||
finished = False
|
||||
while not finished:
|
||||
line_width = font.size(line_text + " " + words[ii])[0]
|
||||
if line_width > width or ii == len(words) - 1:
|
||||
if ii == len(words) - 1 and line_width <= width:
|
||||
if line_text != "":
|
||||
line_text += " "
|
||||
line_text += words[ii]
|
||||
finished = True
|
||||
line = font.render(line_text, antialias, color, background)
|
||||
height += line.get_height()
|
||||
lines.append(line)
|
||||
line_text = ""
|
||||
else:
|
||||
line_text += " " + words[ii]
|
||||
ii += 1
|
||||
top = 0
|
||||
surface = Surface((width, height), SRCALPHA)
|
||||
if background:
|
||||
surface.fill(background)
|
||||
rect = surface.get_rect()
|
||||
for line in lines:
|
||||
line_rect = line.get_rect()
|
||||
line_rect.midtop = rect.centerx, top
|
||||
surface.blit(line, line_rect)
|
||||
top += line_rect.h
|
||||
else:
|
||||
surface = Surface((0, 0), SRCALPHA)
|
||||
return get_boxed_surface(surface, background, border, border_width, padding)
|
||||
|
||||
def get_color_swapped_surface(surface, current, replacement):
|
||||
swapped = surface.copy()
|
||||
pixels = PixelArray(swapped)
|
||||
|
@ -200,6 +257,9 @@ def get_hue_shifted_surface(base, offset):
|
|||
del pixels
|
||||
return surface
|
||||
|
||||
def get_inverted_color(color):
|
||||
return Color(255 - color[0], 255 - color[1], 255 - color[2])
|
||||
|
||||
def get_inverted_surface(base):
|
||||
surface = base.copy()
|
||||
pixels = PixelArray(surface)
|
||||
|
@ -207,10 +267,7 @@ def get_inverted_surface(base):
|
|||
for y in range(surface.get_height()):
|
||||
color = Color(*surface.unmap_rgb(pixels[x][y]))
|
||||
if color.hsla[3]:
|
||||
color.r = 255 - color.r
|
||||
color.g = 255 - color.g
|
||||
color.b = 255 - color.b
|
||||
pixels[x][y] = color
|
||||
pixels[x][y] = get_inverted_color(color)
|
||||
del pixels
|
||||
return surface
|
||||
|
||||
|
@ -267,6 +324,11 @@ def get_random_hsla_color(hue_range=(0, 359), saturation_range=(0, 100),
|
|||
randint(*hue_range), randint(*saturation_range), randint(*lightness_range),
|
||||
randint(*alpha_range))
|
||||
|
||||
def get_hsva_color(hue, saturation=100, value=100, alpha=100):
|
||||
color = Color(0, 0, 0, 0)
|
||||
color.hsva = hue % 360, saturation, value, alpha
|
||||
return color
|
||||
|
||||
# http://www.pygame.org/wiki/BezierCurve
|
||||
def compute_bezier_points(vertices, numPoints=60):
|
||||
points = []
|
||||
|
|
Loading…
Reference in New Issue