paper.js/examples/Tools/Grid.html

44 lines
No EOL
1,007 B
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
/////////////////////////////////////////////////////////////////////
// Values
tool.fixedDistance = 10;
var values = { size: tool.fixedDistance };
/////////////////////////////////////////////////////////////////////
// Mouse handling
var point, path;
function getPos(pt) {
return (pt / values.size).round() * values.size;
}
function onMouseDown(event) {
point = getPos(event.point);
path = new Path();
path.strokeColor = 'black';
path.add(point);
}
function onMouseDrag(event) {
var p = getPos(event.point);
if (point != p) {
path.add(p);
point = p;
}
}
</script>
</head>
<body>
<canvas id="canvas" resize keepalive="true"></canvas>
</body>
</html>