drawbetween.js

A JavaScript library for drawing images and shapes on the specified line segment.

NPM Version Downloads Stats

Demo

https://higuri.github.io/drawbetween.js/sample/

Installation

via NPM

npm install drawbetween
# or...
yarn add drawbetween

CommonJS

const DrawBetween = require('drawbetween');

ES Module

import DrawBetween from 'drawbetween';

via CDN

<script scr="https://unpkg.com/drawbetween"></script>

Usage Example

HTML

<div id="canvas" style="width:300px; height:150px"></div>

JavaScript

const canvas = document.querySelector('#canvas');
const draw = new DrawBetween(canvas);

// draw images between (0,0) and (250,0).
const imageUrl = 'YOUR_IMAGE_URL';
draw.images({x: 0, y: 0}, {x: 250, y: 0}, imageUrl);

// draw rects with default options.
draw.rects({x: 0, y: 40}, {x: 250, y: 40});

// draw cross marks with custom options.
draw.crossMarks({x: 10, y: 80}, {x: 260, y: 80}, {
  minInterval: 40,
  strokeColor: '#f00',
  strokeWidth: 3
});

// draw custom paths.
const drawer = (ctx, p) => {
  ctx.beginPath();
  ctx.arc(p.x, p.y, 10, 0, 2 * Math.PI);
  ctx.fillStyle = '#0af';
  ctx.fill();
};
draw.withDrawer({x: 10, y: 110}, {x: 260, y: 110}, drawer, {
  minInterval: 35
});

CodePen

https://codepen.io/higuri/pen/jJNNmB

API

new DrawBetween(targetDiv)

Create a new DrawBetween object.

line(p0, p1, options)

Draw a straight line between p0 and p1.

images(p0, p1, imageUrl, options)

Draw images on the specified line segment.

rects(p0, p1, options)

Draw rectangles on the specified line segment.

circles(p0, p1, options)

Draw circles on the specified line segment.

crossMarks(p0, p1, options)

Draw cross marks on the specified line segment.

triangles(p0, p1, options)

Draw triangles on the specified line segment.

withDrawer(p0, p1, drawer, options)

Draw specified paths on the specified line segment.

clear()

Clear all drawings of the instance.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.