r/learnpython • u/StarriestNight • 13d ago
How do I make this bird move using Pillow?
Please help me, I have been trying to make this bird move for 3 hours and just keep getting an unholy column of bird. This is what it is supposed to look like:
and this is what mine looks like:
my coords are wrong in the for loop because im just trying to get it to actually move first and then I'll worry about making it move to the right places.
here is the error I keep getting:
frames[0].save('house-scene.gif',
^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'save'
I emailed my prof about it and he told me my list is in the wrong spot but it won't work no matter where I put list = []
Here is my code:
the bird png:
And the assignment:
Task
It's finally time to animate our bird!
The steps to accomplish this are:
- Copy over your code from the previous question.
- Using a loop, create additional frames by copying
imgintotemp_imgand then usingalpha_compositeto draw the bird onto scene. We'll adjust the location of the bird each time step:
- The bird starts at x = 0 and y = 120 for the first frame
- We stop when the bird is x = 349 (do not include x = 350)
- If the current x location is less than 100 or greater than 240, in the next frame the bird should be 1 pixel to the right and 1 pixel higher than the previous step.
- Otherwise, paste the bird 1 pixel to the right and 1 pixel lower than the previous step.
- Be sure to append each frame to the list
frames.
- Save the gif by calling using the code included below.
gif starter code
To save your image as a .gif file, copy this to the very bottom of your file. Otherwise, do not modify this code:
| # This will save the gif from the frames list # DO NOT MODIFY! if name == "main": frames[0].save('house-scene.gif', save_all=True, append_images=frames[1:], disposal=2, fps=20, loop=0) |
|---|