dynamic_background.py 565 B

12345678910111213141516171819202122232425
  1. import random
  2. class DynamicBackground():
  3. def __init__(self):
  4. self.current=[0,0,0]
  5. self.target=[0,0,0]
  6. for x in range(0, 3):
  7. self.target[x]=random.randint(0,255)
  8. def drawBackground(self,surface):
  9. same = True
  10. for x in range(0, 3):
  11. if self.current[x]> self.target[x]:
  12. self.current[x]=self.current[x]-1
  13. elif self.current[x]<self.target[x]:
  14. self.current[x]=self.current[x]+1
  15. if(self.current != self.target):
  16. same = False
  17. if same:
  18. for x in range(0, 3):
  19. self.target[x]=random.randint(0,255)
  20. surface.fill(self.current)