Beispiel #1
0
def get_aa_round_rect(size, radius, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    rectangle = Surface(size, SRCALPHA)
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([min(size) * 5, min(size) * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, (2*radius, 2*radius))
    #now circle is just a small circle of radius
    #blit topleft circle:
    radius_rect = rectangle.blit(circle, (0, 0))
    #now radius_rect = Rect((0, 0), circle.size), rect=Rect((0, 0), size)
    #blit bottomright circle:
    radius_rect.bottomright = rect.bottomright #radius_rect is growing
    rectangle.blit(circle, radius_rect)
    #blit topright circle:
    radius_rect.topright = rect.topright
    rectangle.blit(circle, radius_rect)
    #blit bottomleft circle:
    radius_rect.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius_rect)
    #black-fill of the internal rect
    rectangle.fill((0, 0, 0), rect.inflate(-radius_rect.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius_rect.h))
    #fill with color using blend_rgba_max
    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    #the
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    surface.blit(rectangle, rect.topleft)
    return surface
Beispiel #2
0
 def draw(self):
     surface = Surface(self.size, flags=SRCALPHA).convert_alpha()
     rect = Rect((0, 0), self.size)
     color = Color(*self.color)
     alpha = color.a
     color.a = 0
     rectangle = Surface(rect.size, SRCALPHA)
     #ex: [h*3, h*3]
     circle = Surface([min(rect.size) * 5] * 2, SRCALPHA)
     draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)
     #ex: [h*0.5, h*.05]
     circle = transform.smoothscale(circle, [int(self.radius_value)] * 2)
     #now circle is just a small circle of radius self.radius*h (for example)
     #blit topleft circle:
     radius = rectangle.blit(circle, (0, 0))
     #now radius = Rect((0, 0), circle.size), rect=Rect((0, 0), self.size)
     #blit bottomright circle:
     radius.bottomright = rect.bottomright  #radius is growing
     rectangle.blit(circle, radius)
     #blit topright circle:
     radius.topright = rect.topright
     rectangle.blit(circle, radius)
     #blit bottomleft circle:
     radius.bottomleft = rect.bottomleft
     rectangle.blit(circle, radius)
     #black-fill of the internal rect
     rectangle.fill((0, 0, 0), rect.inflate(-radius.w, 0))
     rectangle.fill((0, 0, 0), rect.inflate(0, -radius.h))
     #fill with color using blend_rgba_max
     rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
     #fill with alpha-withe using blend_rgba_min in order to make transparent
     #the
     rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
     surface.blit(rectangle, rect.topleft)
     return surface
Beispiel #3
0
    def __init__(self):
        '''
        Initialize Akintu graphics engine with default settings
        '''
        self.screen = pygame.display.set_mode((
            PANE_X * TILE_SIZE + 256,
            max(PANE_Y * TILE_SIZE, 20 * TILE_SIZE)))
        pygame.display.set_caption('Akintu r01')
        self.background = pygame.Surface((PANE_X * TILE_SIZE,
                                          PANE_Y * TILE_SIZE))
        self.images = dict()
        self.persons = OrderedDict()
        self.personsgroup = pygame.sprite.RenderUpdates()
        self.playerframes = OrderedDict()
        self.monsterframes = OrderedDict()
        self.scrollcount = 0
        self.textsize = 12
        self.sidetext = []
        self.dialog = None
        self.overlays = {}

        overlay_colors = ['blue', 'green', 'red', 'cyan', 'orange', 'black']
        for c in overlay_colors:
            color = Color(c)
            color.a = 50
            self.overlays[c] = generate_overlay(TILE_SIZE, TILE_SIZE, color)

        pygame.display.flip()
        self.turntime = 0
        self.tile_updated = False

        # Draw the sidebar text area and make sure it has at least one item
        # in it (even though it's a blank item)
        self.show_text('')
Beispiel #4
0
def get_aa_ellipsis(size, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([size[0] * 5, size[1] * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, size)
    #fill with color using blend_rgba_max
    circle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    circle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    return circle
def get_aa_ellipsis(size, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([size[0] * 5, size[1] * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, size)
    #fill with color using blend_rgba_max
    circle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    circle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    return circle
Beispiel #6
0
def AAfilledRoundedRect(surface, rect, color, radius=0.4):
    """
    AAfilledRoundedRect(surface,rect,color,radius=0.4)

    surface : destination
    rect    : rectangle
    color   : rgb or rgba
    radius  : 0 <= radius <= 1
    """

    rect = Rect(rect)
    color = Color(color)
    alpha = color.a
    color.a = 0
    pos = rect.topleft
    rect.topleft = 0, 0
    rectangle = Surface(rect.size, SRCALPHA)

    circle = Surface([min(rect.size) * 3] * 2, SRCALPHA)
    draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, [int(min(rect.size) * radius)] * 2)

    radius = rectangle.blit(circle, (0, 0))
    radius.bottomright = rect.bottomright
    rectangle.blit(circle, radius)
    radius.topright = rect.topright
    rectangle.blit(circle, radius)
    radius.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius)

    rectangle.fill((0, 0, 0), rect.inflate(-radius.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius.h))

    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)

    return surface.blit(rectangle, pos)
Beispiel #7
0
 def draw(self):
     surface = Surface(self.size, flags=SRCALPHA).convert_alpha()
     rect = Rect((0, 0), self.size)
     color = Color(*self.color)
     alpha = color.a
     color.a = 0
     rectangle = Surface(rect.size, SRCALPHA)
     #ex: [h*3, h*3]
     circle = Surface([min(rect.size) * 5] * 2, SRCALPHA)
     draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)
     #ex: [h*0.5, h*.05]
     circle = transform.smoothscale(circle,
                                    [int(self.radius_value)] * 2)
     #now circle is just a small circle of radius self.radius*h (for example)
     #blit topleft circle:
     radius = rectangle.blit(circle, (0, 0))
     #now radius = Rect((0, 0), circle.size), rect=Rect((0, 0), self.size)
     #blit bottomright circle:
     radius.bottomright = rect.bottomright #radius is growing
     rectangle.blit(circle, radius)
     #blit topright circle:
     radius.topright = rect.topright
     rectangle.blit(circle, radius)
     #blit bottomleft circle:
     radius.bottomleft = rect.bottomleft
     rectangle.blit(circle, radius)
     #black-fill of the internal rect
     rectangle.fill((0, 0, 0), rect.inflate(-radius.w, 0))
     rectangle.fill((0, 0, 0), rect.inflate(0, -radius.h))
     #fill with color using blend_rgba_max
     rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
     #fill with alpha-withe using blend_rgba_min in order to make transparent
     #the
     rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
     surface.blit(rectangle, rect.topleft)
     return surface
Beispiel #8
0
def noise(c, amt=8, alpha=None):
    "Add randomness to a color"
    c = Color(*[min(255, max(0, val + randint(-amt, amt))) for val in c])
    if alpha is not None: c.a = alpha
    return c
def get_aa_round_rect(size, radius, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    rectangle = Surface(size, SRCALPHA)
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([min(size) * 5, min(size) * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, (2*radius, 2*radius))
    #now circle is just a small circle of radius
    #blit topleft circle:
    radius_rect = rectangle.blit(circle, (0, 0))
    #now radius_rect = Rect((0, 0), circle.size), rect=Rect((0, 0), size)
    #blit bottomright circle:
    radius_rect.bottomright = rect.bottomright #radius_rect is growing
    rectangle.blit(circle, radius_rect)
    #blit topright circle:
    radius_rect.topright = rect.topright
    rectangle.blit(circle, radius_rect)
    #blit bottomleft circle:
    radius_rect.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius_rect)
    #black-fill of the internal rect
    rectangle.fill((0, 0, 0), rect.inflate(-radius_rect.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius_rect.h))
    #fill with color using blend_rgba_max
    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    #the
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    surface.blit(rectangle, rect.topleft)
    return surface