彩色Pygame整数?

时间:2014-10-05 10:52:29

标签: python colors integer pygame gradient

嗨我正试图在Pygame中制作一个黑色的白色渐变,它从表面的开始到结束都很好,但是当我尝试在一些像素之后开始

from pygame import gfxdraw 

surf = pygame.Surface([256,16], pygame.SRCALPHA, 32)

screen.blit(surf,(0,0))

for y in range(0,16,1):
    for x in range(0,256,1):
        colPos = [0.25,1]
        rG = int(1/(colPos[1]-colPos[0])*x)
        gG = int(1/(colPos[1]-colPos[0])*x)
        bG = int(1/(colPos[1]-colPos[0])*x)
        gfxdraw.pixel(surf, x, y, (rG,gG,bG,255))

但它告诉我:

Traceback (most recent call last):
File "C:\Users\Name\Desktop\game.py", line 76, in <module>
gfxdraw.pixel(surf4, x, y, (rG,gG,bG,255))
TypeError: invalid color argument

我的意思是它是一个整数,为什么会出现错误?

1 个答案:

答案 0 :(得分:1)

因为x的值大于或等于192int(1/(colPos[1]-colPos[0])*x)的结果大于255,因此不是有效参数。

>>> for x in range(190, 195):
    print x, int(x / 0.75) # I simplified the equation


190 253
191 254
192 256
193 257
194 258