paper.js/examples/Tools/Grid.html

45 lines
1.1 KiB
HTML
Raw Normal View History

2011-02-21 08:31:26 -05:00
<!DOCTYPE html>
2011-02-08 19:10:55 -05:00
<html>
<head>
2014-08-16 13:24:54 -04:00
<meta charset="UTF-8">
<title>Grid</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper-full.js"></script>
<script type="text/paperscript" canvas="canvas">
/////////////////////////////////////////////////////////////////////
// Values
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
tool.fixedDistance = 10;
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
var values = { size: tool.fixedDistance };
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
/////////////////////////////////////////////////////////////////////
// Mouse handling
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
var point, path;
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
function getPos(pt) {
return (pt / values.size).round() * values.size;
}
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
function onMouseDown(event) {
point = getPos(event.point);
path = new Path();
path.strokeColor = 'black';
path.add(point);
}
2011-03-04 06:38:38 -05:00
2014-08-16 13:24:54 -04:00
function onMouseDrag(event) {
var p = getPos(event.point);
if (point != p) {
path.add(p);
point = p;
}
}
</script>
2011-02-08 19:10:55 -05:00
</head>
<body>
2014-08-16 13:24:54 -04:00
<canvas id="canvas" resize></canvas>
2011-05-30 18:27:39 -04:00
</body>
</html>