Clean up the PhyllotaxisRaster example and use Item#fitBounds instead of stretching the image.

This commit is contained in:
Jonathan Puckey 2011-06-19 03:43:47 +02:00
parent a0dbf3eb45
commit faf9b453d1

View file

@ -17,25 +17,19 @@
amount: 200 amount: 200
}; };
// Create a raster object, using the image // Create a raster object, using the image
var originalRaster = new Raster('sunflower'); var raster = new Raster('sunflower');
// Stretch the image to fit exactly into the view
originalRaster.bounds = view.bounds; // Transform the raster so it fills the bounding rectangle
originalRaster.visible = false; // of the view:
rasterizeImage(); raster.fitBounds(view.bounds, true);
// Hide the raster:
raster.visible = false;
// Create the group of circle shaped paths and scale it up a bit: // Create the group of circle shaped paths and scale it up a bit:
var group = createPhyllotaxis(values.amount); var group = createPhyllotaxis(values.amount);
group.scale(3); group.scale(3);
function rasterizeImage() {
// Stretch the image to fit exactly into the view
originalRaster.bounds = view.bounds;
if (raster)
raster.remove();
raster = originalRaster.rasterize();
raster.visible = false;
}
function createPhyllotaxis(amount) { function createPhyllotaxis(amount) {
var group = new Group(); var group = new Group();
// The Golden Angle (http://en.wikipedia.org/wiki/Golden_angle) // The Golden Angle (http://en.wikipedia.org/wiki/Golden_angle)
@ -71,10 +65,10 @@
position = event.point; position = event.point;
} }
// Whenever the window is resized, // Whenever the window is resized, we need to fit the raster
// we need to rerasterize the image: // in the bounding rectangle of the view again:
function onResize() { function onResize() {
rasterizeImage(); raster.fitBounds(view.bounds, true);
} }
function onFrame(event) { function onFrame(event) {