So I was testing one interesting thing in pygame. I know this code is very crappy, but it's just a test. In this programme I have a lists that represent a pygame polygon and list of them. In the function, it returns changed list to draw it. But for some reason, no matter how hard I try, it changes original "polygon" list. But if I set the "mor" variable a ctrl + c ctrl + v of "polygon" list, it works just fine Am I crazy? Shouldn't .copy() create unrelated list? Why "hexagon" changes?
import pygame
pygame.init()
sc = pygame.display.set_mode((1000, 1000))
clock = pygame.time.Clock()
WHITE = (255,255,255)
hexagon = [WHITE,[[669,207],[615,240],[615,305],[669,335],[725,305],[725,240]],8]
hexagon2 = [WHITE,[[669,335],[725,305],[725,240],[669,207],[615,240],[615,305]],8]
hexs = [hexagon,hexagon2]
hex = pygame.Surface((1000,1000))
state = 0
def morph (states,first):
global state
done = 0
current = first
for i in current[1]:
a = 0
for n in i:
try:
if n < states[state+1][1][current[1].index(i)][a]:
current[1][current[1].index(i)][a] += 1
elif n > states[state+1][1][current[1].index(i)][a]:
current[1][current[1].index(i)][a] -= 1
else:
done += 1
except:
if n < states[0][1][current[1].index(i)][a]:
current[1][current[1].index(i)][a] += 1
elif n > states[0][1][current[1].index(i)][a]:
current[1][current[1].index(i)][a] -= 1
else:
done += 1
a += 1
if done == len(current[1])*2:
if state + 1 <= len(states):
state += 1
else:
state = 0
return current
run = True
mor = hexagon[:]
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
hex.fill((0,0,0))
mor = morph(hexs,mor)
pygame.draw.polygon(hex,*mor)
sc.blit(hex,(0,0))
pygame.display.update()
clock.tick(60)
pygame.quit()
exit()
Again, sorry for crappy code and bad english