Python Pygame Tutorial 4 - Displaying Images (Blitting, Rotating, Scaling, Animating)
HTML-код
- Опубликовано: 6 окт 2024
- Thank you for watching my video and I really hope you found something useful.
Pygame on Facebook: www. gro...
If you'd like to know how to install and run your first Python Pygame script then watch my first video here: • Python Pygame Tutorial...
For the scripts in this video:
drive.google.c...
You can find all the scripts here in my Google Drive Folder goo.gl/PeBc0Y
Or if you'd like to download the zipped files follow this link
goo.gl/QcGJ7Y
... and if you have any comments then feel free but bear in mind I don't pretend to be an expert, I just enjoying using Python and Pygame.
Anthony
Downloads:
Python 2.7.x ....... www.python.org...
Pygame 1.9.x ....... www.pygame.org/...
Notepad++ ....... notepad-plus-p...
Documents:
Pygame ....... www.pygame.org...
Thank you, you are the first tutorial that showed image transformation...
I have been searching for one like this for a while and this is not only a unique tutorial, it is also a great one in of it self!
Very-Super-Good! Nicely done sir!
25:00 5 x 100 = 1000???? Sorry I meant to say 5 x 200 = 1000 :/
There is a thing called backspace y'know
Ughhh i wish i had watched this before i created several lists of multiple images. 🤦🏽♂️🤦🏽♂️🤦🏽♂️
Thanks for this, it's a great help! With the rotate code I'm trying to use the code to make an artifical horizon. Any tips on how I could redefine the y coordinate of the image to rotate around a new centrepoint and have that new point centre screen?
You could redefine the rotate_and_center function to include an offset rather than just using the center points. For example rotate_and_center(ds, x, y, x_offset, y_offset, image, degrees) and then deduct those offsets from the x and y parameters when blitting like this DS.blit(rotated, (x - x_offset, y - y_offset)).
Thanks for the quick reply. Implementing this centres the new point when blitted, but doesn't seem to move the point of rotation, the rect still rotates around its original centre point. Unless I am doing it wrong.. I'll keep trying. thanks!
I recognize that voice your the guy who did a tutorial on replit right
I am in the thumbnail
what is the point the of DW_HALF - R.center[0] and DW_HALF - R.center[1]? im a newbie and i dont understand the R.center[0] and R.center[1]. I get the DW and DHs but confused on why are we subtracting R.center and what the R.center and the index[0] and [1] is. I guess what im trying to get at is when i blit an img without the - r.center[0] and r.center[1] with just the dw half and dh half , lets say a for dw and dh of500x500, it displays the image in the center of the lower right area, so i guess the - r.centers are needed to place it in the middle but when i tried it also with dw half - 50 and dh half - 50, that also placed it in the middle. i just have a hard time picturing why this makes sense.
I kept getting the error NameError: name 'xrange' is not defined, so I went and copied from your file you listed and I still get that error, do you know where I could be going wrong?
Thanks for the videos, I am pretty new to Python and am enjoying it, I do a lot of dabbling with random numbers so I appreciate this kind of tutorial.
newer python i think. take out the x maybe
xrange is in python2 only
not in python3
HI,
is there a way to rotate the image around one of its corners ?
Actually there is :)
how???????????
pls reply
Just rotate it as you normaly would, using a R matrix. Then translate it by subtracting o(x,y) and p(x,y). Someone correct me if I'm wrong.
dude I can't hear a thing
how to scale the image?
+tejas zarekar displaysurface.blit(pygame.transform.scale(imageToScale, (newWidth, newHeight)))
:)
Hope that helps!
one more thing... How to blit an image that changes at 2 different point. for eg . movement of a connecting rod in an engine? in simpler words, tilt an image?... yeah
+tejas zarekar To do this you need to have a surface that is twice the size of the image you want to rotate.n
w, h = image.get_rect().size
newImage = pygame.Surface((w * 2, h * 2))
Now you need to blit your image to the newImage surface at the center but offset so your pivot is over the center.
newImage.blit(image, (w - pivotPosX, h - pivotPosY))
Now rotate the newImage to n degrees.
rotatedImage = pygame.transform.rotate(newImage, nDegrees)
get the center points on the rotatedImage
cx, cy = rotateImage.get_rect().center
now you can blit the rotated image to the display centred on the x, y coordinate and it'll tilt on the pivot point.
displaySurface.blit(rotatedImage, (x - cx, y - cy))
Hope that helps!
no doubt it did!... can i have your mail id? there;s somthing interesting i am working on
+tejas zarekar code.pylet@gmail.com
hi
go