所以我使用pygame制作绘画程序。我已经加载了色谱,我应该点击鼠标。除此之外,我不太确定如何使用.get_at找出颜色,我不确定如何改变颜色。
到目前为止我的代码是:
color = []
color = ((0,0,0))
running = True
while running:
mb = mouse.get_pressed()
mx,my = mouse.get_pos()
if mb[0] == 1 and palette.collidepoint(mx,my):
color = screen.get_at((mx,my))
color.append()
每次点击我的调色板,我的颜色
答案 0 :(得分:1)
import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640,480])
mousepressed = False
color = (0,0,0,255)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousepressed = True
if event.type == pygame.MOUSEBUTTONUP:
mousepressed = False
if mousepressed:
screen.set_at(pygame.mouse.get_pos(),color)
pygame.display.flip()
抱歉,匆忙,希望这有帮助!
答案 1 :(得分:0)
mouseState = mouse.get_pressed()
mx, my = mouse.get_pos()
if mouseState[0]:
color = screen.get_at((mx, my))
# color is a Color object
# Do some color manipulation by using Color.r, Color.g, Color.b, and Color.a
# For example Color.r = 25
# And at last...
screen.set_at((mx, my), color)
这就是你想要的吗?阅读文档以了解Color.r等的值是什么。