Skip to content

Latest commit

 

History

History
66 lines (58 loc) · 1.46 KB

README.md

File metadata and controls

66 lines (58 loc) · 1.46 KB

Scamper

Scamper takes raw input points and maps them to evenly spaced points along a cubic Bezier curve.

API

Scamper(opts) Creates a new Scamper instance. Optional parameters:

sample: point subsampling rate
step: desired distance between points

newStroke() Begins a new stroke.
addPoint(x, y, p) Adds raw input point to current stroke.
setPointHandler(function) Function to be run on new even step points. Function parameter is a point object with x, y, p (pressure) values.

Usage

var isDrawing = false;
var scamper = new Scamper({step: 10, sample: 2});

scamper.setPointHandler(function(pt) {
	var d = document.createElement("div");
	d.innerHTML = 's';
	d.setAttribute('style', 'position: absolute; top: ' + pt.y + 'px; left: ' + pt.x + 'px;');
	document.body.appendChild(d);
});

window.onmousedown = function(e) {
	isDrawing = true;
	scamper.newStroke();
	scamper.addPoint(
	  e.clientX,
	  e.clientY,
	  0
	);
}
window.onmousemove = function(e) {
	if (!isDrawing) return;
	scamper.addPoint(
	  e.clientX,
	  e.clientY,
	  0
	);
}
window.onmouseup = function(e) {
	isDrawing = false;
	scamper.addPoint(
	  e.clientX,
	  e.clientY,
	  0
	);
}