Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoTrayIcon
- ; Convex Polygon Area
- ; http://redd.it/29umz8
- Global $Form, $idInput, $idOutput, $idButton
- $Form = GUICreate("Convex Polygon Area", 640, 360)
- GUISetFont(10, 1000, 0, "Courier New", $Form)
- $idInput = GUICtrlCreateEdit("Input", 20, 20, 300, 300)
- $idOutput = GUICtrlCreateEdit("", 320, 20, 300, 300)
- $idButton = GUICtrlCreateButton("Calculate", 200, 320, 120, 20)
- GUISetState(@SW_SHOW, $Form)
- Do
- Switch GUIGetMsg()
- Case -3
- ExitLoop
- Case $idButton
- GUICtrlSetData($idOutput, Abs(ConvexPolygonArea(GUICtrlRead($idInput))))
- EndSwitch
- Until False
- Exit
- Func ConvexPolygonArea($input)
- Local $area = 0, $lines, $n, $i, $a, $b
- $input = StringRegExpReplace($input, "^.+\r\n", "") ; remove first line
- $lines = StringSplit($input, @CRLF, 1)
- $n = $lines[0]
- For $i = 1 To $n
- $lines[$i] = StringSplit($lines[$i], ",", 2)
- Next
- For $i = 1 To $n
- $a = $lines[$i]
- $b = $lines[Mod($i, $n)+1]
- $area += $a[0]*$b[1] - $b[0]*$a[1]
- Next
- Return $area / 2
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement