This commit is contained in:
Michael Fogleman 2018-01-29 13:44:44 -05:00
parent c3c3f62fdf
commit c5be87b7b2
4 changed files with 64 additions and 20 deletions

View File

@ -9,9 +9,9 @@ from serial.tools.list_ports import comports
from .planner import Planner from .planner import Planner
from .progress import Bar from .progress import Bar
TIMESLICE_MS = 20 TIMESLICE_MS = 10
MICROSTEPPING_MODE = 2 MICROSTEPPING_MODE = 1
STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1) STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1)
STEPS_PER_INCH = 2032 / STEP_DIVIDER STEPS_PER_INCH = 2032 / STEP_DIVIDER
@ -25,9 +25,17 @@ PEN_DOWN_POSITION = 40
PEN_DOWN_SPEED = 150 PEN_DOWN_SPEED = 150
PEN_DOWN_DELAY = 0 PEN_DOWN_DELAY = 0
ACCELERATION = 8 # ACCELERATION = 8
MAX_VELOCITY = 6 # MAX_VELOCITY = 6
CORNER_FACTOR = 0.005 * 2 # 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' VID_PID = '04D8:FD92'

View File

@ -175,8 +175,9 @@ class Drawing(object):
for angle in range(0, 180, step): for angle in range(0, 180, step):
drawing = self.rotate(angle) drawing = self.rotate(angle)
scale = min(width / drawing.width, height / drawing.height) scale = min(width / drawing.width, height / drawing.height)
drawings.append((scale, drawing)) drawings.append((scale, angle, drawing))
scale, drawing = max(drawings) scale, angle, drawing = max(drawings)
print angle
return drawing.scale(scale, scale).center(width, height) return drawing.scale(scale, scale).center(width, height)
def remove_paths_outside(self, width, height): def remove_paths_outside(self, width, height):

View File

@ -5,14 +5,36 @@ import numpy as np
import os import os
import sys import sys
NUMBER = 5 NUMBER = '19'
TITLE = 'Five Seconds of Donkey Kong' TITLE = 'Fifteen Seconds of The Legend of Zelda'
LABEL = '#%s' % NUMBER LABEL = '#%s' % NUMBER
COLUMNS = 6 COLUMNS = 8
SECONDS = 5 SECONDS = 15
FRAME_OFFSET = -150 FRAME_OFFSET = 600
MIN_CHANGES = 1 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): def stack_drawings(ds, spacing=0):
result = axi.Drawing() result = axi.Drawing()
@ -52,7 +74,6 @@ def main():
# read values and transpose # read values and transpose
data = [map(int, line.split(',')) for line in lines] data = [map(int, line.split(',')) for line in lines]
data = np.transpose(data) data = np.transpose(data)
print '%d series in file' % len(data) print '%d series in file' % len(data)
# trim to SECONDS worth of data # trim to SECONDS worth of data
@ -65,12 +86,23 @@ def main():
# remove addresses with too few values # remove addresses with too few values
data = [x for x in data if len(set(x)) > MIN_CHANGES] data = [x for x in data if len(set(x)) > MIN_CHANGES]
print '%d series that changed' % len(data) 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 # trim so all rows are full
data = data[:int((len(data) // COLUMNS) * COLUMNS)] data = data[:int((len(data) // COLUMNS) * COLUMNS)]
print '%d series after trimming' % len(data) print '%d series after trimming' % len(data)
print '%d data points each' % len(data[0]) print '%d data points each' % len(data[0])
@ -78,6 +110,7 @@ def main():
# create sparklines in a grid pattern # create sparklines in a grid pattern
paths = [] paths = []
for i, row in enumerate(data): for i, row in enumerate(data):
row = simplify_sparkline(row, SIMPLIFY)
r = i // COLUMNS r = i // COLUMNS
c = i % COLUMNS c = i % COLUMNS
lo = min(row) lo = min(row)

View File

@ -5,20 +5,22 @@ def main():
filename = sys.argv[1] filename = sys.argv[1]
print 'loading paths' print 'loading paths'
d = axi.Drawing(axi.load_paths(filename)) d = axi.Drawing(axi.load_paths(filename))
print 'eliminating duplicate paths' # print 'eliminating duplicate paths'
d.paths = list(set([tuple(x) for x in d.paths])) # d.paths = list(set([tuple(x) for x in d.paths]))
print 'joining paths'
d = d.join_paths(0.001)
print 'transforming paths' print 'transforming paths'
d = d.scale(1, -1) d = d.scale(1, -1)
d = d.rotate_and_scale_to_fit(12, 8.5, step=90) d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
print 'sorting paths' print 'sorting paths'
d = d.sort_paths() d = d.sort_paths()
print 'joining paths' print 'joining paths'
d = d.join_paths(0.02) d = d.join_paths(0.01)
print 'simplifying paths' print 'simplifying paths'
d = d.simplify_paths(0.001) d = d.simplify_paths(0.001)
print 'rendering paths' print 'rendering paths'
d.render(line_width=0.25/25.4).write_to_png('out.png') d.render(line_width=0.25/25.4).write_to_png('out.png')
axi.draw(d) # axi.draw(d)
if __name__ == '__main__': if __name__ == '__main__':
main() main()