tags:

views:

600

answers:

3

I am trying to create an application like the one here:

http://www.eigenfaces.com/

Basically lots of overlapping circles drawn with pygame. I cannot figure out how the blend the circles to make them translucent. That is to have overlapping colors show through. My code so far is this:

import sys, random, time
import pygame
from pygame.locals import *
from pygame import draw

rand = random.randint

pygame.init( )

W = 320
H = 320
size = (W, H)

screen = pygame.display.set_mode(size)

run = True
while 1:

    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN: 
            if event.key == pygame.K_SPACE :
                run = not run
            else:
                sys.exit()
    if run:
        xc = rand(1, W)
        yc = rand(1, H)
        rc = rand(1, 25)

        red = rand(1, 255)
        grn = rand(1, 255)
        blu = rand(1, 255)

        draw.circle(screen, (red, grn, blu, 200), (xc, yc), rc, 0)

        pygame.display.flip()
+2  A: 

I got it to work by drawing to a surface that is not the display and combining the set colorkey and set alpha functions.

import pygame
from pygame.locals import *

TRANSPARENT = (255,0,255)
pygame.init()
screen = pygame.display.set_mode((500,500))

surf1 = pygame.Surface((200,200))
surf1.fill(TRANSPARENT)
surf1.set_colorkey(TRANSPARENT)
pygame.draw.circle(surf1, (0,0,200,100),(100,100), 100)

surf2 = pygame.Surface((200,200))
surf2.fill(TRANSPARENT)
surf2.set_colorkey(TRANSPARENT)
pygame.draw.circle(surf2, (200,0,0,100),(100,100), 100)

surf1.set_alpha(100)
surf2.set_alpha(100)

while True:
    screen.fill((255,255,255))

    for event in pygame.event.get():
         if event.type == QUIT:
      pygame.quit()

    screen.blit(surf1, (100,100,100,100))
    screen.blit(surf2, (200,200,100,100))
    pygame.display.flip()

P.S There's also the blend flags that you can put in the blit() arguments: Pygame.org - Surface.blit

Sir Oddfellow
+1  A: 

Hi. I am Dave. Creator of the images at eigenfaces.com. Good luck with your experiments. I am looking at posting the code at some point soon. I just need to clean it up first. It's kind of a mess. I'll post back with a link when I do.

By the way.. I have also experimented with movies... Here is about 20 frames with about 1000 generations each:

http://www.eigenfaces.com/img/morphs/anim-100x20.gif

A: 

FYI, I posted the code here:

http://www.eigenfaces.com/

Let me know if it's of use.