2017-01-09 04:11:33 +00:00
|
|
|
import axi
|
2017-01-14 03:18:02 +00:00
|
|
|
import math
|
2017-01-09 04:11:33 +00:00
|
|
|
import random
|
|
|
|
import time
|
|
|
|
|
2017-01-14 03:18:02 +00:00
|
|
|
def circle(cx, cy, radius, n, rotation):
|
|
|
|
points = []
|
|
|
|
for i in range(n + 1):
|
|
|
|
a = 2 * math.pi * i / n + rotation
|
|
|
|
x = cx + math.cos(a) * radius
|
|
|
|
y = cy + math.sin(a) * radius
|
|
|
|
points.append((x, y))
|
|
|
|
return points
|
|
|
|
|
2017-01-09 04:11:33 +00:00
|
|
|
def main():
|
|
|
|
d = axi.Device()
|
|
|
|
d.pen_up()
|
|
|
|
d.enable_motors()
|
|
|
|
time.sleep(0.2)
|
|
|
|
points = []
|
|
|
|
points.append((0, 0))
|
|
|
|
for i in range(10):
|
2017-01-14 03:18:02 +00:00
|
|
|
while True:
|
|
|
|
x = random.random() * 11
|
|
|
|
y = random.random() * 8.5
|
|
|
|
r = random.random() * 4
|
|
|
|
if x - r < 0 or x + r > 11:
|
|
|
|
continue
|
|
|
|
if y - r < 0 or y + r > 8.5:
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
rotation = random.random() * 2 * math.pi
|
|
|
|
c = circle(x, y, r, 90, rotation)
|
|
|
|
if random.random() < 0.5:
|
|
|
|
c = list(reversed(c))
|
|
|
|
points.extend(c)
|
2017-01-09 04:11:33 +00:00
|
|
|
points.append((0, 0))
|
|
|
|
d.run_path(points)
|
|
|
|
d.wait()
|
|
|
|
d.disable_motors()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|