Commit ba0f7fca authored by ludi's avatar ludi
Browse files

Merge branch 'master' of git.constantvzw.org:relearn.can-it-scale-to-the-universe

parents cf9b17df a8b16289
#! /usr/bin/env python2
"""
Usage:
./gpx2hpgl.py <file.hpgl>
VS
de 1 a 42 cms par secondes
To test out: try to draw an A3 by walking around
try to use the grid on the floor in front of the house to reproduce drawings
"""
from lxml import etree
import datetime
import math
hpgl = "IN\n"
FACTOR = 100000
import sys
from lxml import etree
NS = 'http://www.topografix.com/GPX/1/0'
f = open('pierreh-2013-08-28T153250.gpx')
tree = etree.parse(f)
trkpts = tree.xpath('//gpx:trkpt', namespaces={'gpx': NS})
"""
+----------+
| P2 |
| + |
| : |
| : |
| : |
| + |
| P1 |
+----------+
"""
#ISO A3 = 403.95mm x 276mm = 16158 units x 11040 units
WIDTH = 403.95 # mm
HEIGHT = 276 # mm
XMAX = 16158 # Remember we are working on A3
YMAX = 11040
MAX_VELOCITY = 41
assert (XMAX / WIDTH) == (YMAX / HEIGHT)
mm = XMAX / WIDTH # mm to plotter unit conversion
#XP1
#YP1
#XP2
#YP2
def walk(tree):
trkpts = tree.xpath('//gpx:trkpt', namespaces={'gpx': NS})
for trkpt in trkpts:
lon = float(trkpt.attrib['lon'])
lat = float(trkpt.attrib['lat'])
ele = trkpt.find('{%s}ele' % NS).text
time = trkpt.find('{%s}time' % NS).text
time = datetime.datetime.strptime(time, "%Y-%m-%dT%H:%M:%SZ")
yield dict(lon=lon, lat=lat, ele=ele, time=time)
def velocities(trkpts):
"""
l'anecdote du poteau en plus
"""
for i, trkpt in enumerate(trkpts[1:]):
ab = trkpt['lon'] - trkpts[i]['lon']
bc = trkpt['lat'] - trkpts[i]['lat']
ac = math.sqrt(ab**2 + bc**2)
delta = trkpt['time'] - trkpts[i]['time']
velocity = ac / delta.seconds
yield velocity
def main(f):
f = open(f)
tree = etree.parse(f)
trkpts = list(walk(tree))
min_lon = min(d['lon'] for d in trkpts)
max_lon = max(d['lon'] for d in trkpts)
min_lat = min(d['lat'] for d in trkpts)
max_lat = max(d['lat'] for d in trkpts)
trkpt = trkpts[0]
min_velocity = min([v for v in velocities(trkpts)])
max_velocity = max([v for v in velocities(trkpts)])
shift_x = 200
shift_y = 200
old_lon = float(trkpt.attrib['lon'])
old_lat = float(trkpt.attrib['lat'])
hpgl = "IN\n"
hpgl += "IP0,%s,0,%s;\n" % (XMAX, YMAX)
hpgl += "SC%s,%s,%s,%s;\n" % (0, XMAX / mm, 0, YMAX / mm)
hpgl += "SP1;\n"
hpgl += "PD;\n"
old_ele = trkpt.find('{%s}ele' % NS).text
old_time = trkpt.find('{%s}time' % NS).text
old_time = datetime.datetime.strptime(old_time, "%Y-%m-%dT%H:%M:%SZ")
for i, trkpt in enumerate(trkpts[1:]):
ab = trkpt['lon'] - trkpts[i]['lon']
bc = trkpt['lat'] - trkpts[i]['lat']
ac = math.sqrt(ab**2 + bc**2)
delta = trkpt['time'] - trkpts[i]['time']
hpgl += "IP%s,%s;\n" % (str(old_lon).replace('.', ','), str(old_lon).replace('.', ','))
hpgl += "SC1488,0,0,1052;\n"
hpgl += "SP1;\n"
# From Roland's user manual:
# Changing Maximum Plotting Speed The DIP switches on the back of the
# DXY can be used to change the maximum plotting speed. When shipped
# from the factory, maximum plotting speed is set at 420 mm
# (16-9/16")/sec (all directions), but when set to [FAST] , maximum
# plotting speed is 600 mm (23-5/8")/sec (45 degrees orientation).
velocity = ac / delta.seconds
velocity = (((velocity - min_velocity) / (max_velocity - min_velocity)) * MAX_VELOCITY) + 1
#print(velocity)
for trkpt in trkpts[1:]:
lon = float(trkpt.attrib['lon'])
lat = float(trkpt.attrib['lat'])
ele = trkpt.find('{%s}ele' % NS).text
time = trkpt.find('{%s}time' % NS).text
time = datetime.datetime.strptime(time, "%Y-%m-%dT%H:%M:%SZ")
hpgl += "VS%s;\n" % velocity
ab = lon - old_lon
bc = lat - old_lat
# plot the first point
if i == 0:
lon = (((trkpts[0]['lon'] - min_lon) / (max_lon - min_lon)) * XMAX) / mm
lat = (((trkpts[0]['lat'] - min_lat) / (max_lon - min_lon)) * XMAX) / mm
hpgl += "PA%s,%s;\n" % (lon, lat)
ac = math.sqrt(ab**2 + bc**2)
lon = (((trkpt['lon'] - min_lon) / (max_lon - min_lon)) * XMAX) / mm
lat = (((trkpt['lat'] - min_lat) / (max_lon - min_lon)) * XMAX) / mm
time_delta = time - old_time
hpgl += "VS%s,%s;\n" % (time_delta.seconds, time_delta.microseconds)
hpgl += "PA%s,%s;\n" % (str(lon).replace('.', ','), str(lat).replace('.', ','))
#lon = int(lon / mm)
#lat = int(lat / mm)
old_lat = lat
old_lon = lon
old_ele = ele
old_time = time
hpgl += "PA%s,%s;\n" % (lon, lat)
hpgl += "\n"
hpgl += 'PU;\n'
hpgl += 'PU;\n'
hpgl += 'SP0;\n'
print(hpgl)
print(hpgl)
if __name__ == "__main__":
try:
f = sys.argv[1]
except IndexError:
print("Usage:\n ./gpx2hpgl.py <file.hpgl>")
sys.exit()
main(f)
pattern ="""
||N||-||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||O||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||T||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||H||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||-|||||-||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||N||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||-||G||-||-||-||-||-||-||-||-
||N||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||O||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||T||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||H||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!|||||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||N||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||G||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||T||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||O||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||S||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||E||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||E||!||!||!||!
||N||-||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||O||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||T||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||H||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||-|||||-||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||N||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||-||G||-||-||-||-||-||-||-||-
||N||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||O||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||T||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||H||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!|||||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||N||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||G||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||T||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||O||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||S||!||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||E||!||!||!||!||!
||!||!||!||!||!||!||!||!||!||!||E||!||!||!||!
||N||-||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||O||-||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||T||-||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||H||-||-||-||-||-||-||-||-||-||-||-
||-||-||-||-|||||-||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||N||-||-||-||-||-||-||-||-||-
||-||-||-||-||-||-||G||-||-||-||-||-||-||-||-
"""
inflated = ""
lines = pattern.split("\n")
w = len(lines)
for line in lines:
for c in line:
inflated += c
inflated += c
inflated += c
inflated += "\n"
inflated_lines = ""
lines = inflated.split("\n")
for line in lines:
inflated_lines += '"' + line + '", \n'
inflated_lines += '"' + line + '", \n'
inflated_lines += '"' + line + '", \n'
h = len(inflated_lines)
header = """
static char *moon[] = {
/* columns rows colors chars-per-pixel */
"%s %s 11 1 ",
"| c black",
"- c gray100",
"! c gray50",
"N c pink",
"O c pink",
"T c pink",
"H c pink",
"I c pink",
"G c pink",
"S c pink",
"E c pink",
""" % (w, h)
footer = "};"
print header + inflated_lines + footer
#print w
#print h
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment