Improve several examples.

This commit is contained in:
Jonathan Puckey 2013-03-09 16:02:11 +01:00
parent 2dfe491212
commit ace2e3e13b
4 changed files with 33 additions and 23 deletions

View file

@ -6,15 +6,23 @@
<link rel="stylesheet" href="../css/style.css"> <link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script> <script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas"> <script type="text/paperscript" canvas="canvas">
var redPath = new Path.Circle(view.center, 10); var redPath = new Path.Circle({
redPath.fillColor = 'red'; center: view.center,
radius: 5,
fillColor: 'red'
});
var whitePath = new Path.Circle(view.center, 10); var whitePath = new Path.Circle({
whitePath.fillColor = 'white'; center: view.center,
radius: 5,
fillColor: 'white'
});
var text = new PointText(); var text = new PointText({
text.content = 'Resize your window'; content: 'Resize your window',
text.justification = 'center'; justification: 'center',
point: view.center
});
function onResize(event) { function onResize(event) {
// Resize the red circle to fill the bounds of the view: // Resize the red circle to fill the bounds of the view:

View file

@ -7,14 +7,17 @@
<script type="text/javascript" src="../../dist/paper.js"></script> <script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas"> <script type="text/paperscript" canvas="canvas">
var path; var path;
var rect = new Rectangle([150, 150], [300, 300]);
project.currentStyle.fillColor = 'black';
function onFrame(event) { function onFrame(event) {
if (path) if (path)
path.remove(); path.remove();
var size = Math.abs(Math.sin(event.count / 40)) * 150 + 10; path = new Path.RoundRectangle({
path = new Path.RoundRectangle(rect, size); radius: Math.abs(Math.sin(event.count / 40)) * 150 + 10,
rectangle: {
size: [300, 300]
},
fillColor: 'black'
});
path.position = view.center; path.position = view.center;
} }
</script> </script>

View file

@ -6,20 +6,18 @@
<link rel="stylesheet" href="../css/style.css"> <link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script> <script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas"> <script type="text/paperscript" canvas="canvas">
// All newly created items will receive
// these style properties:
project.currentStyle = {
fillColor: 'white',
strokeColor: 'black'
};
var path;
function onMouseDrag(event) { function onMouseDrag(event) {
// The radius is the distance between the position // The radius is the distance between the position
// where the user clicked and the current position // where the user clicked and the current position
// of the mouse. // of the mouse.
var radius = (event.downPoint - event.point).length; var path = new Path.Circle({
path = new Path.Circle(event.downPoint, radius); center: event.downPoint,
radius: (event.downPoint - event.point).length,
fillColor: 'white',
strokeColor: 'black'
});
// Remove this path on the next drag event:
path.removeOnDrag(); path.removeOnDrag();
}; };
</script> </script>

View file

@ -14,8 +14,9 @@
if (event.delta.length > minSize) { if (event.delta.length > minSize) {
// If there is no path, make one: // If there is no path, make one:
if (!path) { if (!path) {
path = new Path(); path = new Path({
path.fillColor = 'black'; fillColor: 'black'
});
path.add(event.lastPoint); path.add(event.lastPoint);
} }