Add a few mouse tool examples.

This commit is contained in:
Jonathan Puckey 2011-02-08 13:16:43 +01:00
parent cac4bea955
commit 0cefc146bb
4 changed files with 208 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../src/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Item.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Point.js"></script>
<script type="text/javascript" src="../../src/Rectangle.js"></script>
<script type="text/javascript" src="../../src/Size.js"></script>
<script type="text/javascript" src="../../src/Segment.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Path.js"></script>
<script type="text/javascript" src="../../src/Doc.js"></script>
<script type="text/javascript" src="../../src/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/Tool.js"></script>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var doc = new Doc(canvas);
var tool = new Tool({
onMouseDrag: function(event) {
if(event.getCount() != 1)
doc.children.pop();
var distance = event.getDownPoint().subtract(event.getPoint()).getLength();
var path = new Path.Circle(event.getDownPoint(), distance);
path.strokeColor = 'black';
path.fillColor = 'white';
doc.children.push(path);
}
});
tool.setDocument(doc);
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>

View file

@ -0,0 +1,43 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../src/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Item.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Point.js"></script>
<script type="text/javascript" src="../../src/Rectangle.js"></script>
<script type="text/javascript" src="../../src/Size.js"></script>
<script type="text/javascript" src="../../src/Segment.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Path.js"></script>
<script type="text/javascript" src="../../src/Doc.js"></script>
<script type="text/javascript" src="../../src/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/Tool.js"></script>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var doc = new Doc(canvas);
var path;
var tool = new Tool({
onMouseDown: function(event) {
path = new Path();
path.strokeColor = 'black';
path.add(event.getPoint());
doc.children.push(path);
},
onMouseDrag: function(event) {
path.arcTo(event.getPoint(), true);
}
});
tool.setDocument(doc);
tool.setMinDistance(30);
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>

View file

@ -0,0 +1,63 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../src/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Item.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Point.js"></script>
<script type="text/javascript" src="../../src/Rectangle.js"></script>
<script type="text/javascript" src="../../src/Size.js"></script>
<script type="text/javascript" src="../../src/Segment.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Path.js"></script>
<script type="text/javascript" src="../../src/Doc.js"></script>
<script type="text/javascript" src="../../src/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/Tool.js"></script>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var doc = new Doc(canvas);
var values = {
lines: 5,
size: 40,
smooth: true
};
var paths;
var tool = new Tool({
onMouseDown: function(event) {
paths = [];
for (var i = 0; i < values.lines; i++) {
var path = new Path();
path.strokeColor = '#000000';
doc.children.push(path);
paths.push(path);
}
},
onMouseDrag: function(event) {
var offset = event.getDelta();
offset.setAngle(offset.getAngle() + 90);
var lineSize = values.size / values.lines;
for (var i = 0; i < values.lines; i++) {
var path = paths[values.lines - 1 - i];
offset.setLength(lineSize * i + lineSize / 2);
path.add(event.getMiddlePoint().add(offset));
//path.insert(0, event.getMiddlePoint().subtract(offset));
path.smooth();
}
}
});
tool.setDocument(doc);
tool.setFixedDistance(30);
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>

60
examples/Tools/Wave.html Normal file
View file

@ -0,0 +1,60 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../src/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Item.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Point.js"></script>
<script type="text/javascript" src="../../src/Rectangle.js"></script>
<script type="text/javascript" src="../../src/Size.js"></script>
<script type="text/javascript" src="../../src/Segment.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Path.js"></script>
<script type="text/javascript" src="../../src/Doc.js"></script>
<script type="text/javascript" src="../../src/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/Tool.js"></script>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var doc = new Doc(canvas);
var values = {
curviness: 0.5,
distance: 10,
offset: 10,
mouseOffset: true
};
var path;
var mul = 1;
var tool = new Tool({
onMouseDown: function(event) {
path = new Path();
path.strokeColor = 'black';
doc.children.push(path);
},
onMouseDrag: function(event) {
var step = event.getDelta().rotate(90 * mul);
if (!values.mouseOffset)
step.setLength(values.offset);
var segment = new Segment(event.getPoint().add(step));
segment.handleIn = event.getDelta().multiply(-values.curviness);
segment.handleOut = event.getDelta().multiply(values.curviness);
path.add(segment);
mul *= -1;
}
});
tool.setDocument(doc);
tool.setFixedDistance(10);
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>