From c5be87b7b25943656a7121744e405bf19864f864 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 29 Jan 2018 13:44:44 -0500 Subject: [PATCH] wip --- axi/device.py | 18 ++++++++++++----- axi/drawing.py | 5 +++-- examples/nes.py | 51 ++++++++++++++++++++++++++++++++++++++--------- examples/paths.py | 10 ++++++---- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/axi/device.py b/axi/device.py index 16e3831..6acd802 100644 --- a/axi/device.py +++ b/axi/device.py @@ -9,9 +9,9 @@ from serial.tools.list_ports import comports from .planner import Planner from .progress import Bar -TIMESLICE_MS = 20 +TIMESLICE_MS = 10 -MICROSTEPPING_MODE = 2 +MICROSTEPPING_MODE = 1 STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1) STEPS_PER_INCH = 2032 / STEP_DIVIDER @@ -25,9 +25,17 @@ PEN_DOWN_POSITION = 40 PEN_DOWN_SPEED = 150 PEN_DOWN_DELAY = 0 -ACCELERATION = 8 -MAX_VELOCITY = 6 -CORNER_FACTOR = 0.005 * 2 +# ACCELERATION = 8 +# MAX_VELOCITY = 6 +# CORNER_FACTOR = 0.005 + +ACCELERATION = 6 +MAX_VELOCITY = 4 +CORNER_FACTOR = 0.0025 + +# ACCELERATION = 4 +# MAX_VELOCITY = 1 +# CORNER_FACTOR = 0.001 VID_PID = '04D8:FD92' diff --git a/axi/drawing.py b/axi/drawing.py index 520a1a8..57b9483 100644 --- a/axi/drawing.py +++ b/axi/drawing.py @@ -175,8 +175,9 @@ class Drawing(object): for angle in range(0, 180, step): drawing = self.rotate(angle) scale = min(width / drawing.width, height / drawing.height) - drawings.append((scale, drawing)) - scale, drawing = max(drawings) + drawings.append((scale, angle, drawing)) + scale, angle, drawing = max(drawings) + print angle return drawing.scale(scale, scale).center(width, height) def remove_paths_outside(self, width, height): diff --git a/examples/nes.py b/examples/nes.py index f6c7d5c..06f51af 100644 --- a/examples/nes.py +++ b/examples/nes.py @@ -5,14 +5,36 @@ import numpy as np import os import sys -NUMBER = 5 -TITLE = 'Five Seconds of Donkey Kong' +NUMBER = '19' +TITLE = 'Fifteen Seconds of The Legend of Zelda' LABEL = '#%s' % NUMBER -COLUMNS = 6 -SECONDS = 5 -FRAME_OFFSET = -150 -MIN_CHANGES = 1 +COLUMNS = 8 +SECONDS = 15 +FRAME_OFFSET = 600 +MIN_CHANGES = 2 +UNIQUE = False +SIMPLIFY = 5 + +def simplify_sparkline(values, n): + if not n: + return values + result = [] + previous = None + for x, y in enumerate(values): + if result: + window = result[-n:] + lo = min(window) + hi = max(window) + if y >= lo and y <= hi: + result.append(result[-1]) + previous = y + continue + if previous is not None: + result[-1] = previous + result.append(y) + previous = y + return result def stack_drawings(ds, spacing=0): result = axi.Drawing() @@ -52,7 +74,6 @@ def main(): # read values and transpose data = [map(int, line.split(',')) for line in lines] data = np.transpose(data) - print '%d series in file' % len(data) # trim to SECONDS worth of data @@ -65,12 +86,23 @@ def main(): # remove addresses with too few values data = [x for x in data if len(set(x)) > MIN_CHANGES] - print '%d series that changed' % len(data) + # remove duplicate series + if UNIQUE: + new_data = [] + seen = set() + for x in data: + k = tuple(x) + if k in seen: + continue + seen.add(k) + new_data.append(x) + data = new_data + print '%d unique series' % len(data) + # trim so all rows are full data = data[:int((len(data) // COLUMNS) * COLUMNS)] - print '%d series after trimming' % len(data) print '%d data points each' % len(data[0]) @@ -78,6 +110,7 @@ def main(): # create sparklines in a grid pattern paths = [] for i, row in enumerate(data): + row = simplify_sparkline(row, SIMPLIFY) r = i // COLUMNS c = i % COLUMNS lo = min(row) diff --git a/examples/paths.py b/examples/paths.py index 5415d99..2ca9225 100644 --- a/examples/paths.py +++ b/examples/paths.py @@ -5,20 +5,22 @@ def main(): filename = sys.argv[1] print 'loading paths' d = axi.Drawing(axi.load_paths(filename)) - print 'eliminating duplicate paths' - d.paths = list(set([tuple(x) for x in d.paths])) + # print 'eliminating duplicate paths' + # d.paths = list(set([tuple(x) for x in d.paths])) + print 'joining paths' + d = d.join_paths(0.001) print 'transforming paths' d = d.scale(1, -1) d = d.rotate_and_scale_to_fit(12, 8.5, step=90) print 'sorting paths' d = d.sort_paths() print 'joining paths' - d = d.join_paths(0.02) + d = d.join_paths(0.01) print 'simplifying paths' d = d.simplify_paths(0.001) print 'rendering paths' d.render(line_width=0.25/25.4).write_to_png('out.png') - axi.draw(d) + # axi.draw(d) if __name__ == '__main__': main()