Sync online examples back to repo, and some minor cleanups.

This commit is contained in:
Jürg Lehni 2016-06-14 17:22:54 +02:00
parent 643df2d46d
commit 383e574368
7 changed files with 40 additions and 31 deletions

View file

@ -13,7 +13,8 @@
amount: 30 amount: 30
}; };
var raster, group; var raster,
group;
var piece = createPiece(); var piece = createPiece();
var count = 0; var count = 0;
@ -62,9 +63,11 @@
if (group) if (group)
group.remove(); group.remove();
// As the web is asynchronous, we need to wait for the raster to
// load before we can perform any operation on its pixels.
raster = new Raster(image); raster = new Raster(image);
raster.remove(); raster.visible = false;
raster.on('load', function() {
// Transform the raster, so it fills the view: // Transform the raster, so it fills the view:
raster.fitBounds(view.bounds, true); raster.fitBounds(view.bounds, true);
group = new Group(); group = new Group();
@ -79,9 +82,12 @@
// Transform the group so it covers the view: // Transform the group so it covers the view:
group.fitBounds(view.bounds, true); group.fitBounds(view.bounds, true);
group.scale(1.1); group.scale(1.1);
})
} }
function onFrame(event) { function onFrame(event) {
if (!group)
return;
// Loop through the uncolored hexagons in the group and fill them // Loop through the uncolored hexagons in the group and fill them
// with the average color: // with the average color:
var length = Math.min(count + values.amount, group.children.length); var length = Math.min(count + values.amount, group.children.length);
@ -91,7 +97,6 @@
var color = raster.getAverageColor(hexagon); var color = raster.getAverageColor(hexagon);
if (color) { if (color) {
hexagon.fillColor = color; hexagon.fillColor = color;
// hexagon.strokeColor = color;
var top = piece.children[1]; var top = piece.children[1];
top.fillColor = color.clone(); top.fillColor = color.clone();
top.fillColor.brightness *= 1.5; top.fillColor.brightness *= 1.5;
@ -122,6 +127,7 @@
var image = document.createElement('img'); var image = document.createElement('img');
image.onload = function () { image.onload = function () {
handleImage(image); handleImage(image);
view.draw();
}; };
image.src = event.target.result; image.src = event.target.result;
}; };

View file

@ -10,9 +10,13 @@
// certain browsers when serving this script online: // certain browsers when serving this script online:
var path, position, max; var path, position, max;
var count = 0; var count = 0;
var grow = true; var grow = false;
// As the web is asynchronous, we need to wait for the raster to
// load before we can perform any operation on its pixels.
var raster = new Raster('mona'); var raster = new Raster('mona');
raster.remove(); raster.visible = false;
raster.on('load', resetSpiral);
var text = new PointText({ var text = new PointText({
justification: 'right', justification: 'right',
@ -22,11 +26,9 @@
: 'to drag & drop images, please use Webkit, Firefox, Chrome or IE 10' : 'to drag & drop images, please use Webkit, Firefox, Chrome or IE 10'
}); });
resetSpiral();
function onFrame(event) { function onFrame(event) {
if (grow) { if (grow) {
if (raster && (view.center - position).length < max) { if (raster.loaded && (view.center - position).length < max) {
for (var i = 0, l = count / 36 + 1; i < l; i++) { for (var i = 0, l = count / 36 + 1; i < l; i++) {
growSpiral(); growSpiral();
} }
@ -73,6 +75,7 @@
} }
function onResize() { function onResize() {
if (raster.loaded)
resetSpiral(); resetSpiral();
text.point = view.bounds.bottomRight - [30, 30]; text.point = view.bounds.bottomRight - [30, 30];
} }
@ -97,7 +100,7 @@
var image = document.createElement('img'); var image = document.createElement('img');
image.onload = function () { image.onload = function () {
raster = new Raster(image); raster = new Raster(image);
raster.remove(); raster.visible = false;
resetSpiral(); resetSpiral();
}; };
image.src = event.target.result; image.src = event.target.result;