omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Help with rotating images

    Pythonista
    3
    6
    3362
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sashadkiselev125
      sashadkiselev125 last edited by

      Is there anyway to rotate images in scene module without layers. I just want to use the built in image equals sign and turn it side ways to be a pause button

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        Maybe you should start using layers. The problem is that in:<pre>i = scene.image('Alien_Monster', 0, 0) # i is set to None</pre>the i variable is set to None. Scene.image() does not provide an image variable so i.center(), i.skew(), i.rotate(), etc. are not possible. However, if you draw your images into layers then lots of things become possible.

        An alternative to adopting layers would be to use the Python Imaging Library (PIL) to rotate the image BEFORE you make the call to scene.image().

        1 Reply Last reply Reply Quote 0
        • Sebastian
          Sebastian last edited by

          You can rotate images like this:<pre>from scene import *

          class MyScene (Scene):
          def setup(self):
          pass

          def draw(self):
          	background(0, 0, 0)
          	
          	push_matrix()
          	translate(200, 200)
          	rotate(45)
          	image('Alien_Monster', 0, 0, 100, 100)
          	pop_matrix()
          

          run(MyScene())</pre>

          1 Reply Last reply Reply Quote 0
          • sashadkiselev125
            sashadkiselev125 last edited by

            Thanks Sebastian once again. ccc I am using multiple scene code omz made without layers but thanks anyway

            1 Reply Last reply Reply Quote 0
            • Sebastian
              Sebastian last edited by

              I'm glad I could help :)

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                Thanks also Sebastian -- If you can't turn the image <b>after</b> you draw it then you must turn the canvas <b>before</b> you draw it. You learn something new every day.

                Keeping track of properly balancing repeated calls to <b>push_matrix()</b> and <b>pop_matrix()</b> was bugging me so see https://gist.github.com/cclauss/6313658 for the syntax:

                <pre>with privateMatrix(): # Save and then restore the scene.matrix
                translate(200, 200)
                rotate(45)
                image('Alien_Monster', 0, 0, 100, 100)</pre>
                This should eliminate the complexity of calling push_matrix() and pop_matrix() repeatedly in programs that heavily use Scene scale(), transform(), rotation(), etc.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors