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)