Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import ui
  2. import numpy as np
  3. W=1024
  4.  
  5.  
  6.  
  7. import time
  8. from objc_util import *
  9. CAShapeLayer=ObjCClass('CAShapeLayer')
  10.  
  11. t=np.linspace(0,1,1024)
  12. f=25
  13. class plotView(ui.View):
  14. def update(self):
  15.  
  16. y=self.A*np.sin(2*np.pi*f*t)*np.exp(-t/self.tau)+self.height/2
  17. p=ui.Path()
  18. p.move_to(0,y[0])
  19. for ti,yi in zip((t-t[0])/(t[-1]-t[0])*W,y):
  20. p.line_to(ti,yi)
  21.  
  22. self.L.path=p.objc_instance.CGPath()
  23. self.L.setNeedsDisplay()
  24. self.fps.text='{}'.format(1/(time.perf_counter()-self.t))
  25. self.t=time.perf_counter()
  26. def __init__(self):
  27. self.bg_color='white'
  28. L=CAShapeLayer.alloc().init()
  29. L.strokeColor=UIColor.redColor().CGColor()
  30. L.fillColor=UIColor.clearColor().CGColor()
  31. L.lineWidth=2
  32. self.objc_instance.layer().addSublayer_(L)
  33. L.setNeedsDisplay()
  34. self.L=L
  35. self.tau=1
  36. self.A=200
  37. self.fps=ui.Label(0,0,100,40)
  38. self.fps.text='0.0'
  39. self.t=time.perf_counter()
  40. self.add_subview(self.fps)
  41. def touch_moved(self,touch):
  42. x,y=touch.location
  43. #up/down bumps up amplitude
  44. #l/r changes tau
  45. self.tau=x/1024
  46. self.A=y-self.center.y
  47. self.update()
  48. #self.L.setNeedsDisplay()
  49.  
  50.  
  51. v=plotView()
  52. #v.update_interval=1/15
  53.  
  54. v.present()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement