Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class "vector"
- {
- x=0,
- y=0,
- magnitude=function()
- return math.sqrt(self.x^2+self.y^2)
- end,
- unit=function()
- return self/self:magnitude()
- end,
- coords=function()
- return self.x,self.y
- end,
- __settings=
- {
- new=function(x, y)
- return {x=x,y=y}
- end
- },
- __omt=
- {
- __tostring=
- function(a)
- return "Vector : "..a.x..", "..a.y
- end,
- __add=
- function(a,b)
- if tostring(b)=="Vector2" then
- return newObj("vector", a.x+b.x,a.y+b.y)
- else
- return newObj("vector", a.x+b,a.y+b)
- end
- end,
- __sub=
- function(a,b)
- if tostring(b)=="Vector" then
- return newObj("vector", a.x-b.x,a.y-b.y)
- else
- return newObj("vector", a.x-b,a.y-b)
- end
- end,
- __div=
- function(a,b)
- if tostring(b)=="Vector" then
- return newObj("vector", a.x/b.x,a.y/b.y)
- else
- return newObj("vector", a.x/b,a.y/b)
- end
- end,
- __mul=
- function(a,b)
- if tostring(b)=="Vector" then
- return newObj("vector", a.x*b.x,a.y*b.y)
- else
- return newObj("vector", a.x*b,a.y*b)
- end
- end
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement