shuffleTiles = function shuffleTiles() {
var tileCnt = 108;
var colors = [ Color.rgb(0,151,0), Color.rgb(0,142,255), Color.rgb(255,143,0),
Color.rgb(160,0,152), Color.rgb(250,255,0), Color.rgb(255,0,0) ];
var shapes = [ 'C', 'Q', 'D', 'P', 'X', 'S' ];
var tiles = [], rnd;
colors.each(function(c) {
shapes.each(function(s) {
Array.range(1, 3).each(function() {
rnd = Math.floor(Math.random() * tileCnt);
while (rnd >= 0) {
if (tiles[rnd] == undefined) {
tiles[rnd] = [ s, c ];
rnd = -1;
} else
rnd = (rnd + 1) % tileCnt;
}
});
});
});
return tiles;
}
showTiles = function showTiles(tiles, cnt, pos) {
cnt = cnt || tiles.length;
pos = pos || pt(100, 500);
for (var i = 0; i < cnt; i++) {
var tile = $morph('Tile' + tiles[i][0]).copy();
tile.get('TileShape').setFill(tiles[i][1]);
tile.setPosition(pos);
lively.morphic.World.current().addMorph(tile);
pos = pos.addXY(100,0);
if (pos.x > 1100)
pos = pos.addXY(0, 100).withX(100);
}
}
tiles = shuffleTiles();
showTiles(tiles, 6, pt(100, 500));
tiles.shift(6);