Clean up DivisionRaster example.

This commit is contained in:
Jonathan Puckey 2011-06-19 15:01:53 +02:00
parent faf9b453d1
commit fcb7a74610

View file

@ -11,34 +11,21 @@
// Create a raster item using the image with id='lenna'
var raster = new Raster('lenna');
var group = new Group();
function onResize(event) {
// Transform the raster so that it fills the bounding rectangle
// of the view:
raster.fitBounds(view.bounds, true);
// Create a path that fills the view, and fill it with
// the average color of the raster:
var path = new Path.Rectangle(view.bounds);
path.fillColor = raster.getAverageColor(path);
group.children = [path];
}
// Call onResize directly:
onResize();
// Make the raster invisible:
raster.visible = false;
// The mouse has to drag at least 30pt until the next onMouseDrag
// Create a seperate layer that the paths will be placed on:
var layer = new Layer();
// The mouse has to drag at least 5pt until the next onMouseDrag
// event is fired:
tool.minDistance = 5;
function onMouseMove(event) {
// Each drag event, iterate through the children of group:
for (var i = 0; i < group.children.length; i++) {
var child = group.children[i];
for (var i = 0; i < layer.children.length; i++) {
var child = layer.children[i];
var bounds = child.bounds;
if (bounds.contains(event.point)) {
@ -77,6 +64,22 @@
}
}
}
function onResize(event) {
layer.removeChildren();
// Transform the raster so that it fills the bounding rectangle
// of the view:
raster.fitBounds(view.bounds, true);
// Create a path that fills the view, and fill it with
// the average color of the raster:
var path = new Path.Rectangle(view.bounds);
path.fillColor = raster.getAverageColor(path);
}
// Call onResize directly:
onResize();
</script>
</head>
<body>