jmpinit / p5.axidraw

A p5.js library for controlling the AxiDraw pen plotter.
https://jmpinit.github.io/p5.axidraw/
MIT License
23 stars 0 forks source link
p5 p5-js p5-library p5js pen-plotter plotter-art plotters web-serial webserial

p5.axidraw

A p5.js library for controlling the AxiDraw pen plotter via the WebSerial API.

Usage

Upload the latest release as a file in your sketch and then reference it from index.html like so:

<head>
  ...
  <script src="https://github.com/jmpinit/p5.axidraw/raw/main/p5.axidraw.js"></script>
  ...
</head>

An example sketch that connects to the AxiDraw when the mouse is clicked and draws a diagonal line:

const axi = new axidraw.AxiDraw();
let connected = false;

function setup() {
  createCanvas(400, 400);
}

function mouseClicked() {
  if (!connected) {
    // Note: connect() must be called from a user gesture (e.g. a mouse click) due to
    // browser security restrictions
    axi.connect()
      .then(() => {
        connected = true;
      });
  }

  // Draw a diagonal line
  axi.penDown();
  axi.moveTo(10, 10);
  axi.penUp();

  // Draw a diagonal line, but async

  // axi.penDown()
  //   .then(() => axi.moveTo(10, 10))
  //   .then(() => axi.penUp());
}

See the examples directory for more.

Documentation

See jmpinit.github.io/p5.axidraw for the API docs.