Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:25
Show Gist options
  • Save oodavid/202177ae2f0e6baee7ad to your computer and use it in GitHub Desktop.
Save oodavid/202177ae2f0e6baee7ad to your computer and use it in GitHub Desktop.
GC > New Groups Paradigm Bug
import ui.TextView as TextView;
import ui.View as View;
import device;
import animate;
var gx = Math.ceil(device.width/20);
exports = Class(GC.Application, function () {
this.initUI = function () {
// A note
new TextView({
superview: this.view,
width: device.width,
height: (gx*2),
color: '#FFFFFF',
text: 'Tap to shuffle, view the console'
// Create some randomly placed views
var myviews = [];
for(var n=0; n<10; n++){
myviews.push(new View({
superview: this.view,
x: Math.random()*(device.width-(gx*2)),
y: (gx*2)+Math.random()*(device.height-(gx*4)),
width: (gx*2),
height: (gx*2),
backgroundColor: '#'+('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6)
// Tap to animate a randomly-sized group of views
this.view.on('InputStart', bind(this, function(){
console.log('-- NEW ANIMATION --');
var l = Math.floor(Math.random()*myviews.length);
for(var n=0; n<l; n++){
animate(myviews[n], 'mygroup')
x: Math.random()*(device.width-(gx*2)),
y: (gx*2)+Math.random()*(device.height-(gx*4))
}, 500, animate.easeOutBounce);
var g = animate.getGroup('mygroup');
g.once('Finish', bind(this, function(){
console.log('callback fired!');
console.log('Expected group size: '+l);
console.log('Reported group size: '+g.anims.length);
this.launchUI = function () {};
// Fisher-Yates Shuffle
var fyshuffle = function(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment