• Stars
    star
    161
  • Rank 225,555 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use JavaScript to draw on any flat surface with the friendly AxiDraw robot

AxiDrawJS

Description

AxiDrawJS allows you to use JavaScript to draw on any flat surface with an AxiDraw1.

The AxiDraw V3 is a simple, modern, and precise pen plotter, capable of writing or drawing on almost any flat surface. It can write with fountain pens, permanent markers, and a variety of other writing implements to handle an endless number of applications.

Animated Drawing

Examples

This repository includes some basic APIs and the following designs and guides:

  • Map - choose a city and draw the streets
  • Terrain - pseudo 3D map for mountains and hills
  • Lorenz - the well-known Lorenz attractor
  • JSConf - the logo of our favorite conference
  • Label Only - to draw it using a different color
  • Bounds - the reference paper size
  • Adjust Pen - a guide to calibrating the plotter

Sample Prints

Development

Note: This project was built and tested on OSX. Use with care on other platforms.

Prerequisites

Make sure you have the following tools installed:

Also, you’ll need a USB port.

Installation

Download or clone the repository, then install all dependencies:

npm install

Optional: Add API Tokens

This is required if you want to work with the map examples. Copy the api-tokens.example.js to api-tokens.js in the root directory and insert the necessary tokens for the API. Depending on whether you want to use the Tilezen API or Mapbox API, you need to provide the corresponding key.

cp api-tokens.example.js api-tokens.js

In the end, it boils down to the decision if you want to work with src/lib/load-lines.js or src/lib/load-lines-mapbox.js. We currently prefer the latter and will probably keep working with it in the future as well.

Develop

Run the following command to start the server on localhost:

npm start

If the AxiDraw is not connected, the server starts in simulator mode. To visit the simulation go to http://localhost:8080. The CNC-Server will start on http://localhost:4242.

Setup AxiDraw

  1. Connect your AxiDraw to power and via USB to your computer.
  2. Start the server as explained above. It should log out CONNECTSERIAL CONNECT! to show that it found the AxiDraw.
  3. Go to http://localhost:8080/adjust-pen.html and follow the instructions.
  4. For drawing the reference borders go to http://localhost:8080/draw-bounds.html and press Print to draw the bounds of the cards. Note: we’re using cards with the size DIN A6.
  5. Place a card on the reference borders and you’re ready to go!
  6. On http://localhost:4242 you can see the CNC management board with the progress and further options.

Brew Your Own

plot-coords.js

In order to create your own drawings you should start with the high-level Plotter class from src/lib/plot-coords.js.

See src/draw-lorenz.js and html/draw-lorenz.html for a basic example. Note: This requires some boilerplate HTML tags (such as a #preview SVG) and styles. The final paper size is 496x700 pixels and equal to the DIN A6 paper format.

Basic JavaScript outline:

import Plotter from './lib/plot-coords';
const plotter = new Plotter();
plotter.coords = [...]; // assign the coords
plotter.print(); // start drawing

axidraw.js

If you’d like to have more control over the robot, use the low-level API from src/lib/axidraw.js:

import createAxidraw from "./lib/axidraw";
const axidraw = await createAxidraw();
const coords = [...]; // a list of lines 

for (let i = 0; i < coords.length; i++) {
  const line = this._coords[i];
  await axidraw.drawPath(line);
}

coords

You'll need to pass coords with [x, y] pairs that are in the ranging from 0 to 100.

Examples:

const square = [
  [[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]
];

const twoSquares = [
  [[10, 10], [11, 10], [11, 11], [10, 11], [10, 10]],
  [[20, 20], [21, 20], [21, 21], [20, 21], [20, 10]]
];

load-svg-as-coords.js

You can also load SVGs and convert the <path> elements to coordinates:

import load from '../lib/load-svg-as-coords.js';
const coords = await load('/assets/my-logo.svg');

scale-move.js

In order to position and scale elements, use

import {scaleAndMove} from '../lib/scale-move';
const positionedSquare = [
  ...scaleAndMove(square, {scale: 2, x: 10, y: 10})
]

convert-text-to-coords.js

Here is an example for drawing dynamic text:

import convertTextToCoords from './lib/convert-text-to-coords';
const text = await convertTextToCoords(text, {
  x: 100,
  y: 100,
  fontSize: 40,
  anchor: 'center middle'
});

`optimize-lines.js``

If you have a lot of random lines, it might take some time to draw them. Use this helper to sort the lines by picking the closest start point after finishing a line.

import {optimizeOrder} from './optimize-lines';
const randomLines = [...];
const sortedLines = optimizeOrder(randomLines);

merge-lines.js

A simple way to increase drawing speed is to reduce the number of times the pen has to be moved up and down during the drawing process. Note: This will best work with the optimizeOrder helper described above.

import {optimizeOrder} from './optimize-lines';
const random = [...];
const sorted = optimizeOrder(randomLines);
const merged = mergeLines(sortedMapPaths);

Images from Setup

Background

This project started when we were preparing our sponsor booth at JSConf EU 2018. Instead of just spreading swag, we wanted something original and customizable that people would love to take home. And since we are surrounded by digital products all day, we thought that an analog print could definitely make a difference.

At Ubilabs, we work with all kinds of mapping frameworks such as the Google Maps API or Mapbox.gl. The obvious next step was that our little friendly robot would be drawing one of these maps for you.

In the end, we were quite overwhelmed by the positive feedback. The robot was drawing non-stop during the conference and we produced more than 100 maps in two days. What we liked most was that it was a real ice-breaker when talking to strangers. We always asked them where they live to start the conversation. And while watching the robot draw their personal map, we got to know them and had the chance to tell them what we’re doing at Ubilabs.

Links

Follow @ubilabs on Twitter for more projects like this and visit ubilabs.net to find out what kind of map projects we’re doing for our customers.

Acknowledgment

  1. AxiDraw is a trademark used with permission from Evil Mad Science LLC.

More Repositories

1

geocomplete

jQuery Geocoding and Places Autocomplete Plugin
JavaScript
1,227
star
2

react-geosuggest

A React autosuggest for the Google Maps Places API.
TypeScript
1,021
star
3

kd-tree-javascript

JavaScript k-d Tree Implementation
JavaScript
607
star
4

google-maps-api-threejs-layer

Google Maps API layer that uses Three.js to for super fast animation
JavaScript
159
star
5

google-maps-react-hooks

The JavaScript library to easily implement a Google Maps map into your react application. It comes with a collection of React hooks to access the map instance or different Maps JavaScript Services.
TypeScript
73
star
6

threejs-overlay-view

A wrapper for the Google Maps WebglOverlayView that takes care of the integration between three.js and the Google Maps JavaScript API. It lets you create a Google Map overlays directly with three.js.
TypeScript
55
star
7

google.maps.polyline.edit

Enables Google Maps API V3 Polyline Editing
JavaScript
33
star
8

mobile-range-slider

A lightweight JavaScript range slider that works on mobile devices such as iOS or Android.
JavaScript
20
star
9

google-maps-api-svg-overlay

SVG Overlay for the Google Maps JavaScript API v3
JavaScript
16
star
10

google-maps-deckgl-overlay

An example for using a Google Map with Deck.gl
JavaScript
13
star
11

geolocation-remote

Geolocation Remote - Control the Location of Your Mobile Device
JavaScript
11
star
12

node-geobatch

Batch geocode addresses from multiple sources.
JavaScript
10
star
13

esa-climate-from-space

Climate from Space application for ESA's CCI+ program.
TypeScript
9
star
14

node-stagger

Execute a stack with a given "request-per-seconds" and "max" rate.
JavaScript
9
star
15

project-template

The project creation tooling used at Ubilabs
JavaScript
9
star
16

refinery-custom-page-parts

Custom page parts for refinery
Ruby
8
star
17

soccer-debs-challenge

The ACM DEBS 2013 Grand Challenge
JavaScript
8
star
18

webpack-node-modules-list

Exports all used node modules of a webpack bundle to a file.
JavaScript
8
star
19

node-batch-geocoder

Node.js Batch Geocoder for the Google Maps API
JavaScript
7
star
20

node-image-saver

Saves an Image Data URI Back to the File System
JavaScript
7
star
21

sunzi-recipes

Our server provisioning recipes for sunzi.
Shell
6
star
22

node-parallel-transform-stream

A NodeJS transform stream which runs transformations in parallel and preserves input order.
JavaScript
6
star
23

flickr_geocoding_bookmarklet

A Bookmarklet for Better Geocoding within Flickr using Google Maps
JavaScript
6
star
24

grunt-gcloud

A wrapper for the google-gcloud node module.
JavaScript
5
star
25

icons_generator

Multiple Icons Generator using Ruby and ImageMagick
Ruby
5
star
26

touchstates

jQuery Touch State Plugin
JavaScript
4
star
27

kirby-object-storage-stream-wrappers

Prototype to run a Kirby CMS instance with data on Object Storage (GCS)
4
star
28

google-map-bounds-limit

Limits zoom and panning of a google map
JavaScript
4
star
29

cookbooks

Our Fancy Chef Cookbooks
Ruby
3
star
30

fastbillr

Ruby Api wrapper for the fastbill.com API
Ruby
3
star
31

stackenblochen

A grid system for rectanglers.
CSS
2
star
32

jquery-touchevents

jQuery Plugin to Proxy Touch Events
JavaScript
2
star
33

esa-webgl-globe

TypeScript
2
star
34

google-maps-visualrefresh

Comparing the new and old Google Maps styles.
1
star
35

node-google-maps-api-stream

A streaming, rate-limited, and caching interface to Google Maps APIs.
JavaScript
1
star
36

template

HTML, CSS and JavaScript Templates
JavaScript
1
star
37

nagios-plugins

A collection of custom Nagios plugins that we use @ubilabs.
Shell
1
star
38

image-performance

Test Image Rendering Performance on Various Browsers
1
star
39

fusion_wiki

1
star
40

storycamp

Basecamp Story Card Printer for Google Chrome
JavaScript
1
star
41

retrobox

Ruby
1
star
42

basic_server_stack

Ruby
1
star
43

gdd

1
star
44

node-api-stream

Create streaming, rate-limited APIs with ease.
JavaScript
1
star
45

ubilabs.github.com

1
star
46

binary-view.js

Binary schemes for JavaScript. Let's you define (write and load) binary formats
JavaScript
1
star
47

drone_elixir_example

Example to show some examples on drone.io. This one is for elixir
Elixir
1
star
48

babylonian

A Mixed Languages Map Type
1
star