diff --git a/axi/__init__.py b/axi/__init__.py index 1e8d3d7..d25e68d 100644 --- a/axi/__init__.py +++ b/axi/__init__.py @@ -1,6 +1,6 @@ from .device import Device from .drawing import Drawing -from .paths import simplify_paths, sort_paths, join_paths +from .paths import simplify_paths, sort_paths, join_paths, load_paths from .planner import Planner from .turtle import Turtle from .util import draw, reset diff --git a/axi/device.py b/axi/device.py index 0143cb1..64a9f97 100644 --- a/axi/device.py +++ b/axi/device.py @@ -8,9 +8,9 @@ from serial.tools.list_ports import comports from .planner import Planner -TIMESLICE_MS = 10 +TIMESLICE_MS = 20 -MICROSTEPPING_MODE = 1 +MICROSTEPPING_MODE = 2 STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1) STEPS_PER_INCH = 2032 / STEP_DIVIDER @@ -26,7 +26,7 @@ PEN_DOWN_DELAY = 0 ACCELERATION = 8 MAX_VELOCITY = 8 -CORNER_FACTOR = 0.005 +CORNER_FACTOR = 0.0005 VID_PID = '04D8:FD92' diff --git a/axi/paths.py b/axi/paths.py index 72c87c6..c90dc16 100644 --- a/axi/paths.py +++ b/axi/paths.py @@ -3,6 +3,17 @@ from shapely.geometry import LineString from .spatial import Index +def load_paths(filename): + paths = [] + with open(filename) as fp: + for line in fp: + points = filter(None, line.strip().split(';')) + if not points: + continue + path = [tuple(map(float, x.split(','))) for x in points] + paths.append(path) + return paths + def simplify_path(points, tolerance): if len(points) < 2: return points diff --git a/examples/growth.py b/examples/growth.py index 7bb1b38..edcfc07 100644 --- a/examples/growth.py +++ b/examples/growth.py @@ -49,15 +49,23 @@ class Grid(object): self.lines.pop((i, j)) def max_angle(i, d): + if d < 0.1: + return pi + return pi / 4 a1 = 2 * pi a2 = pi / 2 p = min(1, d / 20.0) p = p ** 0.5 return a1 + (a2 - a1) * p +def new_angle(a, d): + if d < 0.1: + return random.random() * 2 * pi + else: + return random.gauss(a, pi / 10) + def choice(items): - # return random.choice(items) - p = random.random() ** 0.1 + p = random.random() ** 0.5 return items[int(p * len(items))] def poisson_disc(x1, y1, x2, y2, r, n): @@ -76,8 +84,9 @@ def poisson_disc(x1, y1, x2, y2, r, n): ax, ay, aa, ai, ad, ag = record = choice(active) for i in range(n): # a = random.random() * 2 * pi - a = aa + (random.random() - 0.5) * max_angle(ai, ad) + # a = aa + (random.random() * 2 - 1) * max_angle(ai, ad) # a = random.gauss(aa, pi / 8) + a = new_angle(aa, ad) d = random.random() * r + r x = ax + cos(a) * d y = ay + sin(a) * d @@ -92,8 +101,6 @@ def poisson_disc(x1, y1, x2, y2, r, n): pairs.append(pair) active.append((x, y, a, ai + 1, ad + d, ag)) active.sort(key=lambda x: -x[4]) - # if random.random() < 0.5: - # active.remove(record) break else: active.remove(record) @@ -118,11 +125,11 @@ def make_path(pairs): return path def main(): - random.seed(1182) - points, pairs = poisson_disc(0, 0, 11, 8.5, 0.05, 24) + # random.seed(1182) + points, pairs = poisson_disc(0, 0, 11, 8.5, 0.035, 32) path = make_path(pairs) drawing = axi.Drawing([path]).scale_to_fit(11, 8.5) - # drawing.render().write_to_png('out.png') + drawing.render().write_to_png('out.png') axi.draw(drawing) if __name__ == '__main__':