[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] surfarray & alpha
Hi Pete,
That doesn't seem to work for me. Here's a version along the lines of
what you suggested (the surface being changed is a 32bit surface
generated by a call to convert_alpha() ("<Surface(100x31x32 SW)>"):
def alpha_gradient(self, r1, r2, x=0, y=0):
x0 = arange(0, self.w)-(self.w/2)-x
y0 = arange(0, self.h)-(self.h/2)+y
x = transpose(resize(x0, (self.h, len(x0))))
y = resize(y0, (self.w, len(y0)))
d = 255 - (255 * ((((x**2)+(y**2))**0.5)-r1) / (r2-r1))
d = where(less(d, 0), 0, where(greater(d, 255), 255, d)).astype(Int)
a0 = pygame.surfarray.pixels_alpha(self.im)
print d.shape, a0.shape, type(a0[1][1]), type(d[1][1])
a0[:] = d
'a0' and 'd' are the same size and type, but I get this error when
I run it:
>...
> (100, 31) (100, 31) <type 'int'> <type 'int'>
> Traceback (innermost last):
> File "sprite.py", line 669, in ?
> i.alpha_gradient(25, 50, 0, 0)
> File "sprite.py", line 358, in alpha_gradient
> a0[:] = d
> TypeError: Array can not be safely cast to required type
>...
Oddly enough, the type(a0[0,0]) == <type 'array'>, while
type(d[0,0]) == <type 'int'>. Any idea why this is the case?
Shouldn't a0[0,0] be an 'int'? I suspect this is the origin of
the error message, but I don't understand why there's a type
mismatch, unless pixels_alpha() returns a 2D array of arrays?
/jamie
--
office: 510-643-3573 mail: 3210 Tolman Hall #1650
lab: 510-642-1950 U.C. Berkeley
fax: 801-697-4179 Berkeley, CA 94720-1650
email: mazer@socrates.berkeley.edu
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org