Skip to content

evhan55/scamper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
	);
}

About

Generate even points along a cubic Bezier curve

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published