Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ui
- import numpy as np
- W=1024
- import time
- from objc_util import *
- CAShapeLayer=ObjCClass('CAShapeLayer')
- t=np.linspace(0,1,1024)
- f=25
- class plotView(ui.View):
- def update(self):
- y=self.A*np.sin(2*np.pi*f*t)*np.exp(-t/self.tau)+self.height/2
- p=ui.Path()
- p.move_to(0,y[0])
- for ti,yi in zip((t-t[0])/(t[-1]-t[0])*W,y):
- p.line_to(ti,yi)
- self.L.path=p.objc_instance.CGPath()
- self.L.setNeedsDisplay()
- self.fps.text='{}'.format(1/(time.perf_counter()-self.t))
- self.t=time.perf_counter()
- def __init__(self):
- self.bg_color='white'
- L=CAShapeLayer.alloc().init()
- L.strokeColor=UIColor.redColor().CGColor()
- L.fillColor=UIColor.clearColor().CGColor()
- L.lineWidth=2
- self.objc_instance.layer().addSublayer_(L)
- L.setNeedsDisplay()
- self.L=L
- self.tau=1
- self.A=200
- self.fps=ui.Label(0,0,100,40)
- self.fps.text='0.0'
- self.t=time.perf_counter()
- self.add_subview(self.fps)
- def touch_moved(self,touch):
- x,y=touch.location
- #up/down bumps up amplitude
- #l/r changes tau
- self.tau=x/1024
- self.A=y-self.center.y
- self.update()
- #self.L.setNeedsDisplay()
- v=plotView()
- #v.update_interval=1/15
- v.present()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement