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.


    how do I use ui.transform.rotation and anchor point on my vector shape

    Pythonista
    2
    2
    111
    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.
    • R
      resserone13v2.0 last edited by

      want to rotate the shape and change the anchor point.

      anchor point gives me error.

      transform doesn't rotate the shape.

      parallelogram.anchor_point(0,0)
      
      # Rotate the parallelogram 180 degrees
      		transform = ui.Transform.rotation(180)
      		self.left_wall.transform = transform	
      

      I want to rotate the parallelogram 180 degrees. here's the complete code

      import ui
      from scene import *
      
      
      def parallelogram(a, angle_of_a, color,  x_pos, y_pos):
          
          b = a
          
          # Calculate the coordinates of points B and C
          angle_A_rad = math.radians(angle_of_a)
          bx = a
          by = 0
          cx = bx + b * math.cos(angle_A_rad)
          cy = b * math.sin(angle_A_rad)
      
          # Create a path to draw the parallelogram
          path = ui.Path()
          path.move_to(bx, by)  # Point B
          path.line_to(cx, cy)  # Point C
          path.line_to(cx - a,cy + a)  # Point D
          path.line_to(bx - a, by + a)  # Point A
          path.close()
          # Create a shape node with the path
          parallelogram = ShapeNode(path=path)
          parallelogram.fill_color = color
          parallelogram.stroke_color = 'black'
          parallelogram.position = (x_pos, y_pos)
          
          parallelogram.anchor_point(0,0)
          
          return parallelogram
      
      
      class MyScene(Scene):
      	def setup(self):
      		self.background_color = 'white'
      		self.left_wall = parallelogram(400, 100, 'orange', self.size.w / 2, self.size.h / 2)
      		
                      # Rotate the parallelogram 180 degrees
      		transform = ui.Transform.rotation(180)
      		self.left_wall.transform = transform		
      		
      		self.add_child(self.left_wall)
      
      if __name__ == '__main__':
      	run(MyScene(), show_fps=False)
      
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @resserone13v2.0 last edited by cvp

        @resserone13v2-0 error is "anchor_point is not callable..."

            parallelogram.anchor_point = (0,0)
        

        Rotation angle is in radians

        		transform = ui.Transform.rotation(math.pi)
        

        ui.Transform is used with an ui.View, not a Node, use Action

        		#transform = ui.Transform.rotation(math.pi)
        		#self.left_wall.transform = transform		
        		self.left_wall.run_action(Action.rotate_by(math.pi, 1, TIMING_EASE_IN_OUT))
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors