Ejemplo n.º 1
0
    def __init__(self,
                 size=None,
                 color=None,
                 pressed=False,
                 dark=None,
                 hovered=False,
                 light=None,
                 thick=1,
                 clip="auto"):
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        BasicFrame.__init__(self,
                            size=size,
                            color=color,
                            clip=clip,
                            pressed=pressed,
                            hovered=hovered)
        self.dark = dark
        self.light = light
        self.thick = thick
        self.light = style.LIGHT_FACTOR if light is None else light
        self.dark = style.DARK_FACTOR if dark is None else dark
        ##        if self.light is None:
        ##            white = make_compatible(constants.WHITE, self.color)
        ##            self.light = mid_color(self.color, white)
        if isinstance(self.light, float):
            self.light = normalize_color(grow_color(self.light, self.color))
##        if self.dark is None:
##            black = make_compatible(constants.BLACK, self.color)
##            self.dark = mid_color(self.color, black)
        if isinstance(self.dark, float):
            self.dark = normalize_color(grow_color(self.dark, self.color))
Ejemplo n.º 2
0
 def __init__(self,
              size=style.SIZE,
              color=style.DEF_COLOR,
              pressed=False,
              hovered=False,
              clip="auto",
              dark=None,
              light=None,
              thick=2):
     if clip is "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     BasicFrame.__init__(self,
                         size=size,
                         color=color,
                         clip=clip,
                         pressed=pressed,
                         hovered=hovered)
     self.light = style.LIGHT_FACTOR if light is None else light
     self.dark = style.DARK_FACTOR if dark is None else dark
     if isinstance(self.light, float):
         self.light = normalize_color(grow_color(self.light, self.color))
     if isinstance(self.dark, float):
         self.dark = normalize_color(grow_color(self.dark, self.color))
     self.thick = thick
Ejemplo n.º 3
0
    def __init__(self, size=None, color=None, pressed=False, dark=None,
                 hovered=False, light=None, thick=1, clip="auto"):
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        BasicFrame.__init__(self,
                            size=size,
                            color=color,
                            clip=clip,
                            pressed=pressed,
                            hovered=hovered)
        self.dark = dark
        self.light = light
        self.thick = thick
        self.light = style.LIGHT_FACTOR if light is None else light
        self.dark = style.DARK_FACTOR if dark is None else dark
##        if self.light is None:
##            white = make_compatible(constants.WHITE, self.color)
##            self.light = mid_color(self.color, white)
        if isinstance(self.light, float):
            self.light = normalize_color(grow_color(self.light, self.color))
##        if self.dark is None:
##            black = make_compatible(constants.BLACK, self.color)
##            self.dark = mid_color(self.color, black)
        if isinstance(self.dark, float):
            self.dark = normalize_color(grow_color(self.dark, self.color))
