Jan-12-2020, 05:53 PM
I'm developing a program that will simply generate all the possible colors if I restrict the rgb values to multiples of 51. Its working out so far, but right now some of my functions generate an infinite loop and I have no clue why. I initially ignored this, but then I opened up taskmanager to find out how much RAM the thing was taking, and I found it was perpetually increasing. Now I want to fix it, but I have no clue why its doing what its doing.
I take it I'm just going to get an answer here? Go figure.
And then someone comes in and sabotages my thread. Aren't you all considerate? The owners of python should sue you for defamation at this rate.
import pygame pygame.init() block=50 screenW=25*block screenH=20*block x=0 y=0 screen=pygame.display.set_mode((screenW,screenH)) red=False green=False blue=False rg=False rb=False gb=False def drawR(): r=255 g=0 b=0 global x global y global red x=0 y=0 while r>=0 and red==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("red",r,g,b) r-=51 y+=block if r<=0: red=True def drawG(): r=0 g=255 b=0 global x global y global green x=block y=0 while g>=0 and green==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("green",r,g,b) g-=51 y+=block if g<=0: green=True def drawB(): r=0 g=0 b=255 global x global y global blue x=block*2 y=0 while b>=0 and blue==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("blue",r,g,b) b-=51 y+=block if b<=0: blue=True def drawRG(): r=255 g=255 b=0 global x global y global rg x=block*3 y=0 while r>=51 and g>=51 and rg==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("redgreen",r,g,b) r-=51 if r<51: r=255 g-=51 if r==0 and g==51: rg=True y+=block if y>block*4: y=0 x+=block def drawRB(): r=255 g=0 b=255 global x global y global rb x=block*8 y=0 while r>=51 and b>=51 and rb==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("redblue",r,g,b) r-=51 if r<51: r=255 b-=51 if r==0 and b==51: rb=True y+=block if y>block*4: y=0 x+=block def drawGB(): r=0 g=255 b=255 global x global y global gb x=block*13 y=0 while b>=51 and g>=51 and rg==False: pygame.draw.rect(screen,(r,g,b),(x,y,block,block)) print("bluegreen",r,g,b) b-=51 if b<51: b=255 g-=51 if b==0 and g==51: gb=True y+=block if y>block*4: y=0 x+=block def main(): while True: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() exit() drawR() drawG() drawB() drawRG() drawRB() drawGB() pygame.display.update() main()What makes no sense is the first three functions (drawR, drawG, and drawB) do NOT make an infinite loop, but the latter three do (at least, they do when they print out the rgb value of each square they draw). They're based on the first three, so I can't fathom why they would do this. Their loops DO have an end point, just like the ones that draw the primary colors. Yeah, they're a bit more elaborate, but that's just because they have to change two values rather than one. I would guess this is a logic error somewhere, except I already made sure that the loops DON'T repeat. I have no clue what could be wrong.
I take it I'm just going to get an answer here? Go figure.
And then someone comes in and sabotages my thread. Aren't you all considerate? The owners of python should sue you for defamation at this rate.