-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
70 lines (52 loc) · 2.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import csv
from argparse import ArgumentParser
from atexit import register
from matplotlib import pyplot as plt
from libs.click_generator import ClickGenerator
from libs.random_generator import RandomGenerator
def exit_handler(x, y, z):
with open("waypoints.csv", "w", newline='') as f:
writer = csv.writer(f)
if z:
writer.writerow(['x', 'y', 'z'])
writer.writerows(zip(x, y, z))
else:
writer.writerow(['x', 'y'])
writer.writerows(zip(x, y))
def main():
args, _ = parse_args()
try:
# Parameters
map_size = 100
line_colour = '#F0A39A'
point_colour = '#383831'
fig = plt.figure()
ax = plt.axes()
ax.set_aspect('equal', adjustable='box')
ax.set_xlim(-map_size, map_size)
ax.set_ylim(-map_size, map_size)
z = None
if args.random:
rand_gen = RandomGenerator(ax, fig, args.random, map_size, line_colour, point_colour)
x, y = rand_gen.generate()
elif args.click:
use_z = args.three_dimension
scroll_sensitivity = args.scroll_sensitivity
click_gen = ClickGenerator(ax, fig, map_size, line_colour, point_colour, use_z, scroll_sensitivity)
x, y, z = click_gen.generate()
else:
raise Exception("Invalid argument.")
plt.grid()
plt.show()
register(exit_handler, x, y, z)
except KeyboardInterrupt:
register(exit_handler, x, y, z)
def parse_args():
parser = ArgumentParser(description='Generator type')
parser.add_argument('-r', '--random', type=int, metavar='', help='Generates a user-selected amount of random waypoints')
parser.add_argument('-c', '--click', action='store_true', help='Generates user-selected waypoint positions')
parser.add_argument('-z', '--three-dimension', action='store_true', help='Allows user to change the z-axis of a created waypoint')
parser.add_argument('-s', '--scroll-sensitivity', type=float, metavar='', help='Sets the scroll sensitivity of the mouse when setting the z-axis')
return parser.parse_known_args()
if __name__ == '__main__':
main()