Example #1
0
def heartimg(alpha = 1, cache = {}):
	z = int(vista.zoom)
	alpha = min(max(int(alpha * 10) / 10., 0), 1)
	key = z, alpha
	if key in cache:
		return cache[key]
	if "base" not in cache:
		cache["base"] = pygame.image.load(data.filepath("heart.png")).convert_alpha()
	img = pygame.transform.smoothscale(cache["base"], (z, z))
	if alpha != 1:
		pixels_alpha(img)[:] *= alpha
	cache[key] = img
	return cache[key]
Example #2
0
def heartimg(alpha=1, cache={}):
    z = int(vista.zoom)
    alpha = min(max(int(alpha * 10) / 10., 0), 1)
    key = z, alpha
    if key in cache:
        return cache[key]
    if "base" not in cache:
        cache["base"] = pygame.image.load(
            data.filepath("heart.png")).convert_alpha()
    img = pygame.transform.smoothscale(cache["base"], (z, z))
    if alpha != 1:
        pixels_alpha(img)[:] *= alpha
    cache[key] = img
    return cache[key]
Example #3
0
def dustcloudimg(angle = 0, alpha = 1, R = 1, cache = {}):
	z = int(R * vista.zoom)
	angle = int(angle % 360) / 10 * 10
	alpha = min(max(int(alpha * 10) / 10., 0), 1)
	key = z, angle, alpha
	if key in cache:
		return cache[key]
	if "base" not in cache:
		img0 = spherecircles.img(R = 0.3, color = "dust", zoom = settings.tzoom0)
		cache["base"] = vista.Surface(0.8*settings.tzoom0)
		cache["base"].blit(img0, img0.get_rect(center = cache["base"].get_rect().center))
	img = pygame.transform.rotozoom(cache["base"], angle, float(z) / settings.tzoom0)
	if alpha != 1:
		pixels_alpha(img)[:] *= alpha
	cache[key] = img
	return cache[key]
Example #4
0
def dustcloudimg(angle=0, alpha=1, R=1, cache={}):
    z = int(R * vista.zoom)
    angle = int(angle % 360) / 10 * 10
    alpha = min(max(int(alpha * 10) / 10., 0), 1)
    key = z, angle, alpha
    if key in cache:
        return cache[key]
    if "base" not in cache:
        img0 = spherecircles.img(R=0.3, color="dust", zoom=settings.tzoom0)
        cache["base"] = vista.Surface(0.8 * settings.tzoom0)
        cache["base"].blit(
            img0, img0.get_rect(center=cache["base"].get_rect().center))
    img = pygame.transform.rotozoom(cache["base"], angle,
                                    float(z) / settings.tzoom0)
    if alpha != 1:
        pixels_alpha(img)[:] *= alpha
    cache[key] = img
    return cache[key]
Example #5
0
def plusimg(color, alpha = 1, cache = {}):
	z = int(vista.zoom * 0.7)
	alpha = min(max(int(alpha * 10) / 10., 0), 1)
	key = z, alpha, color
	if key in cache:
		return cache[key]
	if color not in cache:
		baseimg = vista.Surface(240)
		baseimg.fill((255, 255, 255), (80, 0, 80, 240))
		baseimg.fill((255, 255, 255), (0, 80, 240, 80))
		baseimg.fill((160, 160, 160), (15, 95, 210, 50))
		baseimg.fill((160, 160, 160), (95, 15, 50, 210))
		filtersurface(baseimg, *color)
		cache[color] = baseimg
	img = pygame.transform.smoothscale(cache[color], (z, z))
	if alpha != 1:
		pixels_alpha(img)[:] *= alpha
	cache[key] = img
	return cache[key]
Example #6
0
def filtersurface(surf, x, y, z, a=1):
	arr = pygame.surfarray.pixels3d(surf)
	if x != 1: arr[...,0] *= x
	if y != 1: arr[...,1] *= y
	if z != 1: arr[...,2] *= z
	if a != 1: pixels_alpha(surf)[:] *= a
Example #7
0
	if x != 1: arr[...,0] *= x
	if y != 1: arr[...,1] *= y
	if z != 1: arr[...,2] *= z
	if a != 1: pixels_alpha(surf)[:] *= a


def filtercolorsurface(surf, (x0,y0,z0,a0), (x1,y1,z1,a1)=(0,0,0,0), (x2,y2,z2,a2)=(0,0,0,0)):
	arr = pygame.surfarray.pixels3d(surf)
	r = arr[...,0] * x0 + arr[...,1] * x1 + arr[...,2] * x2
	g = arr[...,0] * y0 + arr[...,1] * y1 + arr[...,2] * y2
	b = arr[...,0] * z0 + arr[...,1] * z1 + arr[...,2] * z2
	arr[...,0] = r
	arr[...,1] = g
	arr[...,2] = b
	# TODO: what to do about transparency here??
	if a0 != 1: pixels_alpha(surf)[:] *= a0


def maketransparent(surf):
	filtersurface(surf, 1, 1, 1, 0.5)


class Circles(object):
	"""A graphic that's made from repeated calls to pygame.draw.circles"""
	def __init__(self):
		self.cache = {}
		self.imgcache = {}
	
	
	def getargs(self, *args):
		"""Return a sequence that's in the same order as the args to getkey
Example #8
0
 def alphacopy(self):
     """Copy from pixel data in the blue surface to the alpha
     channel of the main surface"""
     pixels_alpha(
         self.surf)[:, :] = 255 - pygame.surfarray.array2d(self.blue)
Example #9
0
	def alphacopy(self):
		"""
		Copy from pixel data in the blue surface to the alpha
		channel of the main surface
		"""
		pixels_alpha(self.surf)[:,:] = 255 - pygame.surfarray.array2d(self.blue)
Example #10
0
def filtersurface(surf, x, y, z, a=1):
    arr = pygame.surfarray.pixels3d(surf)
    if x != 1: arr[..., 0] *= x
    if y != 1: arr[..., 1] *= y
    if z != 1: arr[..., 2] *= z
    if a != 1: pixels_alpha(surf)[:] *= a
Example #11
0
    if y != 1: arr[..., 1] *= y
    if z != 1: arr[..., 2] *= z
    if a != 1: pixels_alpha(surf)[:] *= a


def filtercolorsurface(surf, (x0, y0, z0, a0), (x1, y1, z1, a1)=(0, 0, 0, 0),
                       (x2, y2, z2, a2)=(0, 0, 0, 0)):
    arr = pygame.surfarray.pixels3d(surf)
    r = arr[..., 0] * x0 + arr[..., 1] * x1 + arr[..., 2] * x2
    g = arr[..., 0] * y0 + arr[..., 1] * y1 + arr[..., 2] * y2
    b = arr[..., 0] * z0 + arr[..., 1] * z1 + arr[..., 2] * z2
    arr[..., 0] = r
    arr[..., 1] = g
    arr[..., 2] = b
    # TODO: what to do about transparency here??
    if a0 != 1: pixels_alpha(surf)[:] *= a0


def maketransparent(surf):
    filtersurface(surf, 1, 1, 1, 0.5)


class Circles(object):
    """A graphic that's made from repeated calls to pygame.draw.circles"""
    def __init__(self):
        self.cache = {}
        self.imgcache = {}

    def getargs(self, *args):
        """Return a sequence that's in the same order as the args to getkey
        and getcircles, with all the defaults filled in"""