mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Clean up the PhyllotaxisRaster example and use Item#fitBounds instead of stretching the image.
This commit is contained in:
parent
a0dbf3eb45
commit
faf9b453d1
1 changed files with 11 additions and 17 deletions
|
@ -17,25 +17,19 @@
|
|||
amount: 200
|
||||
};
|
||||
// Create a raster object, using the image
|
||||
var originalRaster = new Raster('sunflower');
|
||||
// Stretch the image to fit exactly into the view
|
||||
originalRaster.bounds = view.bounds;
|
||||
originalRaster.visible = false;
|
||||
rasterizeImage();
|
||||
var raster = new Raster('sunflower');
|
||||
|
||||
// Transform the raster so it fills the bounding rectangle
|
||||
// of the view:
|
||||
raster.fitBounds(view.bounds, true);
|
||||
|
||||
// Hide the raster:
|
||||
raster.visible = false;
|
||||
|
||||
// Create the group of circle shaped paths and scale it up a bit:
|
||||
var group = createPhyllotaxis(values.amount);
|
||||
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) {
|
||||
var group = new Group();
|
||||
// The Golden Angle (http://en.wikipedia.org/wiki/Golden_angle)
|
||||
|
@ -71,10 +65,10 @@
|
|||
position = event.point;
|
||||
}
|
||||
|
||||
// Whenever the window is resized,
|
||||
// we need to rerasterize the image:
|
||||
// Whenever the window is resized, we need to fit the raster
|
||||
// in the bounding rectangle of the view again:
|
||||
function onResize() {
|
||||
rasterizeImage();
|
||||
raster.fitBounds(view.bounds, true);
|
||||
}
|
||||
|
||||
function onFrame(event) {
|
||||
|
|
Loading…
Reference in a new issue