gpt4 book ai didi

python - 如何使用 alpha channel 给 png 图像着色?

转载 作者:太空宇宙 更新时间:2023-11-04 04:20:15 25 4
gpt4 key购买 nike

<分区>

我正在尝试编写典型的 DVD 弹跳屏幕保护程序。我对此很满意,但每次它撞到墙上时我都想更改 Logo 的颜色。我使用了 fill(),但 Logo 变为彩色矩形。我想根据图像的 alpha channel 更改 Logo 的颜色。

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()

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com