-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_script.py
71 lines (54 loc) · 1.56 KB
/
draw_script.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
71
import asyncio
from typing import *
from argparse import ArgumentParser
from enum import IntEnum
import matplotlib.pyplot as plt
from matplotlib.axes import Axes as Axes
from matplotlib.figure import Figure as Figure
import numpy as np
from plot_clock import PlotClock
async def __got_to_indefinitely(plot_clock: PlotClock, points: List[List[float]]):
while True:
for p in points:
await plot_clock.got_to(p[0], p[1])
await asyncio.sleep(1)
async def __update_plot(ax: Axes, plot_clock: PlotClock, color: str = "b"):
while True:
t = ax.get_lines()
while len(t) > 0:
ax.lines.remove(t[-1])
t = ax.get_lines()
x, y = plot_clock.arms
ax.plot(x, y, color=color)
x, y = plot_clock.pen_trail
ax.plot(x, y, color='r')
plt.pause(.01)
await asyncio.sleep(.01)
async def __main(loop):
D = 2
lower = 2
upper = np.sqrt(5)
p = PlotClock(lower_arm_length=lower, upper_arm_length=upper, servo_distance=D, servo_speed=.005)
points = [
[0, 2],
[2, 2],
[2, 1.75],
[0, 1.75],
]
plt.style.use("dark_background")
fig = plt.figure()
ax0 = fig.add_subplot(1, 1, 1)
ax0.set_title("PlotClock")
ax0.axis("equal")
await asyncio.gather(
__update_plot(ax0, p),
__got_to_indefinitely(p, points)
)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(__main(loop))
except KeyboardInterrupt:
pass
finally:
pass