This commit is contained in:
Michael Fogleman 2017-01-15 22:02:53 -05:00
parent 0ec2ad29f7
commit 35bd0b6c05
4 changed files with 30 additions and 12 deletions

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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__':