-
Notifications
You must be signed in to change notification settings - Fork 6
Examples
RNO edited this page Jul 22, 2017
·
6 revisions
const plotter = require('xy-plotter')()
const job = plotter.Job('vortex')
const cx = plotter.width / 2
const cy = plotter.height / 2
const margin = 1
const maxRadius = 100
const sides = 100
for (let r = 0; r < maxRadius; r += margin) {
for (let a = 0; a <= Math.PI*2; a += (Math.PI*2 / sides)) {
let d = (a < Math.PI) ? Math.PI : 0
let x = cx + Math.cos(a) * (r + Math.sin(d)*(maxRadius-r) )
let y = cy + Math.sin(a) * (r + Math.cos(d)*(maxRadius-r) )
job.move(x, y)
job.pen_down()
}
}
// anonymous call to serial
plotter.Serial('/dev/tty.wchusbserial1410').send(job)
const plotter = require('xy-plotter')({
width: 380,
height: 310,
pen_positions: {
up: 0,
down: 80
},
decimals: 2
})
console.log(plotter.width, plotter.height)
console.log(plotter.config)
console.log(plotter.defaultConfig)
const path = require('path')
const plotter = require('xy-plotter')()
const job = plotter.Job('hello')
job.svg(path.join(__dirname, 'svg', 'hello.svg'))
plotter.Serial('/dev/tty.wchusbserial1410').send(job)
const path = require('path')
const plotter = require('xy-plotter')()
const job = plotter.Job('broken-circles')
const cx = plotter.width / 2
const cy = plotter.height / 2
const margin = 1
const sides = 100
for (let r = 2; r < 100; r += margin) {
for (let a = 0; a <= Math.PI*2; a += (Math.PI*2 / sides)) {
let dx = (a < Math.PI) ? 50 : -20
let dy = (a > Math.PI) ? 20 : 50
let dr = (a > Math.PI * 0.25 && a < Math.PI * 1) ? -50 : 0
let x = cx + dx + Math.cos(a) * Math.max(r + dr , dx)
let y = cy + dx - dy + Math.sin(a) * Math.max(r + dr, r + dy)
job.move(x, y)
job.pen_down()
}
}
// writing to a png file
const file = plotter.File()
file.export(job, path.join(__dirname, 'broken-circles.png'))
const path = require('path')
const plotter = require('xy-plotter')()
const job = plotter.Job('circles')
const jobPath = path.join(__dirname, 'circles.json')
const cx = plotter.width / 2
const cy = plotter.height / 2
const margin = 1
const maxRadius = 100
const sides = 100
job.setSpeed(0.8)
for (let r = 0; r < maxRadius; r += margin) job.ellipse(cx, cy, r, maxRadius)
for (let r = 0; r < maxRadius; r += margin) job.ellipse(cx, cy, maxRadius, r)
// saving the job
const file = plotter.File()
file.save(job, jobPath)
// loading the job
let loadedJob = file.load(jobPath)
file.export(loadedJob, path.join(__dirname, 'circles.png'))
const plotter = require('xy-plotter')()
const job1 = plotter.Job('small-rectangle')
job1.rect(10, 10, 10, 10).pen_up()
const job2 = plotter.Job('big-rectangle')
job2.rect(10, 10, 5, 5).pen_up()
const job3 = plotter.Job('circle')
job3.circle(10, 10, 3, 10).pen_up()
const serial = plotter.Serial('/dev/tty.wchusbserial1410', {
verbose: true,
progressBar: false,
disconnectOnJobEnd: false // set to false when queuing jobs (default true)
});
// you can make use of the promises to queue job...
serial
.send(job1)
.then(() => serial.send(job2))
.then(() => serial.send(job3))
// you'll need to disconnect manually, as serial.disconnectOnJobEnd is false
.then(() => serial.disconnect())
// ...or use plotter.Serial.sendList([]);
serial
.sendList([job1, job2, job3])
.then(() => serial.disconnect())
const plotter = require('./../index.js')()
const job = plotter.Job('rectangles')
const margin = 1
const startX = plotter.width / 2
const startY = plotter.height / 2 + margin
const x = startX
const y = startY
job.move(startX, startY);
job.pen_down();
for (let i = 0; i < 100; i += margin) {
x = startX
x += i
job.move(x, y)
y += i * 2
job.move(x, y)
x -= i * 2
job.move(x, y)
y -= i * 2 + margin
job.move(x, y)
y = startY - i
}
job.pen_up();
let stats = plotter.Stats(job)
let duration = stats.duration
console.log(`Some stats before starting "${job.getName()}" :`)
console.log(`the pen will run a total of ${stats.distance} mm,`)
console.log(`in about ${duration.estimation.value} seconds (${duration.estimation.formatted}).`)
console.log(`Let's say between ${duration.min.formatted} and ${duration.max.formatted} to be sure.`)
console.log(`Now Let's draw !\n`)
const serial = plotter.Serial('/dev/tty.wchusbserial1410')
serial.send(job)
const plotter = require('./../index.js')()
const job = plotter.Job('red-and-blue-rectangle')
// draw a first rectangle
job.rect(50, 50, 20, 20).pen_up()
// wait until user resume the job
job.wait()
// draw a second rectangle with another pen
job.rect(55, 55, 20, 20)
// anonymous call to serial
plotter.Serial('/dev/tty.wchusbserial1410').send(job)
-
Plotter()
- EventEmitter
-
plotter.Job()
job.name
job.buffer()
job.setSpeed()
job.resetSpeed()
job.optimize()
job.pen_up()
job.pen_down()
job.pen()
job.move()
job.home()
job.wait()
job.drawBoundaries()
job.point()
job.line()
job.triangle()
job.rect()
job.quad()
job.polygon()
job.circle()
job.ellipse()
job.text()
job.svg()
job.addToBuffer()
Event: 'data'
-
plotter.Turtle()
-
plotter.Serial()
serial.connected
serial.paused
serial.send()
serial.sendList()
serial.end()
serial.connect()
serial.disconnect()
serial.pause()
serial.resume()
serial.sendCommand()
Event: 'error'
Event: 'connect'
Event: 'disconnect'
Event: 'pause'
Event: 'resume'
Event: 'job-start'
Event: 'job-progress'
Event: 'job-end'
-
plotter.Server()
-
plotter.File()
-
plotter.Stats()