Have plotter follow MT mouse - a bit hacky still
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Mechanical Turk</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/${PROJECT_DIR_NAME}</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
</pydev_project>
|
|
@ -0,0 +1,16 @@
|
|||
[[source]]
|
||||
url = "https://pypi.python.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
tornado = "*"
|
||||
coloredlogs = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
||||
[packages.a209065]
|
||||
path = "./../../AxiDraw_API_v253r3"
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "58dec9ae9b9fda6e3430fe601c100edb07debda39e6f5530e0c8a5c3286938cf"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.7"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.python.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"a209065": {
|
||||
"path": "./../../AxiDraw_API_v253r3"
|
||||
},
|
||||
"coloredlogs": {
|
||||
"hashes": [
|
||||
"sha256:34fad2e342d5a559c31b6c889e8d14f97cb62c47d9a2ae7b5ed14ea10a79eff8",
|
||||
"sha256:b869a2dda3fa88154b9dd850e27828d8755bfab5a838a1c97fbc850c6e377c36"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==10.0"
|
||||
},
|
||||
"humanfriendly": {
|
||||
"hashes": [
|
||||
"sha256:23057b10ad6f782e7bc3a20e3cb6768ab919f619bbdc0dd75691121bbde5591d",
|
||||
"sha256:33ee8ceb63f1db61cce8b5c800c531e1a61023ac5488ccde2ba574a85be00a85"
|
||||
],
|
||||
"version": "==4.18"
|
||||
},
|
||||
"tornado": {
|
||||
"hashes": [
|
||||
"sha256:349884248c36801afa19e342a77cc4458caca694b0eda633f5878e458a44cb2c",
|
||||
"sha256:398e0d35e086ba38a0427c3b37f4337327231942e731edaa6e9fd1865bbd6f60",
|
||||
"sha256:4e73ef678b1a859f0cb29e1d895526a20ea64b5ffd510a2307b5998c7df24281",
|
||||
"sha256:559bce3d31484b665259f50cd94c5c28b961b09315ccd838f284687245f416e5",
|
||||
"sha256:abbe53a39734ef4aba061fca54e30c6b4639d3e1f59653f0da37a0003de148c7",
|
||||
"sha256:c845db36ba616912074c5b1ee897f8e0124df269468f25e4fe21fe72f6edd7a9",
|
||||
"sha256:c9399267c926a4e7c418baa5cbe91c7d1cf362d505a1ef898fde44a07c9dd8a5"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.0.3"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
from pyaxidraw import axidraw
|
||||
ad = axidraw.AxiDraw()
|
||||
ad.plot_setup()
|
||||
ad.options.mode = "manual"
|
||||
ad.options.manual_cmd = "disable_xy"
|
||||
ad.plot_run()
|
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 6.5 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 8.0 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg viewBox="0 0 600 600"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.1"
|
||||
>
|
||||
<path d="M308.0,244.0 l 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,1.0 1.0,0.0 0.0,1.0 1.0,0.0 1.0,1.0 0.0,1.0 1.0,1.0 0.0,1.0 2.0,2.0 1.0,0.0 0.0,1.0 2.0,1.0 1.0,0.0 1.0,1.0 1.0,1.0 0.0,1.0 1.0,1.0 2.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 0.0,-1.0 1.0,0.0 1.0,0.0 1.0,-1.0 1.0,0.0 1.0,0.0 2.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 3.0,0.0 2.0,0.0 1.0,0.0 3.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 1.0,0.0 2.0,0.0 2.0,1.0 1.0,1.0 2.0,0.0 1.0,2.0 0.0,0.0 " style="stroke:black;stroke-width:2;fill:none;" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 962 B |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 10 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg viewBox="0 0 600 600"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.1"
|
||||
>
|
||||
<path d="M153.0,226.0 l 10.0,-11.0 18.0,-20.0 21.0,-25.0 9.0,-7.0 3.0,-3.0 1.0,0.0 4.0,6.0 7.0,15.0 6.0,21.0 3.0,21.0 3.0,19.0 0.0,15.0 0.0,7.0 0.0,-4.0 9.0,-14.0 11.0,-11.0 9.0,-4.0 2.0,-1.0 1.0,0.0 2.0,4.0 2.0,18.0 0.0,24.0 -1.0,22.0 -8.0,24.0 -11.0,15.0 -3.0,0.0 -2.0,0.0 -7.0,-6.0 -7.0,-13.0 -6.0,-14.0 -2.0,-15.0 0.0,-15.0 0.0,-18.0 10.0,-19.0 14.0,-14.0 29.0,-13.0 17.0,-1.0 13.0,3.0 14.0,13.0 14.0,18.0 13.0,22.0 5.0,24.0 1.0,26.0 0.0,22.0 -3.0,15.0 -7.0,10.0 -5.0,1.0 -8.0,0.0 -26.0,0.0 -31.0,-5.0 -33.0,-13.0 -18.0,-10.0 -5.0,-9.0 -2.0,-14.0 0.0,-21.0 0.0,-24.0 4.0,-29.0 11.0,-38.0 24.0,-54.0 12.0,-25.0 12.0,-19.0 13.0,-18.0 8.0,-12.0 5.0,-9.0 1.0,-3.0 2.0,-2.0 -5.0,6.0 -11.0,15.0 -13.0,17.0 -9.0,17.0 -6.0,14.0 -4.0,11.0 -2.0,9.0 -2.0,5.0 0.0,2.0 0.0,-2.0 20.0,-40.0 25.0,-43.0 18.0,-31.0 8.0,-12.0 1.0,-1.0 0.0,3.0 0.0,26.0 -1.0,36.0 -7.0,50.0 -7.0,46.0 -4.0,26.0 0.0,2.0 0.0,-6.0 6.0,-19.0 21.0,-47.0 17.0,-41.0 13.0,-25.0 4.0,-12.0 0.0,4.0 0.0,11.0 -4.0,50.0 -5.0,39.0 -3.0,29.0 0.0,12.0 7.0,-8.0 16.0,-42.0 10.0,-21.0 11.0,-24.0 6.0,-16.0 0.0,1.0 0.0,23.0 0.0,36.0 -4.0,42.0 -7.0,37.0 -2.0,17.0 0.0,4.0 5.0,-20.0 13.0,-31.0 15.0,-43.0 9.0,-20.0 2.0,-6.0 1.0,0.0 0.0,3.0 -1.0,11.0 -2.0,24.0 -16.0,59.0 -13.0,40.0 -9.0,32.0 -7.0,22.0 0.0,4.0 -3.0,4.0 -4.0,8.0 -4.0,6.0 -4.0,6.0 -4.0,5.0 -8.0,9.0 -6.0,6.0 -5.0,5.0 -2.0,0.0 -1.0,0.0 -1.0,-14.0 4.0,-19.0 2.0,-10.0 0.0,0.0 m38.0,-68.0 l 0.0,5.0 -2.0,27.0 -4.0,21.0 -5.0,21.0 -8.0,17.0 -4.0,11.0 -5.0,11.0 -1.0,1.0 0.0,-1.0 6.0,-13.0 15.0,-22.0 21.0,-20.0 18.0,-18.0 14.0,-15.0 7.0,-9.0 2.0,-2.0 0.0,4.0 -1.0,17.0 -1.0,9.0 -11.0,31.0 -13.0,21.0 -9.0,15.0 -5.0,9.0 -5.0,8.0 -6.0,7.0 -9.0,9.0 -18.0,11.0 -12.0,5.0 -8.0,0.0 -6.0,2.0 -6.0,0.0 -4.0,0.0 -5.0,0.0 -7.0,0.0 -14.0,-2.0 -20.0,0.0 -22.0,0.0 -17.0,0.0 -14.0,-2.0 -7.0,-2.0 -14.0,-10.0 -12.0,-9.0 -36.0,-28.0 -14.0,-19.0 -11.0,-15.0 -5.0,-14.0 -3.0,-11.0 -2.0,-18.0 0.0,-6.0 3.0,-9.0 4.0,-8.0 5.0,-6.0 6.0,-8.0 8.0,-9.0 10.0,-13.0 11.0,-15.0 8.0,-14.0 4.0,-10.0 5.0,-12.0 4.0,-9.0 7.0,-22.0 2.0,-10.0 0.0,-3.0 0.0,-2.0 -1.0,5.0 -6.0,9.0 -18.0,37.0 -10.0,25.0 -4.0,49.0 0.0,15.0 0.0,16.0 1.0,17.0 3.0,23.0 0.0,9.0 0.0,10.0 0.0,13.0 -3.0,10.0 -1.0,2.0 -1.0,0.0 -1.0,1.0 -3.0,-1.0 -14.0,-12.0 -10.0,-8.0 -17.0,-18.0 -7.0,-10.0 -9.0,-20.0 -4.0,-16.0 -7.0,-25.0 -2.0,-41.0 0.0,-9.0 0.0,-11.0 0.0,-17.0 3.0,-11.0 5.0,-12.0 9.0,-16.0 7.0,-11.0 9.0,-13.0 11.0,-16.0 9.0,-10.0 12.0,-14.0 9.0,-12.0 12.0,-12.0 15.0,-15.0 10.0,-10.0 9.0,-9.0 9.0,-6.0 10.0,-4.0 11.0,0.0 10.0,-1.0 10.0,-2.0 10.0,1.0 5.0,3.0 6.0,4.0 14.0,11.0 9.0,9.0 6.0,9.0 14.0,24.0 9.0,12.0 18.0,16.0 10.0,9.0 8.0,4.0 11.0,6.0 13.0,6.0 13.0,7.0 12.0,5.0 9.0,4.0 8.0,8.0 12.0,15.0 11.0,16.0 15.0,34.0 6.0,25.0 5.0,26.0 2.0,24.0 0.0,20.0 0.0,15.0 0.0,11.0 -2.0,11.0 -2.0,8.0 -5.0,10.0 -8.0,12.0 -17.0,29.0 -11.0,20.0 -11.0,22.0 -11.0,17.0 -6.0,11.0 -4.0,8.0 -3.0,5.0 -5.0,6.0 -4.0,4.0 -9.0,6.0 -20.0,8.0 -20.0,4.0 -16.0,0.0 -23.0,0.0 -13.0,-3.0 -21.0,-13.0 -20.0,-13.0 -4.0,-2.0 -2.0,-1.0 -10.0,-1.0 -17.0,7.0 -12.0,11.0 -4.0,4.0 0.0,1.0 0.0,6.0 7.0,6.0 8.0,2.0 17.0,-3.0 29.0,-13.0 22.0,-4.0 10.0,0.0 14.0,0.0 27.0,8.0 26.0,2.0 24.0,2.0 39.0,0.0 43.0,-5.0 25.0,-10.0 4.0,-2.0 1.0,-1.0 0.0,1.0 -1.0,11.0 -10.0,15.0 -21.0,4.0 -35.0,0.0 -62.0,0.0 -92.0,0.0 -80.0,0.0 -34.0,-4.0 -12.0,-9.0 -11.0,-12.0 -9.0,-25.0 -3.0,-31.0 -5.0,-31.0 -4.0,-28.0 -6.0,-24.0 -6.0,-20.0 -2.0,-11.0 -2.0,-6.0 -7.0,-11.0 -9.0,-12.0 -9.0,-9.0 -12.0,-17.0 -6.0,-14.0 -4.0,-20.0 -3.0,-22.0 -1.0,-25.0 -2.0,-20.0 -3.0,-14.0 -1.0,-11.0 -2.0,-5.0 -2.0,-3.0 -1.0,0.0 -5.0,1.0 -11.0,26.0 -4.0,25.0 0.0,25.0 5.0,33.0 9.0,35.0 6.0,39.0 6.0,34.0 6.0,26.0 2.0,23.0 -1.0,20.0 -7.0,12.0 -2.0,4.0 -1.0,1.0 -2.0,1.0 -2.0,2.0 -3.0,4.0 -2.0,5.0 0.0,1.0 1.0,1.0 12.0,-13.0 25.0,-29.0 40.0,-48.0 30.0,-40.0 57.0,-63.0 62.0,-54.0 20.0,-18.0 1.0,-3.0 0.0,0.0 " style="stroke:black;stroke-width:2;fill:none;" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 15 KiB |
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
id="svg8"
|
||||
version="1.1"
|
||||
viewBox="0 0 210 210"
|
||||
height="210mm"
|
||||
width="210mm">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
transform="translate(0,-87)"
|
||||
id="layer1">
|
||||
<rect
|
||||
y="138.32738"
|
||||
x="51.327381"
|
||||
height="107.34524"
|
||||
width="107.34524"
|
||||
id="rect815"
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.75590557;stroke-opacity:1" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
74
server.py
|
@ -11,6 +11,12 @@ import uuid
|
|||
import coloredlogs
|
||||
import glob
|
||||
|
||||
from pyaxidraw import axidraw # import module
|
||||
from threading import Thread
|
||||
from queue import Queue, Empty
|
||||
import threading
|
||||
|
||||
|
||||
|
||||
logger = logging.getLogger("drawing")
|
||||
|
||||
|
@ -63,6 +69,9 @@ class StaticFileWithHeaderHandler(tornado.web.StaticFileHandler):
|
|||
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
||||
CORS_ORIGINS = ['localhost', '.mturk.com', 'here.rubenvandeven.com']
|
||||
connections = set()
|
||||
|
||||
def initialize(self, draw_q: Queue):
|
||||
self.draw_q = draw_q
|
||||
|
||||
def check_origin(self, origin):
|
||||
parsed_origin = urlparse(origin)
|
||||
|
@ -85,8 +94,9 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|||
# TODO: sanitize input: min/max, limit strokes
|
||||
if msg['action'] == 'move':
|
||||
# TODO: min/max input
|
||||
point = [float(msg['direction'][0]),float(msg['direction'][1]), 0]
|
||||
point = [float(msg['direction'][0]),float(msg['direction'][1]), bool(msg['mouse'])]
|
||||
self.strokes.append(point)
|
||||
self.draw_q.put(point)
|
||||
|
||||
elif msg['action'] == 'up':
|
||||
logger.info(f'up: {msg}')
|
||||
|
@ -164,12 +174,47 @@ class LatestImageHandler(tornado.web.RequestHandler):
|
|||
with open(latest_file, 'r') as fp:
|
||||
self.write(fp.read())
|
||||
|
||||
def axiDrawCueListener(q: Queue, isRunning: threading.Event):
|
||||
ad = axidraw.AxiDraw()
|
||||
|
||||
try:
|
||||
ad.interactive()
|
||||
|
||||
ad.connect()
|
||||
ad.options.units = 1 # set to use centimeters instead of inches
|
||||
ad.options.accel = 100;
|
||||
ad.options.speed_penup = 100
|
||||
ad.options.speed_pendown = 100
|
||||
ad.options.model = 2 # A3, set to 1 for A4
|
||||
|
||||
ad.moveto(0,0)
|
||||
|
||||
plotterWidth = 22
|
||||
plotterHeight = 18 # 16?
|
||||
|
||||
while isRunning.is_set():
|
||||
# TODO: set timeout on .get() with catch block, so we can escape if no moves come in
|
||||
try:
|
||||
move = draw_q.get(True, 1)
|
||||
except Empty as e:
|
||||
logger.log(5, "Empty queue.")
|
||||
else:
|
||||
ad.moveto(move[0]* plotterWidth, move[1]*plotterHeight)
|
||||
print('handler!',move)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
finally:
|
||||
logger.warning("Close Axidraw connection")
|
||||
ad.moveto(0,0)
|
||||
ad.disconnect()
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = argParser.parse_args()
|
||||
|
||||
coloredlogs.install(
|
||||
level=logging.DEBUG if args.verbose else logging.INFO,
|
||||
)
|
||||
|
||||
formatter = logging.Formatter(fmt='%(asctime)s %(module)s:%(lineno)d %(levelname)8s | %(message)s',
|
||||
datefmt='%Y/%m/%d %H:%M:%S') # %I:%M:%S %p AM|PM format
|
||||
logFileHandler = logging.handlers.RotatingFileHandler(
|
||||
|
@ -181,13 +226,22 @@ if __name__ == "__main__":
|
|||
logger.addHandler(
|
||||
logFileHandler
|
||||
)
|
||||
|
||||
draw_q = Queue()
|
||||
isRunning = threading.Event()
|
||||
isRunning.set()
|
||||
|
||||
thread = Thread(target = axiDrawCueListener, args = (draw_q, isRunning))
|
||||
thread.start()
|
||||
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/ws(.*)", WebSocketHandler),
|
||||
(r"/latest.svg", LatestImageHandler), # TODO: have js request the right image, based on a 'start' button. This way we can trace the history of a drawing
|
||||
(r"/(.*)", StaticFileWithHeaderHandler,
|
||||
{"path": 'www', "default_filename": 'index.html'}),
|
||||
], debug=True)
|
||||
application.listen(args.port)
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
try:
|
||||
application = tornado.web.Application([
|
||||
(r"/ws(.*)", WebSocketHandler, {'draw_q': draw_q}),
|
||||
(r"/latest.svg", LatestImageHandler), # TODO: have js request the right image, based on a 'start' button. This way we can trace the history of a drawing
|
||||
(r"/(.*)", StaticFileWithHeaderHandler,
|
||||
{"path": 'www', "default_filename": 'index.html'}),
|
||||
], debug=True)
|
||||
application.listen(args.port)
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
finally:
|
||||
isRunning.clear()
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
background:#ccc;
|
||||
|
||||
}
|
||||
html, body{
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -65,8 +69,11 @@
|
|||
let resetEl = document.getElementById('reset');
|
||||
let messageEl = document.getElementById('message');
|
||||
|
||||
|
||||
let strokes = [];
|
||||
let isDrawing = false;
|
||||
let currentPoint = null;
|
||||
|
||||
let draw = function(e) {
|
||||
let pos = svgEl.getBoundingClientRect()
|
||||
let x = e.x - pos['left'];
|
||||
|
@ -77,18 +84,29 @@
|
|||
console.log(d);
|
||||
strokeEl.setAttribute('d', d);
|
||||
|
||||
socket.send(JSON.stringify({
|
||||
currentPoint = {
|
||||
'action': 'move',
|
||||
'direction': [x, y]
|
||||
}));
|
||||
'direction': [e.x/window.innerWidth, e.y/window.innerHeight],
|
||||
'mouse': isDrawing,
|
||||
};
|
||||
console.log([x,y], isDrawing);
|
||||
};
|
||||
|
||||
let interval = window.setInterval(function(){
|
||||
if(currentPoint === null) {
|
||||
return
|
||||
}
|
||||
|
||||
socket.send(JSON.stringify(currentPoint));
|
||||
}, 200);
|
||||
|
||||
let penup = function(e) {
|
||||
if(!isDrawing) {
|
||||
return;
|
||||
}
|
||||
isDrawing = false;
|
||||
|
||||
document.body.removeEventListener('mousemove', draw);
|
||||
//document.body.removeEventListener('mousemove', draw);
|
||||
|
||||
let pos = svgEl.getBoundingClientRect()
|
||||
let x = e.x - pos['left'];
|
||||
|
@ -133,7 +151,7 @@
|
|||
let startDrawing = function(e){
|
||||
isDrawing = true;
|
||||
// start drawing
|
||||
document.body.addEventListener('mousemove', draw);
|
||||
//document.body.addEventListener('mousemove', draw);
|
||||
|
||||
};
|
||||
let reset = function() {
|
||||
|
@ -146,6 +164,9 @@
|
|||
|
||||
|
||||
let socket = new WebSocket(url);
|
||||
document.body.addEventListener('mousemove', draw);
|
||||
document.body.addEventListener('mouseup', penup);
|
||||
document.body.addEventListener('mousedown', startDrawing);
|
||||
|
||||
socket.addEventListener('message', function(e){
|
||||
let msg = JSON.parse(e.data);
|
||||
|
@ -157,8 +178,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('mouseup', penup);
|
||||
svgEl.addEventListener('mousedown', startDrawing);
|
||||
//svgEl.addEventListener('mousedown', startDrawing);
|
||||
resetEl.addEventListener('click', reset);
|
||||
submitEl.addEventListener('click', function(e){
|
||||
if(!strokes.length){
|
||||
|
|
After Width: | Height: | Size: 144 KiB |