fd
qweqrimport pygame
import sys
import random
pygame.init()
size = width, height = 640, 480
black = (0, 0, 0)
white = (255, 255, 255)
class Object():
''' The very generic class '''
count = 0
__private = 20
def __init__(self, coord = None):
self.x = coord[0] if coord else random.random() * width
self.y = coord[1] if coord else random.random() * height
self.size = random.randint(40,150)
self.image = pygame.image.load("/home/user/Documents/pr.png")
self.image = pygame.transform.scale(self.image,(self.size,self.size))
self.__class__.count += 1
def draw(self, screen):
screen.blit(self.image,(self.x - self.size/2.0, self.y - self.size/2.0,self.size, self.size))
# pygame.draw.rect(screen, self.color,
# (self.x - self.size/2.0, self.y - self.size/2.0,
# self.size, self.size))
class Movable(Object):
def __init__(self, coord = None):
Object.__init__(self, coord)
self.vector = (
random.choice((-1,1)) * random.random(),
random.choice((-1,1)) * random.random())
def move(self):
self.x += self.vector[0]
self.y += self.vector[1]
if self.x < 0: self.x = width
if self.y < 0: self.y = height
if self.x > width: self.x = 0
if self.y > height: self.y = 0
clock = pygame.time.Clock()
screen = pygame.display.set_mode(size)
m_rects = [Movable() for i in xrange(15)]
print Object.count
# while True:
# screen.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255)))
# clock.tick(1)
r = 20
g = 65
b = 210
down = True
downg = True
downb = True
while True:
if r < 254 and down == True:
r += 1
if r == 253:
down = False
else:
r -= 1
if r == 2:
down = True
if g < 254 and downg == True:
g += 1
if g == 253:
downg = False
else:
g -= 1
if g == 2:
downg = True
if b < 254 and downb == True:
b += 1
if b == 253:
downb = False
else:
b -= 1
if b == 2:
downb = True
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
screen.fill((r,g,b))
for obj in m_rects:
obj.move()
obj.draw(screen)
pygame.display.flip()
clock.tick(60)