Skip to content

implementation of Bresenham algorithm written in js

License

Notifications You must be signed in to change notification settings

92nqb/bresenham-line

Repository files navigation

Bresenham's line algorithm

npm version License

Build Status

Installation

You can install bresenham-line using npm.

npm install --save bresenham-line

Usage

Just require the module.

// es5
var line = require('bresenham-line').line;

var genLine = line({
  x: 1,
  y: 1
},
{
  x: 6,
  y: 2
});
console.dir(genLine.next().value); // { x: 1, y: 1 }
console.dir(genLine.next().value); // { x: 2, y: 1 }
console.dir(genLine.next().value); // { x: 3, y: 1 }
// ..
// es6
import { line } from 'bresenham-line';

const startPoint = {
  x: 1,
  y: 1
};

const finalPoint = {
  x: 6,
  y: 2
};

for (const point of line(startPoint, finalPoint)) {
  console.dir(point); // { x: 1, y: 1 }, { x: 2, y: 1 }, ...
}

License

MIT @ Nicolas Quiceno

About

implementation of Bresenham algorithm written in js

Resources

License

Stars

Watchers

Forks

Packages

No packages published