Skip to content

Instantly share code, notes, and snippets.

@oodavid
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save oodavid/202177ae2f0e6baee7ad to your computer and use it in GitHub Desktop.

Select an option

Save oodavid/202177ae2f0e6baee7ad to your computer and use it in GitHub Desktop.

Revisions

  1. oodavid revised this gist Jul 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Application.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ exports = Class(GC.Application, function () {
    });
    // Create some randomly placed views
    var myviews = [];
    for(var n=0; n<15; n++){
    for(var n=0; n<10; n++){
    myviews.push(new View({
    superview: this.view,
    x: Math.random()*(device.width-(gx*2)),
  2. oodavid created this gist Jul 27, 2015.
    60 changes: 60 additions & 0 deletions Application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    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<15; 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 --');
    fyshuffle(myviews);
    var l = Math.floor(Math.random()*myviews.length);
    for(var n=0; n<l; n++){
    animate(myviews[n], 'mygroup')
    .then({
    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.removeAllListeners('Finish');
    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;
    }
    };