コード例 #1
0
def core(_color, growth=0, zoom=settings.tzoom0):
    z = settings.tzoom0
    img = vista.Surface(3 * z)
    if not stalkimages:
        for edge in range(6):
            stalkimg = vista.Surface(2 * z)
            x0, y0 = stalkimg.get_rect().center
            stalkimg.fill((0, 0, 0, 0))
            r, g, b, a = colors["app%s" % (edge % 3)]
            S, C = math.sin(math.radians(
                60 * edge)), -math.cos(math.radians(60 * edge))
            dx, dy = 0.3 * S, 0.3 * C
            segmentcircles.draw(stalkimg, z, (1, 1), (dx, dy), 0.3)
            filtersurface(stalkimg, r, g, b, a)
            stalkimages.append(stalkimg)
    for edge in range(6):
        stalkimg = stalkimages[edge]
        x0, y0 = stalkimg.get_rect().center
        S, C = math.sin(math.radians(60 *
                                     edge)), -math.cos(math.radians(60 * edge))
        dx, dy = 0.3 * S * z, 0.3 * C * z
        dr = min(max(
            (1 - growth) * 4 - 0.2 * (5 - edge), 0), 0.5) if growth != 1 else 0
        x, y = (1.5 + (.65 - dr) * S) * z, (1.5 + (.65 - dr) * C) * z
        img.blit(stalkimg, stalkimg.get_rect(center=(x, y)))
    sphereimg = spherecircles.img(R=0.75, color="core", zoom=z)
    #    return sphereimg
    img.blit(sphereimg, sphereimg.get_rect(center=img.get_rect().center))
    return pygame.transform.smoothscale(img, (3 * zoom, 3 * zoom))
コード例 #2
0
ファイル: mask.py プロジェクト: wolmir/cristina
 def redraw(self):
     """Draw entire surface from scratch"""
     self.surf = vista.Surface(self.sx, self.sy)
     self.surf.fill(self.color)
     self.blue = vista.Surface(self.sx, self.sy)
     self.blue.fill((0, 0, 0))
     for p, r in self.ps:
         self.addcirc(p, r)
     self.alphacopy()
     self.lastrequest = None  # Invalidate the last request
コード例 #3
0
def loadbar(f, color="eye", w=60, h=8):
    if color in colors: color = colors[color]
    r, g, b, _ = color
    color = int(255 * r), int(255 * g), int(255 * b)
    img = vista.Surface(w + 2, h + 2, color)
    if 0 < f < 1:
        img.fill((0, 0, 0), (1 + int(f * w), 1, w - int(f * w), h))
    return img
コード例 #4
0
 def grayimg(self, scale, *args, **kw):
     scale = int(scale)
     drawargs, drawkw = self.getdrawargs(*args, **kw)
     key = scale, self.getdrawkey(drawargs, drawkw)
     if key in self.imgcache: return self.imgcache[key]
     img = vista.Surface(2 * scale)
     offset = (1, 1)
     self.draw(img, scale, offset, *drawargs, **drawkw)
     self.imgcache[key] = img
     return img
コード例 #5
0
 def graytile(self, zoom=settings.tzoom0, *args, **kw):
     key = zoom, self.getdrawkey(*self.getdrawargs(*args, **kw))
     if key in self.imgcache: return self.imgcache[key]
     if zoom == settings.tzoom0:
         img0 = self.grayimg(zoom, *args, **kw)
         img = vista.Surface(2 * zoom)
         img.blit(img0, img0.get_rect(center=(zoom, zoom)))
     else:
         img0 = self.graytile(settings.tzoom0, *args, **kw)
         img = pygame.transform.smoothscale(img0, (2 * zoom, 2 * zoom))
     self.imgcache[key] = img
     return img
コード例 #6
0
def heximg(scale, cache={}):
    if scale in cache: return cache[scale]
    s3 = math.sqrt(3)
    img = vista.Surface(2 * scale)
    spos = lambda x, y: (int(scale * (1 + x) + .5), int(scale * (1 - y) + .5))
    vpos = [(1, 0), (.5, -.5), (-.5, -.5), (-1, 0), (-.5, .5), (.5, .5)]
    vps = [spos(x, s3 * y) for x, y in vpos]  # Vertex positions
    vips = [spos(.92 * x, .92 * s3 * y)
            for x, y in vpos]  # inner vertex positions
    pygame.draw.polygon(img, (128, 128, 128), vps, 0)
    pygame.draw.polygon(img, (64, 64, 64), vips, 0)
    cache[scale] = img
    return img
コード例 #7
0
ファイル: mask.py プロジェクト: wolmir/cristina
 def getcirc(r):
     if r not in Mask.circs:
         # TODO: pygame.surfarray
         img = vista.Surface(2 * r)
         for x in range(2 * r):
             for y in range(2 * r):
                 d2 = float((x - r)**2 + (y - r)**2) / r**2
                 d = math.sqrt(d2)
                 a = max(
                     min(int(255 * 1 / (1 + math.exp(-20 + 24 * d))), 255),
                     0)
                 img.set_at((x, y), (0, 0, 255, a))
         Mask.circs[r] = img
     return Mask.circs[r]
コード例 #8
0
def stalkmeter(height, f=3):
    img = vista.Surface(40 * f, f * height)
    h = height / 60.
    ps = []
    for y in range(int(h) + 1):
        p0 = 0, -y
        p1 = 0.15 * math.sin(y**2), -y - 0.3
        p2 = 0.15 * -math.sin((y + 1)**2), -y - 0.7
        p3 = 0, -y - 1
        ps += cBezier(p0, p1, p2, p3)[:-1]
    stalkcircles.draw(img, 60 * f, (1 / 3., h), ps, width=0.3)
    if f != 1:
        img = pygame.transform.smoothscale(img, (40, height))
    return img
コード例 #9
0
def thoughtbubble(h, w=settings.maxblockwidth, cache={}):
    key = w, h
    if key in cache:
        return cache[key]
    circs = []
    for j in range(int(w * h * 0.05)):
        x = random.uniform(0, w)
        y = random.uniform(0, h)
        z = random.uniform(0.5, 1)
        r = random.uniform(10, 20)
        g = z
        circs.append((z, x, y, r, g))
    circs = normcircles(circs, 1, (20, 20))
    img = vista.Surface(w + 40, h + 40)
    drawgraycircles(img, circs)
    cache[key] = img
    return img
コード例 #10
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]
コード例 #11
0
def icon(name, size=settings.layout.buildiconsize, cache={}):
    key = name, size
    if key in cache:
        return cache[key]
    s = settings.largebuildicon
    img = vista.Surface(s)
    r, g, b, a = colors[mechanics.colors[name]]
    color0 = int(r * 255), int(g * 255), int(b * 255)
    color1 = int(r * 32), int(g * 32), int(b * 32)
    img.fill(color0)
    img.fill(color1, (6, 6, s - 12, s - 12))
    import body
    otype = body.otypes[name]
    part = otype(None, None, (0, 0), 3)
    partimg = part.draw0(zoom=int(s * .6), status="", growth=1)
    img.blit(partimg, partimg.get_rect(center=img.get_rect().center))
    img = pygame.transform.smoothscale(img, (size, size))
    return img
コード例 #12
0
def blocktext(text="", size=32, color=(0, 0, 0), cache={}):
    key = text, size, color
    if key in cache: return cache[key]
    if size not in fonts:
        fonts[size] = pygame.font.Font(data.filepath("suckgolf.ttf"), size)
    text = text.replace("0", "o")
    lines = wrap_multi_line(text, fonts[size])
    imgs = [fonts[size].render(line, True, color) for line in lines]
    if len(imgs) == 1:
        img = imgs[0]
    else:
        w = max(img.get_width() for img in imgs)
        h = max(img.get_height() for img in imgs)
        img = vista.Surface(w, h * len(imgs))
        for j, i in enumerate(imgs):
            r = i.get_rect(midtop=(w / 2, j * h))
            img.blit(i, r)
    cache[key] = img
    return cache[key]
コード例 #13
0
def eyeball(R, edge0=3, blink=1, color=(0, 255, 0), cache={}):
    R = int(R + 0.5)
    blink = int(blink * 20) / 20.
    edge0 = 0 if blink == 1 else edge0 % 3
    key = R, edge0, blink, color
    if key in cache: return cache[key]
    img = vista.Surface(2 * R)
    if blink == 1:
        pygame.draw.circle(img, color, (R, R), int(R * 0.35))
    else:
        rect = pygame.Rect(0, 0, int(R * 0.7), int(R * 0.7 * blink))
        rect.center = R, R
        pygame.draw.ellipse(img, color, rect)
    if blink >= 0.4:
        pygame.draw.circle(img, (0, 0, 0), (R, R), int(R * 0.15))
    if edge0:
        img = pygame.transform.rotozoom(img, -60 * edge0, 1)
    cache[key] = img
    return cache[key]
コード例 #14
0
ファイル: mask.py プロジェクト: wolmir/cristina
        channel of the main surface"""
        pixels_alpha(
            self.surf)[:, :] = 255 - pygame.surfarray.array2d(self.blue)

    def getmask(self, (x0, y0, x1, y1), (sx, sy)):
        """Return a piece of the mask that covers the rectangle of given
        world-coordinate edges and has the given pixel dimensions."""
        px0, py1 = self.worldtomask((x0, y0))
        px1, py0 = self.worldtomask((x1, y1))
        key = px0, py0, px1, py1, sx, sy
        if key == self.lastrequest:
            return self.lastresponse
        if 0 <= px0 and px1 <= self.sx and 0 <= py0 < py1 <= self.sy:
            img = self.surf.subsurface((px0, py0, px1 - px0, py1 - py0))
        else:
            img = vista.Surface(px1 - px0, py1 - py0)
            srect = self.surf.get_rect(topleft=(-px0, -py0))
            img.blit(self.surf, srect)
            if srect.left > 0:
                img.fill(self.color, img.get_rect(right=srect.left))
            if srect.right < img.get_width():
                img.fill(self.color, img.get_rect(left=srect.right))
            if srect.top > 0:
                img.fill(self.color, img.get_rect(bottom=srect.top))
            if srect.bottom < img.get_height():
                img.fill(self.color, img.get_rect(top=srect.bottom))
        img = pygame.transform.smoothscale(img, (sx, sy))
        self.lastrequest, self.lastresponse = key, img
        return img

    @staticmethod
コード例 #15
0
def helixmeter(height, f=3):
    img = vista.Surface(40 * f, f * height)
    helixcircles.draw(img, f, (20, height), (0, -height))
    if f != 1:
        img = pygame.transform.smoothscale(img, (40, height))
    return img
コード例 #16
0
    if key in cache:
        return cache[key]
    if (n, "base") not in cache:
        cache[(n, "base")] = pygame.image.load(
            data.filepath("mouth-%s.png" % n)).convert_alpha()
    img = pygame.transform.smoothscale(cache[(n, "base")], (3 * z, 3 * z))
    cache[key] = img
    return cache[key]


if __name__ == "__main__":
    pygame.init()
    screen = pygame.display.set_mode((400, 400))

    screen.fill((0, 0, 0))
    img = vista.Surface(200)

    if False:
        t0 = pygame.time.get_ticks()
        loadallappimages([60])
        t1 = pygame.time.get_ticks()
        print t1 - t0

    if False:
        circs = [(random.uniform(-100, 100), random.uniform(-100, 100),
                  random.uniform(5, 20), random.uniform(64, 192))
                 for _ in range(2000)]
        circs = [(int(x), int(y), int(r), c) for x, y, r, c in circs
                 if x**2 + y**2 < 100**2]

        for _ in range(10):