Ejemplo n.º 4
0
 def build_collision_matrix(self):
     global fn_colors, fn_debris
     colors = self.fn in fn_colors
     do_colors = not (colors)
     w, h = self.img.get_size()
     ck = self.img.get_colorkey()
     r, g, b, n = 0, 0, 0, 0
     for x in range(w):
         for y in range(h):
             col = self.img.get_at((x, y))
             if col != ck:
                 self.collisions[x][y] = True
                 if do_colors:
                     r += col[0]
                     g += col[1]
                     b += col[2]
                     n += 1
     if do_colors:
         self.color = (r // n + 20, g // n + 20, b // n + 20)
         self.color = normalize_color(self.color)
         self.debris = thorpy.fx.get_debris_generator(duration=50,
                                                      color=self.color,
                                                      max_size=8)
         fn_colors[self.fn] = self.color
         fn_debris[self.fn] = self.debris
     else:
         self.color = fn_colors[self.fn]
         self.debris = fn_debris[self.fn]
Ejemplo n.º 5
0
def illuminate_color_except(surface, color_except, color_target, color_bulk=None,
                            subrect=None, factor=1., fadout=2):
    """
    mode : "except" means all the pixels that are not color_source.
           "exact" means all the pixels that are exacly color_source.
    """
    if not HAS_NUMPY:
        raise Exception("Could not use surfarray module from PyGame.\
                     NumPy is probably missing.")
    rect = surface.get_rect()
    newsurf = pygame.Surface(rect.size, depth=surface.get_bitsize()).convert()
    newsurf.blit(surface, (0, 0))
    if subrect:
        rect = subrect
    arrayrgb = surfarray.pixels3d(newsurf)
    points = []
    max_d = hypot(rect.w, rect.h)
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if tuple(arrayrgb[x][y]) != color_except:
                points.append((x, y))
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if not (x, y) in points:
                d = 1. - illuminate_dist(points, rect, x, y) / max_d
                d = d**fadout
                color = grow_color(factor * d, color_target)
                color = normalize_color(color)
                arrayrgb[x][y] = color
            elif color_bulk:
                arrayrgb[x][y] = color_bulk
    return newsurf
Ejemplo n.º 6
0
    def __init__(self, size=None, color=None, clip="auto", radius_ext=None,
                 radius_int=None, pressed=False, dark=None, light=None, thick=1,
                 hovered=False, border_color=None): #changer border
        """If radius is in the range [0, 1], self.radius_value is the fraction
        of radius * min(size), else it is interpreted as a raw pixel value.
        """
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        ClassicFrame.__init__(self,
                              size=size,
                              color=color,
                              pressed=pressed,
                              hovered=hovered,
                              dark=dark,
                              light=light,
                              thick=thick,
                              clip=clip)
        radius_value = style.DEF_RADIUS if radius_ext is None else radius_ext
        if 0. <= radius_value <= 1.:
            radius_value = min(self.size) * radius_value
        self.radius_ext = radius_value
        self.radius_int = radius_int
        if radius_int == None:
            self.radius_int = self.radius_ext - self.thick

        self.border_color = style.BORDER_FACT if border_color is None else border_color
        if isinstance(self.border_color, float):
            self.border_color = normalize_color(grow_color(self.border_color,
                                                           self.color))
Ejemplo n.º 7
0
def illuminate_color_except(surface, color_except, color_target, color_bulk=None,
                            subrect=None, factor=1., fadout=2):
    """
    mode : "except" means all the pixels that are not color_source.
           "exact" means all the pixels that are exacly color_source.
    """
    if not HAS_NUMPY:
        raise Exception("Could not use surfarray module from PyGame.\
                     NumPy is probably missing.")
    rect = surface.get_rect()
    newsurf = pygame.Surface(rect.size, depth=surface.get_bitsize()).convert()
    newsurf.blit(surface, (0, 0))
    if subrect:
        rect = subrect
    arrayrgb = surfarray.pixels3d(newsurf)
    points = []
    max_d = hypot(rect.w, rect.h)
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if tuple(arrayrgb[x][y]) != color_except:
                points.append((x, y))
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if not (x, y) in points:
                d = 1. - illuminate_dist(points, rect, x, y) / max_d
                d = d**fadout
                color = grow_color(factor * d, color_target)
                color = normalize_color(color)
                arrayrgb[x][y] = color
            elif color_bulk:
                arrayrgb[x][y] = color_bulk
    return newsurf
Ejemplo n.º 8
0
 def __init__(self, size=style.SIZE, color=style.DEF_COLOR, clip="auto",
              dark=None, light=None, thick=2, pressed=False, hover=False):
     if clip is "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     BasicFrame.__init__(self,
                         size=size,
                         color=color,
                         clip=clip,
                         pressed=pressed,
                         hovered=hovered)
     self.light = style.LIGHT_FACTOR if light is None else light
     self.dark = style.DARK_FACTOR if dark is None else dark
     if isinstance(self.light, float):
         self.light = normalize_color(grow_color(self.light, self.color))
     if isinstance(self.dark, float):
         self.dark = normalize_color(grow_color(self.dark, self.color))
     self.thick = thick
Ejemplo n.º 9
0
 def __init__(self, size=None, color=None, clip="auto", radius_ext=12,
              radius_int=10, pressed=False, dark=None, light=None, thick=1,
              border_color=None): #changer border
     """Radius = [0, 1]"""
     if clip == "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     ClassicFrame.__init__(self, size, color, pressed, dark, light, thick,
                           clip)
     self.radius_int = radius_int
     self.radius_ext = radius_ext
     self.border_color = style.BORDER_FACT if border_color is None else border_color
     if isinstance(self.border_color, float):
         self.border_color = normalize_color(grow_color(self.border_color,
                                                        self.color))
Ejemplo n.º 10
0
    def __init__(self,
                 size=None,
                 color=None,
                 clip="auto",
                 radius_ext=None,
                 radius_int=None,
                 pressed=False,
                 dark=None,
                 light=None,
                 thick=1,
                 hovered=False,
                 border_color=None):  #changer border
        """If radius is in the range [0, 1], self.radius_value is the fraction
        of radius * min(size), else it is interpreted as a raw pixel value.
        """
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        ClassicFrame.__init__(self,
                              size=size,
                              color=color,
                              pressed=pressed,
                              hovered=hovered,
                              dark=dark,
                              light=light,
                              thick=thick,
                              clip=clip)
        radius_value = style.DEF_RADIUS if radius_ext is None else radius_ext
        if 0. <= radius_value <= 1.:
            radius_value = min(self.size) * radius_value
        self.radius_ext = radius_value
        self.radius_int = radius_int
        if radius_int == None:
            self.radius_int = self.radius_ext - self.thick

        self.border_color = style.BORDER_FACT if border_color is None else border_color
        if isinstance(self.border_color, float):
            self.border_color = normalize_color(
                grow_color(self.border_color, self.color))
 def __init__(self,
              size=None,
              color=None,
              clip="auto",
              radius_ext=12,
              radius_int=10,
              pressed=False,
              dark=None,
              light=None,
              thick=1,
              border_color=None):  #changer border
     """Radius = [0, 1]"""
     if clip == "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     ClassicFrame.__init__(self, size, color, pressed, dark, light, thick,
                           clip)
     self.radius_int = radius_int
     self.radius_ext = radius_ext
     self.border_color = style.BORDER_FACT if border_color is None else border_color
     if isinstance(self.border_color, float):
         self.border_color = normalize_color(
             grow_color(self.border_color, self.color))