Skip to content

Instantly share code, notes, and snippets.

@matarillo
Created October 24, 2009 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matarillo/217308 to your computer and use it in GitHub Desktop.
Save matarillo/217308 to your computer and use it in GitHub Desktop.
var model = {
observers: new Array(),
position: null,
text: null,
queue: null,
running: false,
start: function() {
if (this.running) return;
this.running = true;
this.queue = [
{p: {x:300,y:200}, t: 'ゆっくり'},
{p: {x:50,y:120}, t: 'して'},
{p: {x:500,y:40}, t: 'いってね!'},
{p: {x:0,y:0}, t: ''}
];
this.next();
},
stop: function() {
this.position = null;
this.text = null;
this.queue = null;
this.running = false;
},
next: function() {
if (!this.running) return;
if (this.queue.length == 0) {
this.stop();
return;
}
item = this.queue.shift();
this.position = item.p;
this.text = item.t;
this.notify();
},
notify: function() {
for(var i = 0; i < this.observers.length; i++) {
this.observers[i].update();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment