Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:33:08+00:00 2026-06-14T17:33:08+00:00

So I’m experimenting in pygame and wrote some code for a rectangle that slowly

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:33:09+00:00Added an answer on June 14, 2026 at 5:33 pm

    I would expect a ValueError instead of a TypeError, but it looks like what’s happening is that if we take a = 4 and work with color[0]

    • color[0] == 250, so gets changed to 254
    • color[0] == 254, so stays the same, a gets changed to -4
    • color[0] == 254, so gets changed to 250
    • … keeps substracting 4….

    And I’m not sure -4 is a valid colour…

    maybe look at using

    >>> from itertools import izip, cycle
    >>> a = range(0, 20, 4) + range(20, 0, -4)
    >>> b = range(0, 20, 3) + range(20, 0, -3)
    >>> c = range(0, 20, 2) + range(20, 0, -2)
    >>> test = izip(cycle(a), cycle(b), cycle(c))
    >>> for i in range(30):
        print next(test)
    
    (0, 0, 0)
    (4, 3, 2)
    (8, 6, 4)
    (12, 9, 6)
    (16, 12, 8)
    (20, 15, 10)
    (16, 18, 12)
    (12, 20, 14)
    (8, 17, 16)
    (4, 14, 18)
    (0, 11, 20)
    (4, 8, 18)
    (8, 5, 16)
    (12, 2, 14)
    (16, 0, 12)
    (20, 3, 10)
    (16, 6, 8)
    (12, 9, 6)
    (8, 12, 4)
    (4, 15, 2)
    (0, 18, 0)
    (4, 20, 2)
    (8, 17, 4)
    (12, 14, 6)
    (16, 11, 8)
    (20, 8, 10)
    (16, 5, 12)
    (12, 2, 14)
    (8, 0, 16)
    (4, 3, 18)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.