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.


    Pure Python gestures

    Pythonista
    8
    65
    21860
    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.
    • mikael
      mikael @Anxietier last edited by

      @Anxietier, thanks for catching this. Pan end event was not properly handled, fixed now in the version on the repo.

      Anxietier 1 Reply Last reply Reply Quote 0
      • Anxietier
        Anxietier @Anxietier last edited by

        @Anxietier said:

        @Anxietier said:

        @mikael
        thanks for help, i make it
        but there's another problem showed up:
        i make a main view, then i subclass zoomPanView and add to mainView , after that i add imageView as zoomPanView's subVIew, like what zoomPanDemo did, when i overwrite on_pan method and test it, data.began and data.changed can give me right value, but data.ended not, i dont know why

        one more thing, i overwrote on_pinch too, and i printed data.ended, and got right value, maybe two gesture's ended flag conflict ?

        i resolved this issue
        i subclass both view and GestureMixin as new ZoomPanView, then i overwrite touch_ended, so that when i subclass new ZoomPanView i can edit touch_ended,
        high encapsulation not always convenient XD

        1 Reply Last reply Reply Quote 0
        • Anxietier
          Anxietier @mikael last edited by

          @mikael said:

          @Anxietier, thanks for catching this. Pan end event was not properly handled, fixed now in the version on the repo.

          expecting for new version (👍 ͡❛ ͜ʖ ͡❛)👍

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @Anxietier last edited by

            @Anxietier, is there a specific reason why you are using the Python version instead of the native iOS gestures? Just curious, because I no longer remember why I wrote pygestures. 😁 ... Probably just because I wanted to see if I could do it.

            Anxietier 1 Reply Last reply Reply Quote 1
            • Anxietier
              Anxietier @mikael last edited by

              @mikael
              well, im not good at math, i tried use touch_began\move\ended, and surely i can make simple function, but as it became complex, my brain be in chaos, XD

              mikael 1 Reply Last reply Reply Quote 0
              • mikael
                mikael @Anxietier last edited by

                @Anxietier, I meant choosing between gestures.py (wrapper around iOS native gestures) and pygestures.py (pure Python gestures built on top of the ui.View.touch_x method ”primitives”.

                Your answer leads me to guess you might not have been aware of the first option.

                Anxietier 1 Reply Last reply Reply Quote 0
                • Anxietier
                  Anxietier @mikael last edited by

                  @mikael oh, i did try gesture.py, got some problems, and you suggested me subclass ZoomPanView instead for my need, then i did and i find it's interesting, so ~~ :))

                  @mikael said:

                  @Anxietier, can you subclass ZoomPanView instead?

                  If you run pygestures.py and swipe from the right, you get the demo picture that you can pan and zoom, and that seems to work ok.

                  The code for it is at the end of the file.

                  mikael stephen 2 Replies Last reply Reply Quote 0
                  • mikael
                    mikael @Anxietier last edited by

                    @Anxietier, oh, and I thought you were already using the python version, given the title of this discussion thread... 😄

                    Anxietier 1 Reply Last reply Reply Quote 1
                    • stephen
                      stephen @Anxietier last edited by

                      @Anxietier

                      do you still need help with drag/friction algorithm ?

                      Anxietier 1 Reply Last reply Reply Quote 0
                      • Anxietier
                        Anxietier @stephen last edited by

                        @stephen
                        thank you, maybe not, i did solve this problem (probably not yet)
                        thanks for your help :)

                        stephen 1 Reply Last reply Reply Quote 0
                        • Anxietier
                          Anxietier @mikael last edited by

                          @mikael
                          haha, I was trying to make a zoom demo, but the effect is not good, so I googled key words "pythonista 2 finger zoom", then luckily found this XD

                          1 Reply Last reply Reply Quote 0
                          • stephen
                            stephen @Anxietier last edited by

                            @Anxietier

                            Awesome!

                            ok well il still working on it because parts of the process are in my todo fo mainproject. ill post finished codebwith coments here when finished

                            Anxietier 1 Reply Last reply Reply Quote 0
                            • Anxietier
                              Anxietier @stephen last edited by

                              @stephen
                              good luck ! (っ^▿^)۶🍸🌟🍺٩(˘◡˘ )

                              stephen 1 Reply Last reply Reply Quote 1
                              • stephen
                                stephen @Anxietier last edited by

                                @Anxietier
                                thanks, i noticed you like those ٩(•̮̮̃•̃)۶ faces. idk if you type them everytime but i "buffed" the keyboard example script and gave it more functionality here you will be able to select them from a list that you can add to yourself heres a couple thats included.

                                ٩(•̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ ٩(̃•̃•̃)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃)۶ ε(̮̮̃•̮̮̃̃•̃)з (๏̯͡๏) |=_=|

                                Anxietier 1 Reply Last reply Reply Quote 1
                                • Anxietier
                                  Anxietier @stephen last edited by

                                  @stephen
                                  haha, I would try it

                                  1 Reply Last reply Reply Quote 2
                                  • stephen
                                    stephen last edited by

                                    @mikael i usually do great at dealing with numbers... after a couple days of this i seem to have made a circle back to where i started... it might be that i dont understand Sigma or i may be using the wrong function all together... i even tried generating a logarithmic table then iterating the values to get drag to stop movment lol. any chance you @cvp @JonB or @ccc know a non built-in way to do this? here is where my testing code as it was when i stopped to post this... sorry the codes messy..

                                    
                                    import numpy as np
                                    import math
                                    from scene import *
                                    w, h=get_screen_size()
                                    
                                    def Distance(pos1, pos2):
                                    	x1, y1=pos1
                                    	x2, y2=pos2
                                    	dx, dy=x1-x2, y1-y2
                                    	return math.sqrt(dx*dx + dy*dy)
                                    
                                    def Force(pos1, pos2, k):
                                    	x1, y1=pos1
                                    	x2, y2=pos2
                                    	return Distance(pos1, pos2)*k#/1*(1+np.exp(1))**k
                                    
                                    def Direction(pos1, pos2):
                                    	x1, y1=pos1
                                    	x2, y2=pos2
                                    	dx=(x1-x2)/Distance(pos1,pos2)
                                    	dy=(y1-y2)/Distance(pos1,pos2)
                                    	return Point(dx, dy)
                                    	
                                    class main (Scene):
                                    	def setup(self):
                                    		self.isDragging = False
                                    		self.drag_T=0
                                    		self.i=0
                                    
                                    		self.touch_loc=(0, 0)
                                    		self.ticks=0
                                    		self.tick_rate=0.01
                                    		self.origin_pos=Point(w/2, 64)
                                    		
                                    		self.subject=SpriteNode(
                                    			texture=None, color=(0.0, 1.0, 0.0), size=Size(64, 64),
                                    			position=self.origin_pos, anchor_point=(0.5, 0.5), parent=self)
                                    		self.sub_data=LabelNode(
                                    			text=f'(◕_◕)', font=('Menlo', 22), anchor_point=(0.5, 0.5),
                                    			color=(0.0, 0.0, 0.0, 1.0), parent=self.subject)
                                    		self.data=LabelNode(
                                    			text="", font=('Menlo', 14), anchor_point=(0.0, 0.0), color=(1.0, 1.0, 1.0),
                                    			position=Point(150,512), size=Size(256, 512), parent=self)
                                    								
                                    	
                                    	def update(self):
                                    		w, h=get_screen_size()
                                    		self.i+=self.dt
                                    		self.ticks+=1
                                    		self.drag_T= (self.drag_T+1) if self.isDragging else 0
                                    		d_o=Distance(self.subject.position, self.origin_pos)
                                    		d_s=Distance(self.subject.position, self.touch_loc)
                                    		d_t=Distance(self.origin_pos, self.touch_loc)
                                    		max=Distance((w/2, h/3), self.subject.position)
                                    		target_dir=Direction(self.touch_loc, self.subject.position)
                                    		f=Force(self.origin_pos, self.touch_loc, self.drag_T)
                                    		damp=(1/(1+np.exp(-max)))
                                    		
                                    		
                                    		if self.isDragging:
                                    			w, h=get_screen_size()
                                    			x, y=self.subject.position
                                    			xx, yy=self.touch_loc
                                    			tx, ty=target_dir
                                    			if max > 1:
                                    				self.subject.position=(x+tx, y+ty+max)
                                    			
                                    		self.DataUpdate(d_t, d_s, d_o, max, f, target_dir)
                                    			
                                    		self.i=0
                                    	def DataUpdate(self, d_t_o, d_s_t, d_s_o, max, f, t_dir):
                                    		self.data.text= (f'Ticks: {self.ticks}\n'+
                                    						f'Dist from Max {max}\n'+
                                    						f'Force/Friction: {f}\n'+
                                    						f'Drag Time: {self.drag_T}\n'+
                                    						f'isDragging: {self.isDragging}\n'+
                                    						f'Target Direction: {t_dir}\n'+
                                    						f'Subject position: {self.subject.position}\n'+
                                    						f'Touch location: {self.touch_loc}\n'+
                                    						f'Origin: {self.origin_pos}\n\n'+
                                    						f'Distance - Touch→Origin: {d_t_o}\n'+
                                    						f'Distance - Subject→Origin: {d_s_o}\n'+
                                    						f'Distance - subject→Touch: {d_s_t}\n')
                                    		
                                    	def touch_began(self, touch):
                                    		self.isDragging = True
                                    		self.touch_loc=touch.location
                                    	
                                    	def touch_moved(self, touch):
                                    		tx, ty=touch.location
                                    		sx, sy=self.subject.position
                                    		self.touch_loc=touch.location
                                    		
                                    	def touch_ended(self, touch):
                                    		self.isDragging = False
                                    		#self.touch_loc=(0, 0)
                                    		#self.direction=(0, 0)
                                    		self.drag_T=0
                                    		self.subject.position=self.origin_pos
                                    run(main())
                                    		
                                    	
                                    
                                    cvp 2 Replies Last reply Reply Quote 1
                                    • cvp
                                      cvp @stephen last edited by

                                      @stephen I'm sincerely sorry but, perhaps/obviously due to my poor English, I don't understand what you want to do with this script.

                                      1 Reply Last reply Reply Quote 1
                                      • cvp
                                        cvp @stephen last edited by

                                        @stephen first remark, setting tx,ty,sx,sy is useless, isn't it?

                                            def touch_moved(self, touch):
                                                tx, ty=touch.location
                                                sx, sy=self.subject.position
                                                self.touch_loc=touch.location 
                                        
                                        stephen 1 Reply Last reply Reply Quote 1
                                        • stephen
                                          stephen @cvp last edited by stephen

                                          @cvp yes very much so in is what i posted. when i test i use alot of exlusive calls to insure control to eliminate inclusive bug or errors then when i achieve outcome expected i remove exclusive properties one at a time . just a metegation process i developed over the years. i should have mentioned this im sorry for the confusion. lol ☺️ the one your speaking of used to be connected to instance variables that i already removed lol kinda what i meant when i said sorry for the messy code lol

                                          also my goal was to creat a drag dampener. for example dragging an object from the bottom of the screen thats constrained to half screen size for travel. nd object speed slows as it aproaches max distance. similar to a vehicle comng to a stop at a trafic light..

                                          cvp 1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @stephen last edited by

                                            @stephen ok, understood. I'm really not a specialist of games or scene but I wonder if there are no functions for the physical aspect of the movements.
                                            Hoping other guys will help you. And sorry, I shouldn't have doubted 🙄

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