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.


    iOS 12 malfunction

    Pythonista
    4
    11
    6464
    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.
    • AlbertoAEC
      AlbertoAEC last edited by

      Hello!
      First of all is the first time i am writing in this forum. I want to say this app is incredible and thanks to everyone here because this site was so util for me.

      I am using this app for a year now and never I had any problems but yesterday I updated my iPad (2017 version) and script that uses Scene lib has execution problems.
      Is a script to represents some figures in 3D. Previously, with iOS 10 (iOS 11 doesn't convinced me) where I wrote the code, Pythonista ran it in 60 fps and visualice correctly a cube or a piramid (depending the uncomment lines).
      Now don't draw correctly the figures without change the code and runs in 14 fps.

      Do anyone have any idea? Thanks in advance

      from scene import *
      #import sound
      import random
      import math
      A = Action
      
      class Punto (SpriteNode):
      	def __init__(self, r=10, *args, **kwargs):
      		SpriteNode.__init__(self, 'shp:Circle', *args, **kwargs)
      		self.size = (r, r)
      		#self.color = random.choice(['white','yellow','blue','cyan','red','orange','purple','black','green'])
      
      class Linea (ShapeNode):
      	def __init__(self, orig, dest, *args, **kwargs):
      		ShapeNode.__init__(self, *args, **kwargs)
      		self.line_path(orig, dest)
      		self.stroke_color = '#ffffff'
      		
      	def line_path(self, orig, dest):
      		x1,y1 = orig
      		x2,y2 = dest
      		self.position=((x2-x1)/2 + x1, (y2-y1)/2 + y1)
      		path = ui.Path()
      		path.line_width = 2
      		path.move_to(x1,y2)
      		path.line_to(x2,y1)
      		self.path = path
      
      	
      class Vector3D (object):
      	def __init__(self, values):
      		self.vector = values
      		
      	def to2D(self):
      		elem = [[1, 0, 0],
      						[0, 1, 0]]
      						
      		return (elem[0][0] * self.vector[0] + elem[0][1] * self.vector[1] + elem[0][2] * self.vector[2],
      						elem[1][0] * self.vector[0] + elem[1][1] * self.vector[1] + elem[1][2] * self.vector[2])
      						
      	def rotateX(self, fi):
      		rotMat = [[math.cos(fi), -math.sin(fi), 0],
      							[math.sin(fi), math.cos(fi), 0],
      							[0, 0, 1]]
      		self.rotate(rotMat)
      		
      	def rotateY(self, fi):
      		rotMat = [[math.cos(fi), 0, -math.sin(fi)],
      							[0, 1, 0],
      							[math.sin(fi), 0, math.cos(fi)]]
      		self.rotate(rotMat)
      		
      	def rotateZ(self, fi):
      		rotMat = [[1, 0, 0],
      							[0, math.cos(fi), -math.sin(fi)],
      							[0, math.sin(fi), math.cos(fi)]]
      		self.rotate(rotMat)
      	
      	def rotate(self, rotMat):		
      		self.vector = [rotMat[0][0] * self.vector[0] + rotMat[0][1] * self.vector[1] + rotMat[0][2] * self.vector[2],
      						rotMat[1][0] * self.vector[0] + rotMat[1][1] * self.vector[1] + rotMat[1][2] * self.vector[2],
      						rotMat[2][0] * self.vector[0] + rotMat[2][1] * self.vector[1] + rotMat[2][2] * self.vector[2]]
      						
      	def center(self, centro):
      		return Vector3D([self.vector[0] + centro[0], self.vector[1] + centro[1], self.vector[2] + centro[2]])
      		
      class MyScene (Scene):
      	def setup(self):
      		self.angle = 0.005
      		self.angleX = 0
      		self.angleY = 0
      		self.init_angle = self.angle
      		self.centro = [500,400,0]
      		#----CUBE-----
      #		self.p = [Vector3D([-100,-100,-100]),
      #							Vector3D([100,-100,-100]),
      #							Vector3D([100,100,-100]),
      #							Vector3D([-100,100,-100]),
      #							Vector3D([-100,-100,100]),
      #							Vector3D([100,-100,100]),
      #							Vector3D([100,100,100]),
      #							Vector3D([-100,100,100])]
      
      		#-----PIRAMID-----
      		self.p = [Vector3D([-100,-100,-100]),
      							Vector3D([100,-100,-100]),
      							Vector3D([100,100,-100]),
      							Vector3D([-100,100,-100]),
      							Vector3D([0,0,100]),
      							Vector3D([0,0,100]),
      							Vector3D([0,0,100]),
      							Vector3D([0,0,100])]
      							
      		self.puntos = []
      		for i,punto in enumerate(self.p):
      			self.puntos.append(Punto(position=punto.to2D()))
      			self.add_child(self.puntos[i])
      		
      		self.uniones = []
      		for j in range(0,4):
      			self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+4].center(self.centro).to2D()))
      			
      		for j in range(0,3):
      			self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+1].center(self.centro).to2D()))	
      		self.uniones.append(Linea(self.p[0].center(self.centro).to2D(), self.p[3].center(self.centro).to2D()))
      
      		for j in range(4,7):
      			self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+1].center(self.centro).to2D()))	
      		self.uniones.append(Linea(self.p[4].center(self.centro).to2D(), self.p[7].center(self.centro).to2D()))
      
      		for uni in self.uniones:
      			self.add_child(uni)
      		
      	def did_change_size(self):
      		pass
      	
      	def update(self):
      		for p in self.p:
      			#p.rotateX(self.angle)
      			p.rotateY(self.angleX)
      			p.rotateZ(self.angleY)
      		
      		for i,punto in enumerate(self.puntos):
      			punto.position = self.p[i].center(self.centro).to2D()
      		
      		for j in range(0,4):
      			self.uniones[j].line_path(self.puntos[j].position, self.puntos[j+4].position)
      			
      		for j in range(0,3):
      			self.uniones[j+4].line_path(self.puntos[j].position, self.puntos[j+1].position)
      		self.uniones[7].line_path(self.puntos[0].position, self.puntos[3].position)
      		
      		for j in range(4,7):
      			self.uniones[j+4].line_path(self.puntos[j].position, self.puntos[j+1].position)
      		self.uniones[11].line_path(self.puntos[4].position, self.puntos[7].position)
      
      	
      	def touch_began(self, touch):
      		#self.angle = 0
      		self.move = 0
      		x, y = touch.location
      		self.inicio = {'x':x, 'y':y}
      	
      	def touch_moved(self, touch):
      		self.move = 1
      		x, y = touch.location
      		x = abs(self.inicio['x']) - abs(x)
      		y = abs(self.inicio['y']) - abs(y)
      		self.angleX = math.radians(x)/50
      		self.angleY = math.radians(y)/50
      	
      	def touch_ended(self, touch):
      		#self.angle = self.init_angle
      		if self.move == 1:
      			self.angleX = 0
      			self.angleY = 0
      		else:
      			self.angleX = self.angle
      			self.angleY = self.angle
      		
      
      if __name__ == '__main__':
      	run(MyScene(), show_fps=True)
      
      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @AlbertoAEC last edited by

        @AlbertoAEC, seems like a major bug related to this iOS version. For your reference, I see the same issue with iOS 12 on iPhoneX – broken shape running at around 10 fps.

        AlbertoAEC 1 Reply Last reply Reply Quote 0
        • jgoalby
          jgoalby last edited by

          Another point of reference for you. I have iOS 11 on my iPad still and it runs fine at 60fps. Sometimes goes down to 58fps when I rotate. I’ll update my iPad to iOS 12 soon and can confirm the slowness most likely.

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

            Out of curiosity, have you tried writing this as numpy arrays? You can transform all of the points at the same time, should be a lot faster...

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

              @mikael Thank you, I have imagined that. I will wait for future version that fix it.

              @jgoalby said:

              Another point of reference for you. I have iOS 11 on my iPad still and it runs fine at 60fps. Sometimes goes down to 58fps when I rotate. I’ll update my iPad to iOS 12 soon and can confirm the slowness most likely.

              Yes, in previous version I had the same behaviour and it seems you will report the same slowness when you updates.

              @JonB said:

              Out of curiosity, have you tried writing this as numpy arrays? You can transform all of the points at the same time, should be a lot faster...

              Thank you for the info. The script was only for fun purpose and I didn’t though so much.

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

                When you say that, in addition to slowness, the picture does not look corredt, can you post a screenie? maybe if we can figure out the cause of the drawing error, we will get to the cause of the slowness.

                Does the initial picture, before using touch look ok?
                Could you try using update to rotate directly, without using touch?
                If those are messed up, then you can set a specific rotation angle, and dump out the points and rotation matricies, and we can check against the theoretical.

                AlbertoAEC 1 Reply Last reply Reply Quote 0
                • AlbertoAEC
                  AlbertoAEC @JonB last edited by

                  @JonB Both problems seems to be caused by the iOS version. Before update all works perfectly. You can try the code in your own device to try something.

                  Automatic rotation is already coded in the script posted above. To try it you need to make a single tap at any point of the screen.
                  I post you two screenshots. First at the initial position and the second one at random angle.
                  http://i990.photobucket.com/albums/af26/AEC_railsim/9DE5F099-6B4A-40C5-A018-F8C93F338354_zpscu2jzikq.png~original

                  http://i990.photobucket.com/albums/af26/AEC_railsim/C9367625-6273-4A69-8EA3-85DB20AC926A_zps82tytquh.png~original

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @AlbertoAEC last edited by

                    Is it fair to say the the corner points seem to be behaving correctly, and the lines have the correct angles, however the line positions appear incorrect?

                    One problem I see is that you should not be using update. This calls the function even if it is not needed. Instead, rename it to update_points and call that from touch_moved and touch_ended.

                    A second issue is that you are creating many, many Vector3D objects, since .center() creates new instances. Might be a memory problem.

                    As a debug, maybe you can change Linea as follows, and see if the orig/dest are being set correctly (this adds a label to the center of each line).

                    class Linea (ShapeNode):
                        def __init__(self, orig, dest, *args, **kwargs):
                            ShapeNode.__init__(self, *args, **kwargs)
                            self.lbl=LabelNode('{},{}'.format(orig,dest),font=('<System>',6),color='red')
                            self.add_child(self.lbl)
                            self.line_path(orig, dest)
                            self.stroke_color = '#ffffff'
                            self.anchor_point=(.5,.5)
                        def line_path(self, orig, dest):
                            x1,y1 = orig
                            x2,y2 = dest
                            self.position=((x2-x1)/2. + x1, (y2-y1)/2. + y1)
                            path = ui.Path()
                            path.line_width = 2
                            path.move_to(x1,y2)
                            path.line_to(x2,y1)
                            self.lbl.text='{}\n{}'.format(orig,dest)
                            self.path = path
                    

                    I suspect the issue has something to do with how Paths auto reset the bounds, which the original code depends on. Maybe ios12 behaves differently.
                    Finally, here is a numpy'd version of the code. Does this work for you, and is it faster?

                    https://gist.github.com/6881aaaf165e248b3f8c0549df03503c

                    mikael AlbertoAEC 2 Replies Last reply Reply Quote 0
                    • mikael
                      mikael @JonB last edited by

                      @JonB, works for me @60 fps, except probably was not made for iPhone as the cube is only partially visible when in landscape mode, and not at all in portrait.

                      1 Reply Last reply Reply Quote 0
                      • AlbertoAEC
                        AlbertoAEC @JonB last edited by

                        @JonB Thank you very much for your help. Your code works perfectly. I barely had used the numpy lib and you made me a lesson of use.
                        I think too the error is caused by how the version interpret the ui.Path.

                        @mikael change the “centro” variable that is the center point of the 3D figure

                        self.centro = np.mat([500,400,0]).T
                        
                        1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB last edited by

                          I think what was happening is that paths are funny, because their bounds change on you, by which I mean if you draw a line from x=5 to 10, instead they vare drawn from -2.5 to 2.5. The original code was trying to accommodate that by changing the position.

                          Not sure what would make the code so much slower, nor I could not find any mention of UIBezierPath changes in ios12 change notes.

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