def __init__(self, point1 = None, point2 = None, slab = None): # Huaicai 4/23/05: added some comments below to help understand the code. if slab: # convert from 2d (x, y) coordinates into its 3d world (x, y, 0) #coordinates(the lower-left and upper-right corner). #In another word, the 3d coordinates minus the z offset of the plane x = dot(A(point1), A(point2)) # Get the vector from upper-right point to the lower-left point dx = subtract.reduce(x) # Get the upper-left and lower right corner points oc = x[1] + V(point2[0]*dot(dx,point2[0]), point2[1]*dot(dx,point2[1])) # Get the four 3d cooridinates on the bottom cookie-cutting plane sq1 = cat(x,oc) + slab.normal*dot(slab.point, slab.normal) # transfer the above 4 3d coordinates in parallel to get that on #the top plane, put them together sq1 = cat(sq1, sq1+slab.thickness*slab.normal) self.data = V(maximum.reduce(sq1), minimum.reduce(sq1)) elif point2: # just 2 3d points self.data = V(maximum(point1, point2), minimum(point1, point2)) elif point1: # list of points: could be 2d or 3d? +/- 1.8 to make the bounding #box enclose the vDw ball of an atom? self.data = V(maximum.reduce(point1) + BBOX_MARGIN, minimum.reduce(point1) - BBOX_MARGIN) else: # a null bbox self.data = None
def __init__(self, point1=None, point2=None, slab=None): # Huaicai 4/23/05: added some comments below to help understand the code. if slab: # convert from 2d (x, y) coordinates into its 3d world (x, y, 0) #coordinates(the lower-left and upper-right corner). #In another word, the 3d coordinates minus the z offset of the plane x = dot(A(point1), A(point2)) # Get the vector from upper-right point to the lower-left point dx = subtract.reduce(x) # Get the upper-left and lower right corner points oc = x[1] + V(point2[0] * dot(dx, point2[0]), point2[1] * dot(dx, point2[1])) # Get the four 3d cooridinates on the bottom cookie-cutting plane sq1 = cat(x, oc) + slab.normal * dot(slab.point, slab.normal) # transfer the above 4 3d coordinates in parallel to get that on #the top plane, put them together sq1 = cat(sq1, sq1 + slab.thickness * slab.normal) self.data = V(maximum.reduce(sq1), minimum.reduce(sq1)) elif point2: # just 2 3d points self.data = V(maximum(point1, point2), minimum(point1, point2)) elif point1: # list of points: could be 2d or 3d? +/- 1.8 to make the bounding #box enclose the vDw ball of an atom? self.data = V( maximum.reduce(point1) + BBOX_MARGIN, minimum.reduce(point1) - BBOX_MARGIN) else: # a null bbox self.data = None
def make_shadow(image, ambience=None): """Return a shadow representation of image for a given ambient lighting image - foreground image. ambience (optional) - 0.0 to 1.0: Ambient light ratio. 0.0 gives a totally black shadow while 1.0 gives no shadow. Defaults to 0.0 . """ if ambience is None: ambience = 0.0 elif not (0.0 <= ambience <= 1.0): raise ValueError("ambience must be between 0.0 and 1.0 inclusive") if image.get_masks()[3] != 0: image_alpha = pygame.surfarray.pixels_alpha(image) if ambience > 0.0: shadow_alpha = (image_alpha * (1.0 - ambience)).astype(uint8) else: shadow_alpha = image_alpha elif image.get_colorkey() is not None: image_alpha = pygame.surfarray.array_colorkey(image) image.unlock(); image.unlock() # pygame 1.7 bug (fixed in 1.8). surface_alpha = image.get_alpha() if surface_alpha is not None: # Do what array_colorkey should have done: use surface alpha! minimum(image_alpha, surface_alpha, image_alpha) if ambience > 0.0: shadow_alpha = (image_alpha * (1.0 - ambience)).astype(uint8) else: shadow_alpha = image_alpha else: image_alpha = image.get_alpha() if image_alpha is None: image_alpha = 255 shadow_alpha = int(image_alpha * (1.0 - ambience)) shadow = image.convert_alpha() shading = pygame.Surface(shadow.get_size(), pygame.SRCALPHA, 32) pygame.surfarray.pixels_alpha(shading)[...] = image_alpha shadow.blit(shading, (0, 0)) pygame.surfarray.pixels_alpha(shadow)[...] = shadow_alpha return shadow
def blit_tinted(surface, image, pos, tint, src_rect=None): from Numeric import add, minimum from pygame.surfarray import array3d, pixels3d if src_rect: image = image.subsurface(src_rect) buf = Surface(image.get_size(), SRCALPHA, 32) buf.blit(image, (0, 0)) src_rgb = array3d(image) buf_rgb = pixels3d(buf) buf_rgb[...] = minimum(255, add(tint, src_rgb)).astype('b') surface.blit(buf, pos)
def blit_tinted(surface, image, pos, tint, src_rect=None): from Numeric import array, add, minimum from pygame.surfarray import array3d, pixels3d if src_rect: image = image.subsurface(src_rect) buf = Surface(image.get_size(), SRCALPHA, 32) buf.blit(image, (0, 0)) src_rgb = array3d(image) buf_rgb = pixels3d(buf) buf_rgb[...] = minimum(255, add(tint, src_rgb)).astype('b') buf_rgb = None surface.blit(buf, pos)
def isin(self, pt): return (minimum(pt,self.data[1]) == self.data[1] and maximum(pt,self.data[0]) == self.data[0])
def isin(self, pt): return (minimum(pt, self.data[1]) == self.data[1] and maximum(pt, self.data[0]) == self.data[0])