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...

Комментарии • 28

  • @IdoAloni123
    @IdoAloni123 5 лет назад +4

    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!

  • @hugueskir6203
    @hugueskir6203 5 лет назад +1

    Very-Super-Good! Nicely done sir!

  • @codePylet
    @codePylet  8 лет назад +8

    25:00 5 x 100 = 1000???? Sorry I meant to say 5 x 200 = 1000 :/

  • @dp0813
    @dp0813 5 лет назад +5

    Ughhh i wish i had watched this before i created several lists of multiple images. 🤦🏽‍♂️🤦🏽‍♂️🤦🏽‍♂️

  • @maltreatedpony
    @maltreatedpony 8 лет назад +3

    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?

    • @codePylet
      @codePylet  8 лет назад +3

      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)).

    • @maltreatedpony
      @maltreatedpony 8 лет назад

      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!

  • @MowiWowi
    @MowiWowi Год назад

    I recognize that voice your the guy who did a tutorial on replit right

  • @caelbrenning4763
    @caelbrenning4763 4 года назад +1

    I am in the thumbnail

  • @daedae515
    @daedae515 3 года назад

    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.

  • @bluidguy4007
    @bluidguy4007 5 лет назад

    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.

  • @DarKingdoomalmot
    @DarKingdoomalmot 8 лет назад +1

    HI,
    is there a way to rotate the image around one of its corners ?

    • @codePylet
      @codePylet  7 лет назад +1

      Actually there is :)

    • @kamalnayan9157
      @kamalnayan9157 7 лет назад

      how???????????

    • @kamalnayan9157
      @kamalnayan9157 7 лет назад

      pls reply

    • @ribarmilos
      @ribarmilos 5 лет назад

      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.

  • @shnerped3549
    @shnerped3549 4 года назад +1

    dude I can't hear a thing

  • @tejaszarekar9145
    @tejaszarekar9145 7 лет назад +2

    how to scale the image?

    • @codePylet
      @codePylet  7 лет назад +3

      +tejas zarekar displaysurface.blit(pygame.transform.scale(imageToScale, (newWidth, newHeight)))
      :)
      Hope that helps!

    • @tejaszarekar9145
      @tejaszarekar9145 7 лет назад

      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

    • @codePylet
      @codePylet  7 лет назад +3

      +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!

    • @tejaszarekar9145
      @tejaszarekar9145 7 лет назад

      no doubt it did!... can i have your mail id? there;s somthing interesting i am working on

    • @codePylet
      @codePylet  7 лет назад +1

      +tejas zarekar code.pylet@gmail.com

  • @namanaio2421
    @namanaio2421 7 лет назад +1

    hi