I'm trying to code the typical dvd bouncing screensaver. I am happy with it but I want to change the color of the logo everytime it hits the wall. I have used fill(), but the logo changes to a colored rectangle. I want to change the color of the logo, respecting the alpha channel of the image.
from pygame import *
import random
#set canvas size variables
width = 700
height = 450
#draw canvas
screen = display.set_mode((width,height))
display.set_caption('Graphics')
#initial XY coordinates where game starts
x = random.randint(1, width)
y = random.randint(1, height)
#import logo
logo_img = image.load('dvd_logo_alpha.png')
R = 255
G = 255
B = 255
def logo(x,y):
screen.blit(logo_img, (x,y))
def Col():
R = random.randint(100,255)
G = random.randint(100,255)
B = random.randint(100,255)
#speed of the logo
dx = 3
dy = 3
endProgram = False
while not endProgram:
for e in event.get():
if e.type == QUIT:
endProgram = True
#speed changes position XY
x += dx
y += dy
#detection of collision with border of screen
if y<0 or y>height-47:
dy *= -1
R = random.randint(100,255)
G = random.randint(100,255)
B = random.randint(100,255)
if x<0 or x>width-100:
dx *= -1
R = random.randint(100,255)
G = random.randint(100,255)
B = random.randint(100,255)
screen.fill((0))
logo_img.fill((R,G,B)) #here is the problem I can not solve
logo(x,y)
display.update()