Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- test
- -- Use this function to perform your initial setup
- function setup()
- if backup then Backup("pinch") end
- img=readImage("Small World:Mine Medium")
- p=pinch()
- end
- function draw()
- background(0)
- p:processTouches()
- sprite(img,WIDTH/2,HEIGHT/2,500*p.zoom)
- end
- function touched(touch)
- p:touched(touch)
- end
- pinch=class()
- function pinch:init()
- self.tb={}
- self.zoom=1
- end
- function pinch:touched(touch)
- if touch.state==ENDED then self.tb={} self.d1=nil self.d2=nil
- else table.insert(self.tb,{x=touch.x,y=touch.y}) end
- end
- function pinch:processTouches()
- if #self.tb==2 then
- local v1,v2=vec2(self.tb[1].x,self.tb[1].y), vec2(self.tb[2].x,self.tb[2].y)
- self.d1=v1:dist(v2)
- end
- if self.d2~=nil then self.zoom=self.zoom*self.d1/self.d2 end
- self.d2=self.d1 self.tb={}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement