import pygame import pygame.locals import random pygame.init() screen=pygame.display.set_mode((300,300)) pygame.display.set_caption('Fountain') numBalls = 10 gravity = 0.1 class Ball: def __init__(self): self.radius = 5 self.x = 150 self.y = 260 self.vx = random.uniform(-1, 1) self.vy = random.uniform(-7, -3) # https://www.pygame.org/docs/ref/color.html c = pygame.Color(0, 0, 0) # hue saturation lightness alpha c.hsla = (colour, 100, 50, 100) self.color = c; def go(self): # move self.vy += gravity; self.x += self.vx; self.y += self.vy; # fallen off bottom of the screen, fire it off again if self.y > 300: self.__init__() # draw # https://www.pygame.org/docs/ref/draw.html # circle(surface, color, center, radius) pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), self.radius) colour = 0 # make a list of balls listballs = [Ball() for i in range(numBalls)] clock = pygame.time.Clock() running = True while running: # get one event off the event queue # without waiting until there is one event = pygame.event.poll() if event.type == pygame.locals.QUIT: running = False # ignore all other events colour += 1 if colour == 360: colour = 0 # clear screen screen.fill((255,255,255)) # draw all the balls [b.go() for b in listballs] pygame.display.update() # time delay # from the raspberry spoon game # https://www.pygame.org/docs/ref/time.html clock.tick(30) pygame.quit()