Created
May 29, 2013 20:09
-
-
Save adambutler/5673432 to your computer and use it in GitHub Desktop.
Create Rectangle From Line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local a = {} | |
local b = {} | |
local c = {} | |
local d = {} | |
a.x = 200 | |
a.y = 200 | |
b.x = 800 | |
b.y = 300 | |
deltaX = b.x - a.x | |
deltaY = b.y - a.y | |
deg = math.atan2(deltaY, deltaX) * 180 / math.pi | |
c.x = b.x + 20 * math.cos(math.rad(deg+90)) | |
c.y = b.y + 20 * math.sin(math.rad(deg+90)) | |
d.x = a.x + 20 * math.cos(math.rad(deg+90)) | |
d.y = a.y + 20 * math.sin(math.rad(deg+90)) | |
print("a.x = "..a.x..", a.y = "..a.y) | |
print("b.x = "..b.x..", b.y = "..b.y) | |
print("c.x = "..c.x..", c.y = "..c.y) | |
print("d.x = "..d.x..", d.y = "..d.y) | |
local lineA = display.newLine(a.x, a.y, b.x, b.y) | |
local lineB = display.newLine(b.x, b.y, c.x, c.y) | |
local lineC = display.newLine(c.x, c.y, d.x, d.y) | |
local lineD = display.newLine(d.x, d.y, a.x, a.y) | |
lineA.width = 5 | |
lineB.width = 5 | |
lineC.width = 5 | |
lineD.width = 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment