# Dot Fountain screen hack 0.0.2 # Copyright 2003 Lja MultiMedia # May be used under the GNU GPL import pygame, pygame.draw from vectors import vector from random import randrange, random def polar2cartesian(coords): return 'FIXME' def cartesian2polar(coords): d = vectors.distance(coords) a = 'FIXME' def random_color(brightness=256): rf = random() gf = random() * (1 - rf) bf = 1 - rf - gf r = min(255, int(rf * brightness)) g = min(255, int(gf * brightness)) b = min(255, int(bf * brightness)) return r, g, b class particle: def __init__(self, p, v, a): self.p = vector(p) self.v = vector(v) self.a = vector(a) def __repr__(self): return '' % self.__dict__ def move(self): self.v += self.a self.p += self.v def draw(self, surface): pygame.draw.circle(surface, (255, 255, 255), self.p, 1) class hack: def __init__(self, min, max): self.min = min self.max = max self.size = max - min def __float__(self): return self.min + random() * self.size def __int__(self): return randrange(self.min, self.max) class generator: def __init__(self, px, py, vx, vy, ax, ay): self.px = px self.py = py self.vx = vx self.vy = vy self.ax = ax self.ay = ay def particle(self): p = float(self.px), float(self.py) v = float(self.vx), float(self.vy) a = float(self.ax), float(self.ay) return particle(p, v, a) def __test(full=0): if full: mode = 1024, 768 options = pygame.FULLSCREEN | pygame.DOUBLEBUF else: mode = 800, 600 options = pygame.DOUBLEBUF g = generator(mode[0] / 2, mode[1], hack(-10, 11), hack(-40, -29), 0, 1) pygame.init() screen = pygame.display.set_mode(mode, options) particles = [] done = 0 while not done: for event in pygame.event.get(): if event.type in (pygame.QUIT, pygame.KEYUP): done = 1 screen.fill((0, 0, 0)) for i in range(randrange(10,21)): particles.append(g.particle()) for p in particles[:]: p.draw(screen) p.move() if p.p[0] < 0 or p.p[0] > mode[0] or p.p[1] < 0 or p.p[1] > mode[1]: particles.remove(p) pygame.display.flip() if __name__ == '__main__': __test()