Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Vector/Lua/vector.lua
Normal file
33
Task/Vector/Lua/vector.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
vector = {mt = {}}
|
||||
|
||||
function vector.new (x, y)
|
||||
local new = {x = x or 0, y = y or 0}
|
||||
setmetatable(new, vector.mt)
|
||||
return new
|
||||
end
|
||||
|
||||
function vector.mt.__add (v1, v2)
|
||||
return vector.new(v1.x + v2.x, v1.y + v2.y)
|
||||
end
|
||||
|
||||
function vector.mt.__sub (v1, v2)
|
||||
return vector.new(v1.x - v2.x, v1.y - v2.y)
|
||||
end
|
||||
|
||||
function vector.mt.__mul (v, s)
|
||||
return vector.new(v.x * s, v.y * s)
|
||||
end
|
||||
|
||||
function vector.mt.__div (v, s)
|
||||
return vector.new(v.x / s, v.y / s)
|
||||
end
|
||||
|
||||
function vector.print (vec)
|
||||
print("(" .. vec.x .. ", " .. vec.y .. ")")
|
||||
end
|
||||
|
||||
local a, b = vector.new(5, 7), vector.new(2, 3)
|
||||
vector.print(a + b)
|
||||
vector.print(a - b)
|
||||
vector.print(a * 11)
|
||||
vector.print(a / 2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue