So I’m experimenting in pygame and wrote some code for a rectangle that slowly changes color
a = 4
b = 3
c = 2
#some irrelevant code later
if color[0]+a < 255:
color[0] += a
else:
a *= -1
if color[1]+b < 255:
color[1] += b
else:
b *= -1
if color[2]+c < 255:
color[2] += c
else:
c *= -1
a, b, and c as the speed of change for red, green, and, blue.
The problem is that for some reason it will give me a TypeError: Invalid color argument after a few seconds of the program running, usually when the color is very blue. I don’t see any reason an invalid color argument would appear.
I would expect a
ValueErrorinstead of aTypeError, but it looks like what’s happening is that if we takea = 4and work withcolor[0]color[0]== 250, so gets changed to254color[0]== 254, so stays the same,agets changed to-4color[0]== 254, so gets changed to2504….And I’m not sure -4 is a valid colour…
maybe look at using